From d269d45c37b58da17da8a05afaa3649e38f7fac4 Mon Sep 17 00:00:00 2001 From: sulenn <273409891@qq.com> Date: Tue, 10 Dec 2019 22:00:46 +0800 Subject: [PATCH] complete knowledge graph and modify the province to place --- demo.html | 62 +++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/demo.html b/demo.html index ddb878b..4cb785c 100644 --- a/demo.html +++ b/demo.html @@ -69,12 +69,12 @@
- +
@@ -1094,42 +1094,51 @@ "links":[] }} currentGraph = { - nodes: {}, - links: {}, - } - nodeMap = {}; - category = 1 - symbolSize = 40 + nodes: {}, + links: {}, + } + nodeMap = {}; + category = 1 + symbolSize = 40 init(city) }); myChart.setOption(option); - function fillInfo(result) { + function fillInfo(result, name) { // graphList = {"keyword":{ // "nodes":[], // "links":[] // }} if (graphList.keyword.nodes.length == 0) { - formNode = {"name":result.data.entity, "category":category, "symbolSize":symbolSize} + formNode = {"name":name, "category":category, "symbolSize":symbolSize} graphList.keyword.nodes[0]=formNode category += 1 symbolSize -= 5 } - else if (graphList.keyword.nodes[0].name == result.data.entity) { + else if (graphList.keyword.nodes[0].name == name) { return 0 } + else { + // console.log(name) + category = nodeMap[name].category + 1 + symbolSize = nodeMap[name].symbolSize - 5 + } + nodeLen = graphList.keyword.nodes.length linkLen = graphList.keyword.links.length - source = result.data.entity - // console.log(result) + source = name for (i = 0; i < result.data.avp.length; i++) { + if (source == result.data.avp[i][1]) { + nodeLen-- + linkLen-- + continue + } formNode = {"name":result.data.avp[i][1], "category":category, "symbolSize":symbolSize} graphList.keyword.nodes[nodeLen+i]=formNode formLink = {"source":source, "target":result.data.avp[i][1]} graphList.keyword.links[linkLen+i]=formLink } - // console.log(graphList) } @@ -1158,7 +1167,7 @@ alert("nothing") return 0 } - fillInfo(result) + fillInfo(result, name) nodeMap = {}; graph = graphList.keyword for (let i = 0; i < graph.nodes.length; i++) { @@ -1186,7 +1195,6 @@ }; } redrawGraph(); - // append(result.data.entity) } function loadData(name) { @@ -1195,13 +1203,9 @@ alert("nothing") return 0 } - fillInfo(result) - // nodeMap = {}; + fillInfo(result, name) + nodeMap = {}; graph = graphList.keyword - // console.log("qiubing2") - console.log(graph) - // console.log(nodeMap) - len = nodeMap.length for (let i = 0; i < graph.nodes.length; i++) { nodeMap[graph.nodes[i].name] = graph.nodes[i]; nodeMap[graph.nodes[i].name]['links'] = {}; @@ -1232,10 +1236,6 @@ let node = nodeMap[nodeName]; - // console.log(node) - // console.log("qiubing3") - // console.log(nodeName) - // console.log(nodeMap) if (node.hasAppend === true || Object.keys(node.nodes).length === 0 || Object.keys(node.links).length === 0) { alert("无法继续展开"); return @@ -1269,10 +1269,8 @@ } // 根据更新后的option重新画图 function redrawGraph() { - // console.log(currentGraph) optionGraph.series[0].data = Object.values(currentGraph.nodes); optionGraph.series[0].links = Object.values(currentGraph.links); - // console.log(optionGraph); myChartGraph.setOption(optionGraph); } @@ -1315,14 +1313,14 @@ { name: 4, itemStyle: { - color: '#61a0a8' + color: '#999ea4' }, }, { name: 5, itemStyle: { - color: '#999ea4' + color: '#555555' }, } ], @@ -1363,10 +1361,6 @@ if (node.hasAppend === true) { remove(node.name) } else { - // console.log("qiubing") - // console.log(node) - // console.log(nodeMap) - // console.log(node.name) loadData(node.name); } }