Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reword README, use a graph object in example #197

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is a collection of packages for working with <a href="https://graphviz.org">Graphviz</a> in JavaScript. The main package, [viz](./packages/viz), is a WebAssembly build of Graphviz with a simple JavaScript wrapper.

With Viz.js, you can easily render a graph written in [Graphviz's DOT language](https://www.graphviz.org/doc/info/lang.html) and display it as an SVG element in a webpage:
With Viz.js, you can easily render a graph diagram as an SVG element to display it in a webpage:

```js
import { instance } from "@viz-js/viz";
Expand Down
12 changes: 11 additions & 1 deletion packages/examples/parcel/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { graphvizVersion } from "@viz-js/viz";

function randomNode() {
return Math.ceil(Math.random() * 10);
}

function randomGraph() {
return {
edges: Array.from({ length: 10 }, () => ({ tail: randomNode(), head: randomNode() }))
};
}

document.getElementById("version").appendChild(document.createTextNode(graphvizVersion));

import("@viz-js/viz")
.then(module => module.instance())
.then(viz => {
document.getElementById("output").appendChild(viz.renderSVGElement("digraph { a -> b }"));
document.getElementById("output").appendChild(viz.renderSVGElement(randomGraph()));
});
2 changes: 1 addition & 1 deletion packages/examples/parcel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"@viz-js/viz": "3.1.0",
"@viz-js/viz": "3.1.0-dev",
"parcel": "^2.9.3"
},
"browserslist": "> 0.5%, last 2 versions, not dead",
Expand Down
21 changes: 9 additions & 12 deletions packages/viz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,23 @@ Viz.js is published on NPM as `@viz-js/viz`.

## Usage

Call `instance()`, which returns a `Promise` that resolves to a new `Viz` instance. Then call any of the instance's `render` methods to render a graph written in [the DOT language](https://www.graphviz.org/doc/info/lang.html). The `renderSVGElement()` method is convenient for displaying a graph in a webpage. The instance can be reused for multiple `render` calls.
Call `instance()`, which returns a `Promise` that resolves to a new `Viz` instance. Then call any of the instance's `render` methods to render a graph. A graph can be written in [the DOT language](https://www.graphviz.org/doc/info/lang.html) or as a plain JavaScript object. The `renderSVGElement()` method is convenient for displaying a graph in a webpage. The instance can be reused for multiple `render` calls.

```js
<script type="module">

import { instance } from "@viz-js/viz";

instance().then(function(viz) {
// DOT string
document.body.appendChild(viz.renderSVGElement("digraph { a -> b }"));
});

</script>
```

```js
<script src="viz-standalone.js"></script>
<script>

Viz.instance().then(function(viz) {
document.body.appendChild(viz.renderSVGElement("digraph { a -> b }"));

// Graph object
document.body.appendChild(viz.renderSVGElement({
edges: [
{ tail: "a", head: "b" }
]
}));
});

</script>
Expand Down