Giter VIP home page Giter VIP logo

viz.js's Introduction

Viz.js

This project is a Makefile for building Graphviz with Emscripten and a simple wrapper for using it in the browser.

Getting Viz.js

Install with Bower:

bower install viz.js

Or with npm:

npm install viz.js

Or download the viz.js "binary" from the releases page.

"Lite" Version

A smaller version of Viz.js can be downloaded from the releases page and is available in the Bower package. viz-lite.js omits Expat and the NEATO layout plugin.

API

Viz(src, options={ format="svg", engine="dot", scale, totalMemory=16777216 })

  • src is a string representing the graph to render in the DOT language.
  • options
    • format sets the output format, and may be one of "svg", "xdot", "plain", "ps", "json", or "png-image-element".
    • engine sets the Graphviz engine to use, and may be one of "circo", "dot", "neato", "osage", or "twopi".
    • scale sets the scale factor for the "png-image-element" format. If this is not specified, window.devicePixelRatio will be used if available, and 1 if not.
    • totalMemory sets the total memory available for the Emscripten module instance. This should be a power of 2. The default of 16MB should be sufficient for most cases โ€” only consider using a larger number if you run into the error "Cannot enlarge memory arrays".

Parses src and renders a graph according to the options given. Output is a string, except when using the "png-image-element" format, when it is returned as an instance of HTMLImageElement.

For example:

result = Viz("digraph { a -> b; }");
result = Viz("digraph { a -> b; }", { format: "png-image-element", scale: 2 });
result = Viz("graph { n0 -- n1 -- n2 -- n3 -- n0; }", { engine: "neato" });
result = Viz("digraph { x -> y -> z; }", { format: "plain" });

If Graphviz encounters an error, Viz will throw an Error object with the error message.

Viz.svgXmlToPngImageElement(svgXml[, scale[, callback]])

  • svgXml is an SVG XML string, as may be obtained from the Viz function using the "svg" format option.
  • scale sets the scale factor for the output. If this is not specified, window.devicePixelRatio will be used if available, and 1 if not.
  • callback is an optional Node-style callback. If specified, it is given two arguments, (err, image). If not specified, Viz.svgXmlToPngImageElement returns an instance of HTMLImageElement.

Converts svgXml to a PNG HTMLImageElement. If callback is specfied, image is loaded by the time the callback is invoked.

Viz.svgXmlToPngBase64(svgXml, scale, callback)

  • svgXml is an SVG XML string, as may be obtained from the Viz function using the "svg" format option.
  • scale sets the scale factor for the output. If this is given as undefined, window.devicePixelRatio will be used if available, and 1 if not.
  • callback is a Node-style callback. It is given two arguments, (err, data).

Converts svgXml to a PNG represented as a Base64 string. This function requires a callback, unlike svgXmlToPngImageElement.

Supported Graphviz features

These engines are supported:

  • circo
  • dot
  • fdp
  • neato
  • osage
  • twopi

These formats are supported:

  • svg
  • xdot
  • plain
  • ps
  • json

PNG output

Viz.js provides the "png-image-element" format in addition to the regular Graphviz formats. This returns an HTMLImageElement which can be inserted into the document.

image = Viz("digraph g { a -> b; }", { format: "png-image-element" });
document.body.appendChild(image);

However, this won't work in a Web Worker context. In that case, ask for the "svg" format in the worker and convert using the accessory function Viz.svgXmlToPngImageElement in the window context. See tests/png.js for an example.

Internet Explorer support

Internet Explorer 10 and 11 require Fabric.js as an optional dependency for PNG output. Viz.js will look for a fabric object as a member of the global object with a loadSVGFromString() function and use that if present.

Build

To build from source, you will need to install the Emscripten SDK.

To download the sources and build everything:

make

Donate

If you find Viz.js useful, please consider a donation. Thank you!

Click here to lend your support to: Viz.js and make a donation at pledgie.com !

viz.js's People

Contributors

mdaines avatar ivangoncharov avatar jed avatar cyshi avatar

Watchers

DreamChaser avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.