Skip to content

Commit

Permalink
Generate the temporary svg in the DOM
Browse files Browse the repository at this point in the history
instead of in a Document Fragment.

Fixes #2
  • Loading branch information
Magnus Jacobsson committed Aug 29, 2017
1 parent 99eee70 commit b65fe7e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ export default function(src) {
}
);

var newDoc = d3.select(document.createDocumentFragment())
.append('div');
var newDoc = d3.selection()
.append('div')
.attr('display', 'none');

newDoc
.html(svgDoc);
Expand All @@ -171,6 +172,7 @@ export default function(src) {
this._data = data;
this._dictionary = dictionary;
this._nodeDictionary = nodeDictionary;
newDoc.remove();

return this;
};
4 changes: 2 additions & 2 deletions test/graphviz-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tape("graphviz().render() renders an SVG from graphviz DOT.", function(test) {
var document = global.document = jsdom('<div id="graph"></div>');
var graphviz = d3_graphviz.graphviz("#graph");

svgDoc = `<svg width="62pt" height="116pt" viewbox="0.00 0.00 62.00 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
svgDoc = `<svg width="62pt" height="116pt" viewBox="0.00 0.00 62.00 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
<title>%0</title>
<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-112 58,-112 58,4 -4,4"></polygon>
Expand Down Expand Up @@ -92,7 +92,7 @@ tape("graphviz().render() removes SVG elements for nodes and edges when removed
.dot('digraph {a}')
.render();

svgDoc2 = `<svg width="62pt" height="44pt" viewbox="0.00 0.00 62.00 44.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
svgDoc2 = `<svg width="62pt" height="44pt" viewBox="0.00 0.00 62.00 44.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 40)">
<title>%0</title>
<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-40 58,-40 58,4 -4,4"></polygon>
Expand Down

0 comments on commit b65fe7e

Please sign in to comment.