diff --git a/kg-builder/public/static/kgData.json b/kg-builder/public/static/kgData.json index 9ffd201..4e2ee43 100644 --- a/kg-builder/public/static/kgData.json +++ b/kg-builder/public/static/kgData.json @@ -6,7 +6,8 @@ "parentCode": "27301", "grade": "2", "name": "儒家", - "uuid": "26365002" + "uuid": "26365002", + "imgsrc": "" }, { "code": "273010308", @@ -14,7 +15,8 @@ "parentCode": "2730103", "grade": "4", "name": "王守仁", - "uuid": "46178689" + "uuid": "46178689", + "imgsrc": "http://h.bytravel.cn/ren/0/head/2057.gif" }, { "code": "273010307", @@ -22,7 +24,8 @@ "parentCode": "2730103", "grade": "4", "name": "陆九渊", - "uuid": "46178686" + "uuid": "46178686", + "imgsrc": "https://bkimg.cdn.bcebos.com/pic/dcc451da81cb39dbde12202dd0160924aa1830fe?x-bce-process=image/resize,m_lfit,w_268,limit_1/format,f_jpg" }, { "code": "273010306", @@ -30,7 +33,8 @@ "parentCode": "2730103", "grade": "4", "name": "朱熹", - "uuid": "46178681" + "uuid": "46178681", + "imgsrc": "https://bkimg.cdn.bcebos.com/pic/f31fbe096b63f624da9384678944ebf81b4ca38c?x-bce-process=image/resize,m_lfit,w_268,limit_1/format,f_jpg" }, { "code": "273010305", @@ -38,7 +42,8 @@ "parentCode": "2730103", "grade": "4", "name": "程颐", - "uuid": "46178676" + "uuid": "46178676", + "imgsrc": "https://bkimg.cdn.bcebos.com/pic/060828381f30e92489594e3b4f086e061d95f73f?x-bce-process=image/resize,m_lfit,w_268,limit_1/format,f_jpg" }, { "code": "273010304", @@ -46,7 +51,8 @@ "parentCode": "2730103", "grade": "4", "name": "董仲舒", - "uuid": "46178671" + "uuid": "46178671", + "imgsrc": "https://bkimg.cdn.bcebos.com/pic/b17eca8065380cd7bbccaaf5a344ad34588281d3?x-bce-process=image/resize,m_lfit,w_268,limit_1/format,f_jpg" }, { "code": "273010309", @@ -54,7 +60,8 @@ "parentCode": "2730103", "grade": "4", "name": "曾子", - "uuid": "46178665" + "uuid": "46178665", + "imgsrc": "https://bkimg.cdn.bcebos.com/pic/838ba61ea8d3fd1fa226566e3f4e251f95ca5fb3?x-bce-process=image/resize,m_lfit,w_268,limit_1/format,f_jpg" }, { "code": "273010303", @@ -62,7 +69,8 @@ "parentCode": "2730103", "grade": "4", "name": "荀子", - "uuid": "46178660" + "uuid": "46178660", + "imgsrc": "https://bkimg.cdn.bcebos.com/pic/37d3d539b6003af36cf611c53b2ac65c1138b6c3?x-bce-process=image/resize,m_lfit,w_268,limit_1/format,f_jpg" }, { "code": "273010302", @@ -70,7 +78,8 @@ "parentCode": "2730103", "grade": "4", "name": "孟子", - "uuid": "46178654" + "uuid": "46178654", + "imgsrc": "http://img.duoziwang.com/2018/19/07051620110108.jpg" }, { "code": "273010301", @@ -78,7 +87,8 @@ "parentCode": "2730103", "grade": "4", "name": "孔子", - "uuid": "46178648" + "uuid": "46178648", + "imgsrc": "http://img.duoziwang.com/2018/17/05142055603532.jpg" } ], "relationship": [ diff --git a/kg-builder/src/components/KGBuilder.vue b/kg-builder/src/components/KGBuilder.vue index 8a38538..daaf29a 100644 --- a/kg-builder/src/components/KGBuilder.vue +++ b/kg-builder/src/components/KGBuilder.vue @@ -191,23 +191,42 @@ export default { var noddd = [ { flag: '1', - code: '27301', + code: '27301111', parentCode: '273', grade: '2', name: '儒家2', uuid: '4617858011', }, { - code: '2730107', + code: '273012222', flag: '1', - parentCode: '27301', + parentCode: '273', grade: '3', name: '故事轶闻2', uuid: '2636501111', }, ] + var newships = [ + { + sourceid: '273', + targetid: '2636501111', + name: '', + targetcode: '2730107', + uuid: '91804213', + sourcecode: '27301', + }, + { + sourceid: '273', + targetid: '4617858011', + name: '', + targetcode: '273010723', + uuid: '91804389', + sourcecode: '2730107', + }, + ] _this.graph.nodes = _this.graph.nodes.concat(noddd) - _this.updateGraph() + _this.graph.links = _this.graph.links.concat(newships) + _this.updategraph() }, drawNode(nodes) { var _this = this @@ -239,7 +258,47 @@ export default { }) nodeEnter.on('mouseleave', function () { console.log('鼠标移出') - d3.select(this).style('stroke-width', '2') + d3.select(this).style('stroke-width', 2) + //todo其他节点和连线一并显示 + d3.select('.node').style('fill-opacity', 1) + d3.select('.nodetext').style('fill-opacity', 1) + d3.selectAll('.linetext').style('fill-opacity', 1) + }) + nodeEnter.on('mouseover', function (d) { + //todo鼠标放上去只显示相关节点,其他节点和连线隐藏 + d3.selectAll('.node').style('fill-opacity', 0.2) + + var relvantNodeIds = [] + var relvantNodes = _this.graph.links.filter(function (n) { + return n.sourceid == d.uuid || n.targetid == d.uuid + }) + relvantNodes.forEach(function (item) { + relvantNodeIds.push(item.sourceid) + relvantNodeIds.push(item.targetid) + }) + _this.qaGraphNode + .selectAll('circle') + .style('fill-opacity', function (c) { + if (relvantNodeIds.indexOf(c.uuid) > -1) { + return 1.0 + } + }) + d3.selectAll('.nodetext').style('fill-opacity', 0.2) + _this.qaGraphNodeText + .selectAll('.nodetext') + .style('fill-opacity', function (c) { + if (relvantNodeIds.indexOf(c.uuid) > -1) { + return 1.0 + } + }) + d3.selectAll('.linetext').style('fill-opacity', 0.2) + _this.qaGraphLinkText + .selectAll('.linetext') + .style('fill-opacity', function (c) { + if (c.lk.targetid === d.uuid) { + return 1.0 + } + }) }) nodeEnter.call( d3 @@ -251,7 +310,7 @@ export default { node = nodeEnter.merge(node).text(function (d) { return d.name }) - node.style('opacity', 0.8) + //node.style('opacity', 0.8) node.style('stroke', function (d) { if (d.color) { return d.color @@ -260,19 +319,42 @@ export default { }) node.style('stroke-opacity', 0.6) node.attr('r', function (d) { + if (d.r) { + return d.r + } return d.index === 0 ? 28 : 20 }) - node.attr('fill', function (d) { - if (d.cur === '1') { - return _this.colorList[0] + node.attr('fill', function (d, i) { + //创建圆形图像 + if (d.imgsrc) { + var img_w = 77, + img_h = 80 + var defs = d3.selectAll('svg >defs') + var catpattern = defs + .append('pattern') + .attr('id', 'catpattern' + i) + .attr('height', 1) + .attr('width', 1) + catpattern + .append('image') + .attr('x', -(img_w / 2 - d.r)) + .attr('y', -(img_h / 2 - d.r)) + .attr('width', img_w) + .attr('height', img_h) + .attr('xlink:href', d.imgsrc) + return 'url(#catpattern' + i + ')' } else { - return _this.colorList[2] + if (d.cur === '1') { + return _this.colorList[0] + } else { + return _this.colorList[2] + } } }) node .append('title') // 为每个节点设置title .text(function (d) { - if (!d.name) { + if (d.name) { return d.name } return '' @@ -329,6 +411,7 @@ export default { var linkEnter = link .enter() .append('line') + //.attr('class', 'link') .attr('stroke-width', 1) .attr('stroke', function () { return _this.colorList[2] @@ -588,7 +671,7 @@ export default { _this.bindEventButtonGroup() }, dragStarted(d) { - if (!d3.event.active) this.simulation.alphaTarget(0.3).restart() + if (!d3.event.active) this.simulation.alphaTarget(0.8).restart() d.fx = d.x d.fy = d.y },