Skip to content

Commit 251c4d2

Browse files
committed
refactor(web): replace plotly with chart.js
1 parent 38ee787 commit 251c4d2

File tree

6 files changed

+99
-35
lines changed

6 files changed

+99
-35
lines changed

push_results.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
cp webdriver-ts-results/dist/index.html ../krausest.github.io/js-framework-benchmark/current.html
22
cp webdriver-ts-results/dist/BoxPlotTable*.js ../krausest.github.io/js-framework-benchmark/
3-
cp webdriver-ts-results/dist/plotly*.js ../krausest.github.io/js-framework-benchmark/
3+
cp webdriver-ts-results/dist/chartjs*.js ../krausest.github.io/js-framework-benchmark/
44
cp webdriver-ts-results/dist/index*.css ../krausest.github.io/js-framework-benchmark/
55
cp webdriver-ts-results/dist/index*.js ../krausest.github.io/js-framework-benchmark/
66
cd ../krausest.github.io
77
git add js-framework-benchmark/current.html
88
git add js-framework-benchmark/BoxPlotTable*.js
9-
git add js-framework-benchmark/plotly*.js
9+
git add js-framework-benchmark/chartjs*.js
1010
git add js-framework-benchmark/index*.css
1111
git add js-framework-benchmark/index*.js
1212
git commit -m "update results"

webdriver-ts-results/package-lock.json

Lines changed: 34 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webdriver-ts-results/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"private": true,
55
"type": "module",
66
"dependencies": {
7+
"@sgratzl/chartjs-chart-boxplot": "^4.2.8",
78
"antd": "^5.14.2",
9+
"chart.js": "^4.4.2",
810
"jstat": "^1.9.6",
911
"lucide-react": "^0.344.0",
10-
"plotly.js-cartesian-dist": "2.18.2",
1112
"react": "^18.2.0",
1213
"react-dom": "^18.2.0",
1314
"zustand": "^4.4.1"
Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
import { useRef, useEffect } from "react";
2-
import Plotly from "plotly.js-cartesian-dist";
2+
import { BoxPlotChart } from "@sgratzl/chartjs-chart-boxplot";
3+
import { Chart, ChartConfiguration } from "chart.js";
4+
5+
Chart.register(BoxPlotChart);
6+
7+
const backgroundColor = [
8+
"hsl(0 80% 50%)", // Red
9+
"hsl(40 80% 50%)", // Orange
10+
"hsl(80 80% 50%)", // Yellow
11+
"hsl(120 80% 50%)", // Green
12+
"hsl(160 80% 50%)", // Cyan
13+
"hsl(200 80% 50%)", // Blue
14+
"hsl(240 80% 50%)", // Purple
15+
"hsl(280 80% 50%)", // Magenta
16+
"hsl(320 80% 50%)", // Pink
17+
];
318

419
interface BoxPlotData {
520
framework: string;
@@ -11,34 +26,54 @@ interface Props {
1126
}
1227

1328
const BoxPlotTableChart = ({ traces }: Props) => {
14-
const elemRef = useRef(null);
29+
const chartRef = useRef<HTMLCanvasElement>(null);
1530

1631
useEffect(() => {
17-
const plotlTtraces = traces.map((t) => ({
18-
type: "box",
19-
y: t.values,
20-
boxpoints: false,
21-
jitter: 0.5,
22-
name: t.framework,
23-
boxmean: "sd",
24-
}));
25-
26-
const layout = {
27-
showlegend: false,
28-
margin: {
29-
l: 40,
30-
r: 0,
31-
b: 120,
32-
t: 0,
33-
pad: 0,
32+
const labels: string[] = [];
33+
const data: number[][] = [];
34+
35+
for (const trace of traces) {
36+
labels.push(trace.framework);
37+
data.push(trace.values);
38+
}
39+
40+
const config: ChartConfiguration<"boxplot"> = {
41+
type: "boxplot",
42+
data: {
43+
labels,
44+
datasets: [
45+
{
46+
backgroundColor,
47+
data,
48+
},
49+
],
50+
},
51+
options: {
52+
scales: {
53+
x: {
54+
grid: {
55+
display: false,
56+
},
57+
},
58+
y: {
59+
beginAtZero: false,
60+
},
61+
},
3462
},
3563
};
36-
Plotly.newPlot(elemRef.current, plotlTtraces, layout, {
37-
staticPlot: true,
38-
editable: false,
39-
});
64+
65+
const chart = new BoxPlotChart(chartRef.current!, config);
66+
67+
return () => {
68+
chart.destroy();
69+
};
4070
}, [traces]);
41-
return <div ref={elemRef} style={{ height: "100%", width: "100%" }}></div>;
71+
72+
return (
73+
<div style={{ height: "28rem" }}>
74+
<canvas style={{ maxHeight: "100%" }} ref={chartRef}></canvas>
75+
</div>
76+
);
4277
};
4378

4479
export default BoxPlotTableChart;

webdriver-ts-results/src/components/ResultTable/ResultTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { benchmarks } from "@/results";
77
import { useRootStore } from "@/reducer";
88
import SizeResultsTable from "@/components/tables/SizeResultsTable";
99

10-
const BoxPlotTable = React.lazy(() => import("@/components/BoxPlotTable"));
10+
const BoxPlotTable = React.lazy(() => import("@/components/BoxPlotTable/BoxPlotTable"));
1111

1212
interface Props {
1313
type: FrameworkType;

webdriver-ts-results/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default defineConfig({
1010
rollupOptions: {
1111
output: {
1212
manualChunks: {
13-
plotly: ["plotly.js-cartesian-dist"],
13+
chartjs: ["chart.js", "@sgratzl/chartjs-chart-boxplot"],
1414
},
1515
},
1616
},

0 commit comments

Comments
 (0)