Skip to content

Commit df1d9af

Browse files
authored
Merge pull request #57 from CarnegieLearningWeb/dev
Refactor GraphvizParent component to use named imports for React and FC
2 parents e737075 + 0993775 commit df1d9af

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

src/components/GraphvizParent.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// React component code
2-
import React, {useContext, useEffect, useRef, useState} from 'react';
2+
import {FC, RefObject, useContext, useEffect, useRef, useState} from 'react';
33
import {graphviz} from 'd3-graphviz';
44
import {
55
generateDotString,
@@ -21,12 +21,7 @@ interface GraphvizParentProps {
2121
minVisits: number;
2222
}
2323

24-
const GraphvizParent: React.FC<GraphvizParentProps> = ({
25-
csvData,
26-
filter,
27-
selfLoops,
28-
minVisits,
29-
}) => {
24+
const GraphvizParent: FC<GraphvizParentProps> = ({csvData, filter, selfLoops, minVisits}) => {
3025
const [dotString, setDotString] = useState<string | null>(null);
3126
const [filteredDotString, setFilteredDotString] = useState<string | null>(null);
3227
const [topDotString, setTopDotString] = useState<string | null>(null);
@@ -145,14 +140,14 @@ const GraphvizParent: React.FC<GraphvizParentProps> = ({
145140
.on('end', () => {
146141
const svgElement = ref.current?.querySelector('svg');
147142
if (svgElement) {
148-
exportGraphAsPNG(svgElement, filename);
143+
exportGraphAsPNG(ref, filename);
149144
}
150145
});
151146
}
152147
};
153148

154149
// Export a graph as high-quality PNG
155-
const exportGraphAsPNG = (graphRef: React.RefObject<HTMLDivElement>, filename: string) => {
150+
const exportGraphAsPNG = (graphRef: RefObject<HTMLDivElement>, filename: string) => {
156151
if (!graphRef.current) return;
157152

158153
const svgElement = graphRef.current.querySelector('svg');
@@ -215,8 +210,6 @@ const GraphvizParent: React.FC<GraphvizParentProps> = ({
215210
}, [filteredDotString]);
216211

217212

218-
219-
220213
return (
221214
<div className="graphviz-container flex-col w-[500px] items-center">
222215
<ErrorBoundary>

0 commit comments

Comments
 (0)