Skip to content

Instantly share code, notes, and snippets.

@fengmk2
Created January 19, 2019 11:27
Show Gist options
  • Select an option

  • Save fengmk2/ac06c36ee48eeae3c17fb0bae61a1221 to your computer and use it in GitHub Desktop.

Select an option

Save fengmk2/ac06c36ee48eeae3c17fb0bae61a1221 to your computer and use it in GitHub Desktop.

Revisions

  1. fengmk2 created this gist Jan 19, 2019.
    55 changes: 55 additions & 0 deletions crash.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    '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);