Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
qq547276542 committed Apr 13, 2018
2 parents 4b6f6f6 + 54fa81e commit 8b1a5ea
Showing 1 changed file with 45 additions and 16 deletions.
61 changes: 45 additions & 16 deletions demo/templates/relation.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ <h2>数据库中暂未添加该实体</h2>
<script type="text/javascript">
// 将后端的查询结果使用echarts展示
var ctx = [ {{ ctx|safe }} ] ;

//{entity2,rel}
var entityRelation = [ {{ entityRelation|safe }} ] ;

var data = [] ;
Expand All @@ -86,12 +88,17 @@ <h2>数据库中暂未添加该实体</h2>
if(url.indexOf("?") != -1){
str = url.split("=")[1]
}
//实体1
node['name'] = str;
//alert(document.getElementById('user_text').value)
node['draggable'] = true ;
node['id'] = 0 ;
var id = 0;
node['id'] = id.toString() ;
data.push(node) ;
for( var i = 0 ;i < Math.min(15,entityRelation[0].length) ; i++ ){

//获取实体2,存储在data中,如果实体2已经存在于data中,则不push
var maxDisPlayNode = 15 ;
for( var i = 0 ;i < Math.min(maxDisPlayNode,entityRelation[0].length) ; i++ ){
node = {} ;
node['name'] = entityRelation[0][i]['entity2']['title'] ;
node['draggable'] = true ;
Expand All @@ -101,17 +108,38 @@ <h2>数据库中暂未添加该实体</h2>
else{
node['category'] = 2 ;
}
node['id'] = i + 1;
data.push(node) ;
}
//最多展示16个节点
for(var i = 0 ;i<Math.min(15,entityRelation[0].length) ; i++){
relation = {} ;
relation['source'] = 0 ;
relation['target'] = i+1 ;
relation['category'] = 0 ;
relation['value'] = entityRelation[0][i]['rel']['type'];
links.push(relation) ;
id = i + 1
node['id'] = id.toString();
var flag = 1 ;
relationTarget = id.toString() ;
for(var j = 0 ; j<data.length ;j++){
if(data[j]['name'] === node['name']){
flag = 0 ;
relationTarget = data[j]['id'] ;
break ;
}
}
relation = {}
relation['source'] = 0 ;
relation['target'] = relationTarget ;
relation['category'] = 0 ;

if(flag === 1){
data.push(node) ;
relation['value'] = entityRelation[0][i]['rel']['type'] ;
links.push(relation) ;
}
else{
maxDisPlayNode += 1 ;
for(var j = 0; j<links.length ;j++){
if(links[j]['target'] === relationTarget){
links[j]['value'] = links[j]['value']+" | "+entityRelation[0][i]['rel']['type']
break ;
}
}

}

}

//用表格列出所有的关系
Expand Down Expand Up @@ -189,7 +217,7 @@ <h2>数据库中暂未添加该实体</h2>
normal: {
show: true,
textStyle: {
fontSize: 12
fontSize: 12,
},
}
},
Expand All @@ -211,8 +239,9 @@ <h2>数据库中暂未添加该实体</h2>
lineStyle: {
normal: {
opacity: 0.9,
width: 1,
curveness: 0
width: 1.3,
curveness: 0,
color:"#262626"
}
}
}
Expand Down

0 comments on commit 8b1a5ea

Please sign in to comment.