import * as React from "react"; import { D3ForceGraph, D3ForceGraphParameters } from "./D3ForceGraph"; export interface GraphVizComponentProps { forceGraphParams: D3ForceGraphParameters; } /** * Both React and D3 are modifying the DOM and therefore should not share control. * The approach taken here is to block React updates and let d3 take control of the dom and do its thing. */ export class GraphVizComponent extends React.Component { private forceGraph: D3ForceGraph; private rootNode: Element; public constructor(props: GraphVizComponentProps) { super(props); this.forceGraph = new D3ForceGraph(this.props.forceGraphParams); } public componentDidMount(): void { this.forceGraph.init(this.rootNode); } public shouldComponentUpdate(): boolean { // Prevents component re-rendering return false; } public componentWillUnmount(): void { this.forceGraph.destroy(); } public render(): JSX.Element { return ( this.setRef(elt)}> Main Graph {/* svg load more icon inlined as-is here: remove the style="fill:#374649;" so we can override it */} {/* */} {/* */} {/**/} ); } private setRef(element: Element): void { this.rootNode = element; } }