Skip to content

Instantly share code, notes, and snippets.

@fengmk2 fengmk2/crash.js
Created Jan 19, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.