Skip to content
Snippets Groups Projects
Commit eb40076e authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[ivette] renamed sandboxed diagrams

parent 5b328364
No related branches found
No related tags found
No related merge requests found
...@@ -137,7 +137,7 @@ const byNode = (a: Node, b: Node): number => byStr(a.id, b.id); ...@@ -137,7 +137,7 @@ const byNode = (a: Node, b: Node): number => byStr(a.id, b.id);
const byEdge = (a: Edge, b: Edge): number => byStr(edgeKey(a), edgeKey(b)); const byEdge = (a: Edge, b: Edge): number => byStr(edgeKey(a), edgeKey(b));
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* --- d3-Graphviz Component --- */ /* --- d3-Graphviz view --- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
let divId = 0; let divId = 0;
...@@ -146,6 +146,7 @@ const newDivId = (): string => `dome_d3gv_${++divId}`; ...@@ -146,6 +146,7 @@ const newDivId = (): string => `dome_d3gv_${++divId}`;
interface GraphvizProps extends DiagramProps { size: Size } interface GraphvizProps extends DiagramProps { size: Size }
function GraphvizView(props: GraphvizProps): JSX.Element { function GraphvizView(props: GraphvizProps): JSX.Element {
// --- Model Generation // --- Model Generation
const { direction = 'LR', nodes, edges } = props; const { direction = 'LR', nodes, edges } = props;
const model = React.useMemo(() => { const model = React.useMemo(() => {
...@@ -155,19 +156,22 @@ function GraphvizView(props: GraphvizProps): JSX.Element { ...@@ -155,19 +156,22 @@ function GraphvizView(props: GraphvizProps): JSX.Element {
edges.concat().sort(byEdge).forEach(e => dot.edge(e)); edges.concat().sort(byEdge).forEach(e => dot.edge(e));
return dot.flush(); return dot.flush();
}, [direction, nodes, edges]); }, [direction, nodes, edges]);
// --- Model Update Callback // --- Model Update Callback
const { onModelChanged } = props; const { onModelChanged } = props;
React.useEffect(() => { React.useEffect(() => {
if (onModelChanged) onModelChanged(model); if (onModelChanged) onModelChanged(model);
}, [model, onModelChanged]); }, [model, onModelChanged]);
// --- Rendering
// --- Rendering & Remote
const id = React.useMemo(newDivId, []); const id = React.useMemo(newDivId, []);
const { width, height } = props.size; const { width, height } = props.size;
React.useEffect(() => { React.useEffect(() => {
d3.graphviz(`#${id}`, { d3.graphviz(`#${id}`, {
fit: false, zoom: false, width, height, fit: false, zoom: true, width, height,
}).renderDot(model); }).renderDot(model);
}, [id, model, width, height]); }, [id, model, width, height]);
return ( return (
<Catch label='Graphviz Error'> <Catch label='Graphviz Error'>
<div id={id} className={props.className} /> <div id={id} className={props.className} />
......
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment