This repository is for PoC. Please copy and use.
This repository shows an example of integrating ReactDOM and @ts-graphviz/react
to display the image output from Graphviz on the browser.
Check the result with this DEMO
If you use Graphviz component, you can display the image output by Graphviz
without being aware of the boundary between ReactDOM and @ts-graphviz/react as shown below.
import { FC } from 'react';
import { render } from 'react-dom';
import { Digraph, Edge, Node } from '@ts-graphviz/react';
import { wasmFolder } from '@hpcc-js/wasm';
import { Graphviz } from './components/Graphviz'
export const App: FC = () => {
return (
<div>
<Graphviz>
<Digraph>
<Node id="a" />
<Node id="b" />
<Edge targets={['a', 'b']} />
</Digraph>
</Graphviz>
</div>
);
};
wasmFolder('https://cdn.jsdelivr.net/npm/@hpcc-js/wasm/dist');
render(<App />, document.getElementById('root'));This repository uses @hpcc-js/wasm to run Graphviz on the browser.
Since @hpcc-js/wasm uses WASM internally, there are restrictions on the browsers that can be executed.
Check the result with this DEMO.
The following processing is performed inside the Graphviz component.
- Converts
@ts-graphviz/react's components inside aGraphvizcomponent to a string in dot language format.- Don't include components for ReactDOM (such as
div) withinGraphvizcomponents.
- Don't include components for ReactDOM (such as
- The graphviz module in the
@hpcc-js/wasmpackage does the dot to svg conversion. - The output svg is inserted in the DOM.
This software is released under the MIT License, see LICENSE.