From 9f95fa9c95e3bfed880089e02af439ae90cfa38b Mon Sep 17 00:00:00 2001 From: Geno Date: Wed, 1 Nov 2017 11:43:20 +0100 Subject: [PATCH] [BUGFIX] Select correct goto link --- lib/forcegraph.js | 17 ++++++++--------- lib/forcegraph/draw.js | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/forcegraph.js b/lib/forcegraph.js index d3f0b88..ceecedc 100644 --- a/lib/forcegraph.js +++ b/lib/forcegraph.js @@ -242,12 +242,9 @@ define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease', self.gotoNode = function gotoNode(d) { moveTo(function calcToNode() { - for (var i = 0; i < intNodes.length; i++) { - var n = intNodes[i]; - if (n.o.node_id !== d.node_id) { - continue; - } - draw.setHighlight({ type: 'node', o: n.o }); + draw.setHighlight({ type: 'node', id: d.node_id }); + var n = dictNodes[d.node_id]; + if (n) { return [n.x, n.y, (ZOOM_MAX + 1) / 2]; } return [0, 0, (ZOOM_MIN + 1) / 2]; @@ -256,9 +253,11 @@ define(['d3-selection', 'd3-force', 'd3-zoom', 'd3-drag', 'd3-timer', 'd3-ease', self.gotoLink = function gotoLink(d) { moveTo(function calcToLink() { - draw.setHighlight({ type: 'link', o: d }); - for (var i = 0; i < intLinks.length; i++) { - var l = intLinks[i]; + draw.setHighlight({ type: 'link', id: d.id }); + var l = intLinks.find(function (link) { + return link.o.id === d.id; + }); + if (l) { return [(l.source.x + l.target.x) / 2, (l.source.y + l.target.y) / 2, (ZOOM_MAX / 2) + ZOOM_MIN]; } return [0, 0, (ZOOM_MIN + 1) / 2]; diff --git a/lib/forcegraph/draw.js b/lib/forcegraph/draw.js index f5c2ed2..38323f7 100644 --- a/lib/forcegraph/draw.js +++ b/lib/forcegraph/draw.js @@ -32,7 +32,7 @@ define(['helper'], function (helper) { } function drawHighlightNode(d) { - if (highlight && highlight.type === 'node' && d.o.node_id === highlight.o.node_id) { + if (highlight && highlight.type === 'node' && d.o.node_id === highlight.id) { ctx.arc(d.x, d.y, NODE_RADIUS * 1.5, 0, 2 * Math.PI); ctx.fillStyle = highlightColor; ctx.fill(); @@ -41,7 +41,7 @@ define(['helper'], function (helper) { } function drawHighlightLink(d, to) { - if (highlight && highlight.type === 'link' && d.o.id === highlight.o.id) { + if (highlight && highlight.type === 'link' && d.o.id === highlight.id) { ctx.lineTo(to[0], to[1]); ctx.strokeStyle = highlightColor; ctx.lineWidth = LINE_RADIUS * 2;