Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
@aduh95/viz.js
Advanced tools
@aduh95/viz.js is a JavaScript wrapper for Graphviz, a popular open-source graph visualization software. It allows you to create, manipulate, and render graphs using the DOT language directly in JavaScript environments, including Node.js and browsers.
Render DOT to SVG
This feature allows you to render a DOT string into an SVG element. The code sample demonstrates how to create a simple directed graph from node 'a' to node 'b' and append the resulting SVG to the document body.
const viz = new Viz();
viz.renderSVGElement('digraph { a -> b; }')
.then(function(element) {
document.body.appendChild(element);
});
Render DOT to PNG
This feature allows you to render a DOT string into a PNG image element. The code sample shows how to create a simple directed graph and append the resulting PNG image to the document body.
const viz = new Viz();
viz.renderImageElement('digraph { a -> b; }')
.then(function(element) {
document.body.appendChild(element);
});
Render DOT to plain text
This feature allows you to render a DOT string into plain text. The code sample demonstrates how to create a simple directed graph and log the resulting plain text representation to the console.
const viz = new Viz();
viz.renderString('digraph { a -> b; }')
.then(function(result) {
console.log(result);
});
viz.js is another JavaScript wrapper for Graphviz. It is similar to @aduh95/viz.js but is more widely used and has a larger community. It also supports rendering graphs in various formats such as SVG, PNG, and plain text.
d3-graphviz is a D3-based library for rendering Graphviz DOT files. It integrates well with the D3.js ecosystem, allowing for more complex and interactive visualizations. It is more suitable for users who are already familiar with D3.js.
graphviz-cli is a command-line interface for Graphviz. It allows you to render DOT files to various formats using the command line. It is more suitable for users who prefer working with the command line rather than a JavaScript environment.
This project builds Graphviz with Emscripten and provides a simple wrapper for using it in the browser.
For more information, see the wiki.
Have a look at Dagre, which is not a hack.
import Viz from "@aduh95/viz.js";
import getWorker from "@aduh95/viz.js/worker";
const worker = getWorker();
const viz = new Viz({ worker });
viz
.renderString("digraph{1 -> 2 }")
.then(svgString => {
console.log(svgString);
})
.catch(error => {
console.error(error);
})
.finally(() => {
// If you don't terminate the worker explicitly, it will be terminated at the end of process
worker.terminate();
});
If you want to use it from a CommonJS script, you would need to use a dynamic imports:
async function dot2svg(dot, options = {}) {
const Viz = await import("@aduh95/viz.js").then(module => module.default);
const worker = await import("@aduh95/viz.js/worker").then(module =>
module.default()
);
const viz = new Viz({ worker });
return viz.renderString(dot, options);
}
In a world where Import Maps and import.meta.resolve
are reality, you could
have something like that:
import Viz from "@aduh95/viz.js";
async function dot2svg(dot, options) {
const workerURL = await import.meta.resolve("@aduh95/viz.js/worker");
const viz = new Viz({ workerURL });
return viz.renderString(dot, options);
}
To build from source, first install the Emscripten SDK. You'll also need Node.js and Yarn.
On macOS:
brew install binaryen emscripten automake libtool pkg-config qt
You will certainly need to tweak config files to make sure your system knows where it should find each binary.
The build process for Viz.js is split into two parts: building the Graphviz and Expat dependencies, and building the rendering script files and API.
make deps
make all
Install the development dependencies using Yarn:
$ yarn install
$ yarn test
FAQs
A hack to put Graphviz on the web.
The npm package @aduh95/viz.js receives a total of 256,349 weekly downloads. As such, @aduh95/viz.js popularity was classified as popular.
We found that @aduh95/viz.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.