-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGraphvizViewer.tsx
More file actions
47 lines (42 loc) · 1.44 KB
/
GraphvizViewer.tsx
File metadata and controls
47 lines (42 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import * as React from "react";
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
const classNames = require("./graphviz_viewer");
type DivProps = JSX.IntrinsicElements["div"];
interface GraphvizViewerProps extends DivProps {
svgElement: string | undefined;
}
const GraphvizViewer = ({ svgElement, ...props }: GraphvizViewerProps) => {
if (typeof svgElement !== "string") {
return <div>Now loading ....</div>;
}
return (
<div {...props}>
<TransformWrapper defaultScale={1} options={{ minScale: 0.1 }}>
{({ zoomIn, zoomOut, resetTransform, ...rest }: any) => (
<React.Fragment>
<div className={classNames.tool}>
<button className={classNames.button} onClick={zoomIn}>
ZOOM IN
</button>
<button className={classNames.button} onClick={zoomOut}>
ZOOM OUT
</button>
<button className={classNames.button} onClick={resetTransform}>
RESET
</button>
</div>
<TransformComponent>
<div
className={classNames.viewer}
dangerouslySetInnerHTML={{
__html: svgElement,
}}
/>
</TransformComponent>
</React.Fragment>
)}
</TransformWrapper>
</div>
);
};
export { GraphvizViewerProps as Props, GraphvizViewer as Component };