Skip to content

Commit

Permalink
Merge pull request #6 from magjac/fix-growing-edges-to-nodes-with-url
Browse files Browse the repository at this point in the history
Fix growing edges to nodes with url
  • Loading branch information
Magnus Jacobsson authored Sep 23, 2017
2 parents f8f5314 + 4536f5d commit fdfbbfb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,18 @@ export default function(src) {
var prevStartNode = prevNodeDictionary[startNodeId];
if (prevStartNode) {
var startShape = startNode.children[3];
if (startShape.tag == 'g' && startShape.children[0].tag == 'a') {
startShape = startShape.children[0].children[1];
}
var prevStartShape = prevStartNode.children[3];
if (prevStartShape.tag == 'g' && prevStartShape.children[0].tag == 'a') {
prevStartShape = prevStartShape.children[0].children[1];
}
if (startShape.tag != 'polygon' && startShape.tag != 'ellipse') {
throw Error('Unexpected tag: ' + startShape.tag, '. Please file an issue at https://github.com/magjac/d3-graphviz/issues');
throw Error('Unexpected tag: ' + startShape.tag + '. Please file an issue at https://github.com/magjac/d3-graphviz/issues');
}
if (prevStartShape.tag != 'polygon' && prevStartShape.tag != 'ellipse') {
throw Error('Unexpected tag: ' + prevStartShape.tag, '. Please file an issue at https://github.com/magjac/d3-graphviz/issues');
throw Error('Unexpected tag: ' + prevStartShape.tag + '. Please file an issue at https://github.com/magjac/d3-graphviz/issues');
}
datum.offset = {
x: prevStartShape.center.x - startShape.center.x,
Expand Down
27 changes: 27 additions & 0 deletions test/graphviz-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,30 @@ tape("graphviz().render() renders edges with tooltip attribute.", function(test)

test.end();
});

tape("graphviz().render() renders growing edges to nodes with URL attribute.", function(test) {
var document = global.document = jsdom('<div id="graph"></div>');
var graphviz = d3_graphviz.graphviz("#graph");

graphviz
.tweenShapes(false)
.growEnteringEdges(true)
.zoom(false)
.renderDot('digraph {node [URL="DUMMY-URL"]; a -> b;}');
test.equal(d3.selectAll('.node').size(), 2, 'Number of initial nodes');
test.equal(d3.selectAll('.edge').size(), 1, 'Number of initial edges');
test.equal(d3.selectAll('g').size(), 6, 'Number of groups');
test.equal(d3.selectAll('a').size(), 2, 'Number of hyperlinks');
test.equal(d3.selectAll('ellipse').size(), 2, 'Number of ellipses');
test.equal(d3.selectAll('path').size(), 1, 'Number of paths');
graphviz
.renderDot('digraph {node [URL="DUMMY-URL"]; a -> b; a -> c}')
test.equal(d3.selectAll('.node').size(), 3, 'Number of nodes after add');
test.equal(d3.selectAll('.edge').size(), 2, 'Number of edges after add');
test.equal(d3.selectAll('g').size(), 9, 'Number of groups');
test.equal(d3.selectAll('a').size(), 3, 'Number of hyperlinks');
test.equal(d3.selectAll('ellipse').size(), 3, 'Number of ellipses');
test.equal(d3.selectAll('path').size(), 2, 'Number of paths');

test.end();
});

0 comments on commit fdfbbfb

Please sign in to comment.