/ concept-collection / benchcompress
Sign in
concept-collection / benchcompress
benchcompress / web-ui / src / components / benchmark / charts / BenchmarkCharts.tsx
153 lines · 4.3 KBCodeBlameHistory
70a7a71code formattingJeremy Magland 1import { useState } from "react";
a2daa82reference compression ratiosJeremy Magland 2import Plot from "react-plotly.js";
eacabc8test real dataJeremy Magland 3
05ee84fimprove bar graphsJeremy Magland 4interface BenchmarkBarChartProps {
5 title: string;
6 data: ChartData[];
7 dataKey: keyof Pick<
8 ChartData,
9 "compression_ratio" | "encode_speed" | "decode_speed"
10 >;
11 color: string;
12 xAxisTitle: string;
15function BenchmarkBarChart({
16 title,
17 data,
18 dataKey,
19 color,
20 xAxisTitle,
21}: BenchmarkBarChartProps) {
22 return (
23 <div style={{ margin: "0 20px 20px 0" }}>
24 <h3 style={{ marginBottom: "10px" }}>{title}</h3>
25 <Plot
26 data={[
27 {
28 type: "bar",
29 orientation: "h",
a2daa82reference compression ratiosJeremy Magland 30 y: data.map((d) => d.algorithmOrDataset),
05ee84fimprove bar graphsJeremy Magland 31 x: data.map((d) => d[dataKey]),
32 marker: { color },
a2daa82reference compression ratiosJeremy Magland 33 name: title,
05ee84fimprove bar graphsJeremy Magland 34 },
a2daa82reference compression ratiosJeremy Magland 35 ...(dataKey === "compression_ratio" &&
36 data.some((d) => d.reference_compression_ratio !== null)
37 ? [
38 ...data
39 .filter((d) => d.reference_compression_ratio !== null)
40 .flatMap((d) => [
41 {
42 type: "scatter" as const,
43 mode: "lines" as const,
44 y: [d.algorithmOrDataset, d.algorithmOrDataset],
45 x: [0, d.reference_compression_ratio],
46 line: { color: "#aaaaaa", width: 1 },
47 showlegend: false,
48 hoverinfo: "skip" as const,
49 },
50 {
51 type: "scatter" as const,
52 mode: "markers" as const,
53 y: [d.algorithmOrDataset],
54 x: [d.reference_compression_ratio],
55 marker: { color: "#aaaaaa", size: 8 },
56 name: "Best Compression",
57 hovertemplate: "Best: %{x:.2f}<extra></extra>",
58 showlegend:
59 d.algorithmOrDataset === data[0].algorithmOrDataset, // Only show legend for first point
60 },
61 ]),
62 ]
63 : []),
05ee84fimprove bar graphsJeremy Magland 64 ]}
65 layout={{
66 width: 700,
67 height: Math.max(300, data.length * 23 + 40),
68 margin: { t: 5, r: 30, l: 200, b: 30 },
69 xaxis: { title: xAxisTitle },
70 yaxis: { automargin: true, ticksuffix: " " },
71 dragmode: false,
72 }}
73 config={{ displayModeBar: false }}
74 />
75 </div>
76 );
eacabc8test real dataJeremy Magland 79interface ChartData {
a2daa82reference compression ratiosJeremy Magland 80 algorithmOrDataset: string;
eacabc8test real dataJeremy Magland 81 compression_ratio: number;
a2daa82reference compression ratiosJeremy Magland 82 reference_compression_ratio: number | null; // the highest compression ratio for the dataset (if algorithmOrDataset is a dataset)
eacabc8test real dataJeremy Magland 83 encode_speed: number;
84 decode_speed: number;
87interface BenchmarkChartsProps {
88 chartData: ChartData[];
a2daa82reference compression ratiosJeremy Magland 89 showSortByCompressionRatio?: boolean;
eacabc8test real dataJeremy Magland 90}
a2daa82reference compression ratiosJeremy Magland 92export function BenchmarkCharts({
93 chartData,
94 showSortByCompressionRatio,
95}: BenchmarkChartsProps) {
96 const [sortByRatio, setSortByRatio] = useState(
97 showSortByCompressionRatio ? true : false,
98 );
100 console.log("--- showSortByCompressionRatio", showSortByCompressionRatio);
eacabc8test real dataJeremy Magland 102 if (!chartData.length) return null;
8a6e869delta encoding for other algsJeremy Magland 104 const sortedData = sortByRatio
105 ? [...chartData].sort((a, b) => a.compression_ratio - b.compression_ratio)
106 : chartData;
eacabc8test real dataJeremy Magland 108 return (
8a6e869delta encoding for other algsJeremy Magland 109 <div>
a2daa82reference compression ratiosJeremy Magland 110 {showSortByCompressionRatio && (
111 <div style={{ marginBottom: "10px" }}>
112 <label style={{ display: "flex", alignItems: "center", gap: "8px" }}>
113 <input
114 type="checkbox"
115 checked={sortByRatio}
116 onChange={(e) => setSortByRatio(e.target.checked)}
117 />
118 Sort by compression ratio
119 </label>
120 </div>
121 )}
05ee84fimprove bar graphsJeremy Magland 122 <div
123 style={{
124 display: "flex",
125 flexWrap: "wrap",
126 gap: "20px",
127 }}
128 >
129 <BenchmarkBarChart
130 title="Compression Ratio"
131 data={sortedData}
132 dataKey="compression_ratio"
133 color="#8884d8"
134 xAxisTitle="Ratio"
135 />
136 <BenchmarkBarChart
137 title="Encode Speed (MB/s)"
138 data={sortedData}
139 dataKey="encode_speed"
140 color="#82ca9d"
141 xAxisTitle="MB/s"
142 />
143 <BenchmarkBarChart
144 title="Decode Speed (MB/s)"
145 data={sortedData}
146 dataKey="decode_speed"
147 color="#ff7300"
148 xAxisTitle="MB/s"
149 />
8a6e869delta encoding for other algsJeremy Magland 150 </div>
eacabc8test real dataJeremy Magland 151 </div>
152 );
moveopenescclose