| | |
| | | p {{toolTipAddr}} |
| | | d3-network( |
| | | ref='net' |
| | | :startX="startX" |
| | | :net-nodes="nodes" |
| | | :net-links="links" |
| | | :options="options" |
| | |
| | | @drag-start='dragStart' |
| | | @node-click='nodeClick' |
| | | @node-hover='nodeHover' |
| | | @node-out='nodeOut' |
| | | @node-out='nodeOut' |
| | | ) |
| | | </template> |
| | | |
| | | |
| | | <script> |
| | | import D3Network from "./vue-d3-network"; |
| | | import RoleIcon from "./icons.js"; |
| | |
| | | }, |
| | | props: { |
| | | agent: String, |
| | | members: Array |
| | | members: Array, |
| | | sizeX: Number, |
| | | sizeY: Number, |
| | | startX: Number, |
| | | isShowHover: Boolean |
| | | }, |
| | | data() { |
| | | data () { |
| | | return { |
| | | nodeSize: 20, |
| | | fontSize: 20, |
| | |
| | | toolTipStyle: { |
| | | display: "none", |
| | | height: "30px", |
| | | width: "120px" |
| | | width: "150px" |
| | | } |
| | | }; |
| | | }, |
| | | computed: { |
| | | nodes() { |
| | | nodes () { |
| | | let n = new Array(); |
| | | this.members.forEach((v, i) => { |
| | | n.push({ |
| | |
| | | name: v.nodeName, |
| | | svgSym: RoleIcon[v.role], |
| | | _color: |
| | | this.agent === v.nodeName |
| | | ? "red" |
| | | : v.role === "master" |
| | | ? "orange" |
| | | : "" |
| | | v.role === "master" |
| | | ? "orange" |
| | | : "" |
| | | |
| | | }); |
| | | }); |
| | | |
| | | return n; |
| | | }, |
| | | links() { |
| | | links () { |
| | | let arr = new Array(); |
| | | let dup = new Array(); // Deduplicate to ensure that two nodes have only one line |
| | | const count = this.members.length; |
| | |
| | | |
| | | return arr; |
| | | }, |
| | | options() { |
| | | options () { |
| | | return { |
| | | force: 3000, |
| | | nodeSize: this.nodeSize, |
| | |
| | | nodeLabels: true, |
| | | canvas: this.canvas, |
| | | linkWidth: 0, |
| | | // size: { |
| | | // w: 745, |
| | | // h: 426 |
| | | // } |
| | | size: { |
| | | w: 745, |
| | | h: 426 |
| | | w: this.sizeX || 445, |
| | | h: this.sizeY || 426 |
| | | } |
| | | }; |
| | | } |
| | | }, |
| | | created() { |
| | | created () { |
| | | this.reset(); |
| | | }, |
| | | methods: { |
| | | nodeHover(event, node) { |
| | | nodeHover (event, node) { |
| | | console.log(node); |
| | | node._opacity = 1; |
| | | node._size = 28; |
| | | let width = document.body.clientWidth; |
| | | this.toolTipStyle.display = "block"; |
| | | this.toolTipStyle.top = node.y - 10 + "px"; |
| | | this.toolTipStyle.left = node.x + width / 2 - 30 + "px"; |
| | | //let width = document.body.clientWidth; |
| | | if (this.isShowHover) { |
| | | this.toolTipStyle.display = "block"; |
| | | this.toolTipStyle.top = node.y - 60 + "px"; |
| | | this.toolTipStyle.left = node.x + "px"; |
| | | console.log(this.members[node.id]) |
| | | this.toolTipNode = this.members[node.id].nodeName; |
| | | this.toolTipAddr = this.members[node.id].Address; |
| | | } |
| | | |
| | | this.toolTipNode = this.members[node.id].nodeName; |
| | | this.toolTipAddr = this.members[node.id].Address; |
| | | }, |
| | | nodeOut(event, node) { |
| | | nodeOut (event, node) { |
| | | node._opacity = node.opacity; |
| | | node._size = node.size; |
| | | this.toolTipStyle.display = "none"; |
| | | }, |
| | | dragStart(event) { |
| | | dragStart (event) { |
| | | if (event) { |
| | | this.movement = event.timeStamp; |
| | | } |
| | | }, |
| | | nodeClick(event, node) { |
| | | nodeClick (event, node) { |
| | | // if (this.nodeSelected[node.id]) { |
| | | // this.unSelectNode(node.id) |
| | | // // is not nodeSelected |
| | |
| | | // } |
| | | // this.selectNodesLinks() |
| | | // this.$set(this.nodes, node.index, node) |
| | | |
| | | console.log(event, node) |
| | | debugger |
| | | if (event.timeStamp - this.movement < 200) { |
| | | this.$emit("selected-node", event, this.members[node.id]); |
| | | } |
| | | }, |
| | | reset() { |
| | | reset () { |
| | | this.nodeSelected = {}; |
| | | this.linksSelected = {}; |
| | | (this.toolTipNode = ""), (this.toolTipAddr = ""), (this.movement = 0); |
| | | }, |
| | | unSelectNode(nodeId) { |
| | | unSelectNode (nodeId) { |
| | | if (this.nodeSelected[nodeId]) { |
| | | delete this.nodeSelected[nodeId]; |
| | | } |
| | | this.selectNodesLinks(); |
| | | }, |
| | | unSelectLink(linkId) { |
| | | unSelectLink (linkId) { |
| | | if (this.linksSelected[linkId]) { |
| | | delete this.linksSelected[linkId]; |
| | | } |
| | | }, |
| | | selectNode(node) { |
| | | selectNode (node) { |
| | | this.nodeSelected[node.id] = node; |
| | | }, |
| | | selectLink(link) { |
| | | selectLink (link) { |
| | | this.$set(this.linksSelected, link.id, link); |
| | | }, |
| | | selectNodesLinks() { |
| | | selectNodesLinks () { |
| | | for (let link of this.links) { |
| | | // node is nodeSelected |
| | | if (this.nodeSelected[link.sid] || this.nodeSelected[link.tid]) { |
| | |
| | | } |
| | | }; |
| | | </script> |
| | | |
| | | |
| | | <style> |
| | | .net { |
| | | height: 100%; |
| | | margin: 0; |
| | | position: relative; |
| | | } |
| | | |
| | | .node { |
| | |
| | | .arrow_box p { |
| | | height: 30px; |
| | | line-height: 30px; |
| | | width: 100px; |
| | | width: 100%; |
| | | overflow: hidden; |
| | | } |
| | | .arrow_box:after, |
| | | .arrow_box:before { |
| | | right: 100%; |
| | | top: 50%; |
| | | right: 50%; |
| | | top: 100%; |
| | | border: solid transparent; |
| | | content: " "; |
| | | content: ' '; |
| | | height: 0; |
| | | width: 0; |
| | | position: absolute; |
| | |
| | | border-right-color: #fff; |
| | | border-width: 5px; |
| | | margin-top: -5px; |
| | | transform: translateY(6px) rotateZ(-90deg); |
| | | } |
| | | .arrow_box:before { |
| | | border-color: rgba(194, 225, 245, 0); |
| | | border-right-color: #323333; |
| | | border-width: 6px; |
| | | margin-top: -6px; |
| | | border-width: 5px; |
| | | margin-top: -5px; |
| | | } |
| | | </style> |
| | | .arrow_box:before { |
| | | border-color: rgba(194, 225, 245, 0); |
| | | border-right-color: #323333; |
| | | border-width: 5px; |
| | | margin-top: -5px; |
| | | transform: translateY(6px) rotateZ(-90deg); |
| | | } |
| | | </style> |