Skip to content

Commit 31d67e4

Browse files
committed
Merge branch 'Tali-Dev'
# Conflicts: # bun.lockb # src/components/GraphvizParent.tsx
2 parents df1d9af + 9b63f1e commit 31d67e4

3 files changed

Lines changed: 43 additions & 36 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"@types/lodash": "^4.17.1",
3333
"@types/papaparse": "^5.3.14",
3434
"@types/timsort": "^0.3.3",
35-
"caniuse-lite": "^1.0.30001688",
35+
"caniuse-lite": "^1.0.30001699",
3636
"class-variance-authority": "^0.7.0",
3737
"clsx": "^2.1.1",
3838
"d3": "^7.9.0",

src/components/GraphvizParent.tsx

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

24-
const GraphvizParent: FC<GraphvizParentProps> = ({csvData, filter, selfLoops, minVisits}) => {
24+
const GraphvizParent: React.FC<GraphvizParentProps> = ({
25+
csvData,
26+
filter,
27+
selfLoops,
28+
minVisits,
29+
}) => {
2530
const [dotString, setDotString] = useState<string | null>(null);
2631
const [filteredDotString, setFilteredDotString] = useState<string | null>(null);
2732
const [topDotString, setTopDotString] = useState<string | null>(null);
@@ -120,34 +125,8 @@ const GraphvizParent: FC<GraphvizParentProps> = ({csvData, filter, selfLoops, mi
120125
setFilteredDotString(null);
121126
}
122127
}, [csvData, filter, selfLoops, minVisits, selectedSequence]);
123-
124-
// Render Graphviz graphs using d3-graphviz
125-
const renderGraph = (
126-
dot: string | null,
127-
ref: React.RefObject<HTMLDivElement>,
128-
filename: string,
129-
numberOfGraphs: number
130-
) => {
131-
if (dot && ref.current) {
132-
// Dynamically adjust width based on the number of graphs
133-
const width = numberOfGraphs === 3 ? 325 : 425; // Adjust the width for 3 graphs or 2 graphs
134-
const height = 530; // Fixed height (or adjust dynamically if needed)
135-
136-
graphviz(ref.current)
137-
.width(width)
138-
.height(height)
139-
.renderDot(dot)
140-
.on('end', () => {
141-
const svgElement = ref.current?.querySelector('svg');
142-
if (svgElement) {
143-
exportGraphAsPNG(ref, filename);
144-
}
145-
});
146-
}
147-
};
148-
149-
// Export a graph as high-quality PNG
150-
const exportGraphAsPNG = (graphRef: RefObject<HTMLDivElement>, filename: string) => {
128+
// Export a graph as high-quality PNG
129+
const exportGraphAsPNG = (graphRef: React.RefObject<HTMLDivElement>, filename: string) => {
151130
if (!graphRef.current) return;
152131

153132
const svgElement = graphRef.current.querySelector('svg');
@@ -197,17 +176,43 @@ const GraphvizParent: FC<GraphvizParentProps> = ({csvData, filter, selfLoops, mi
197176

198177
const numberOfGraphs = [topDotString, dotString, filteredDotString].filter(Boolean).length;
199178

179+
// Render Graphviz graphs using d3-graphviz
180+
const renderGraph = (
181+
dot: string | null,
182+
ref: React.RefObject<HTMLDivElement>,
183+
filename: string,
184+
numberOfGraphs: number
185+
) => {
186+
if (dot && ref.current) {
187+
// Dynamically adjust width based on the number of graphs
188+
const width = numberOfGraphs === 3 ? 325 : 425; // Adjust the width for 3 graphs or 2 graphs
189+
const height = 530; // Fixed height (or adjust dynamically if needed)
190+
191+
graphviz(ref.current)
192+
.width(width)
193+
.height(height)
194+
.renderDot(dot)
195+
.on('end', () => {
196+
const svgElement:RefObject<HTMLDivElement>|SVGSVGElement|null|undefined= ref.current?.querySelector('svg');
197+
if (svgElement) {
198+
exportGraphAsPNG(svgElement as unknown as RefObject<HTMLDivElement>, filename);
199+
}
200+
});
201+
}
202+
};
203+
204+
200205
useEffect(() => {
201206
renderGraph(filteredDotString, graphRefFiltered, 'filtered_graph', numberOfGraphs);
202-
}, [topDotString]);
207+
}, [filteredDotString]);
203208

204209
useEffect(() => {
205210
renderGraph(topDotString, graphRefTop, 'selected_sequence', numberOfGraphs);
206-
}, [dotString]);
211+
}, [topDotString]);
207212

208213
useEffect(() => {
209214
renderGraph(dotString, graphRefMain, 'all_students', numberOfGraphs);
210-
}, [filteredDotString]);
215+
}, [dotString]);
211216

212217

213218
return (
@@ -263,4 +268,4 @@ function ExportButton({onClick, label = "Export Image"}: ExportButtonProps) {
263268
{label}
264269
</Button>
265270
);
266-
};
271+
}

src/components/GraphvizProcessing.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Papa from 'papaparse';
22
import {SequenceCount} from "@/Context";
3+
// import {autoType} from "d3";
34

45
interface CSVRow {
56
'Session Id': string;
@@ -20,7 +21,8 @@ interface CSVRow {
2021
export const loadAndSortData = (csvData: string): CSVRow[] => {
2122
const parsedData = Papa.parse<CSVRow>(csvData, {
2223
header: true,
23-
skipEmptyLines: true
24+
skipEmptyLines: true,
25+
delimiter: ',',
2426
}).data;
2527

2628
const transformedData = parsedData.map(row => ({

0 commit comments

Comments
 (0)