Skip to content

Instantly share code, notes, and snippets.

@fengmk2
Created January 19, 2019 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fengmk2/ac06c36ee48eeae3c17fb0bae61a1221 to your computer and use it in GitHub Desktop.
Save fengmk2/ac06c36ee48eeae3c17fb0bae61a1221 to your computer and use it in GitHub Desktop.
viz crash.js
'use strict';
const Viz = require('viz.js');
const { Module, render } = require('viz.js/full.render.js');
const viz = new Viz({ Module, render });
let total = 0;
async function graphviz(content) {
const svg = await viz.renderString(content);
total++;
return Buffer.from(svg);
}
const content = `
digraph g {
rankdir=LR;
node [shape=record,width=01,height=.1];
a[label="<1>Hash Table|<2>Node|<3>Node|...|<4>TreeNode"];
{
node1[label="{<1>A1|<2>A2|...|An}"]
node2[label="{<1>B1|<2>B2|...|Bn}"]
subgraph cluster_treenode{
penwidth=0;
node[shape=circle];
root[label="", style=filled,fillcolor=black,width=.2];
n1[label="", style=filled,fillcolor=red,width=.2]
n2[label="", style=filled,fillcolor=black,width=.2]
n3[label="", style=filled,fillcolor=black,width=.2]
n4[label="", style=filled,fillcolor=red,width=.2]
n5[label="", style=filled,fillcolor=black,width=.2]
n6[label="", style=filled,fillcolor=black,width=.2]
root->n1;
n1->n2;
n1->n3;
root->n4;
n4->n5;
n4->n6;
}
}
a:2:e->node1:1 [style=dashed];
a:3:e->node2:1;
a:4:e->root;
}
`;
graphviz(content).then(svg => {
console.log('%j', svg);
});
setInterval(() => {
graphviz(content).then(svg => {
console.log('%d svg length: %d', total, svg.length);
});
}, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment