Skip to content

Commit 93cd600

Browse files
author
pcarapic15
committed
Construct basic speed tradeoff line chart
1 parent 457786f commit 93cd600

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import React from "react";
2+
import {
3+
ScatterChart,
4+
Scatter,
5+
XAxis,
6+
YAxis,
7+
CartesianGrid,
8+
Tooltip,
9+
Legend,
10+
} from "recharts";
11+
12+
const trendLineData = [
13+
{ x: 0.5, y: 0.5 },
14+
{ x: 1, y: 1 },
15+
{ x: 1.5, y: 1.5 },
16+
{ x: 2, y: 2.2 },
17+
{ x: 2.5, y: 3 },
18+
{ x: 3, y: 4 },
19+
{ x: 3.5, y: 5.3 },
20+
{ x: 4, y: 7 },
21+
];
22+
23+
export default function SpeedTradeoffChart() {
24+
return (
25+
<ScatterChart
26+
width={700}
27+
height={450}
28+
margin={{ top: 20, right: 20, bottom: 20, left: 20 }}
29+
className="mx-auto mt-20"
30+
>
31+
<CartesianGrid />
32+
<XAxis
33+
type="number"
34+
dataKey="x"
35+
name="Time"
36+
label={{ value: "Time", position: "insideBottom", offset: -20 }}
37+
/>
38+
<YAxis
39+
type="number"
40+
dataKey="y"
41+
name="Quality"
42+
label={{ value: "Quality", angle: -90, position: "insideLeft" }}
43+
/>
44+
<Tooltip
45+
cursor={{ strokeDasharray: "3 3" }}
46+
formatter={(value, name) => [
47+
`${value}`,
48+
name === "x" ? "Time" : "Quality",
49+
]}
50+
content={({ payload }) =>
51+
payload && payload.length ? (
52+
<div
53+
style={{
54+
background: "#fff",
55+
padding: "5px",
56+
border: "1px solid #ccc",
57+
}}
58+
>
59+
<strong>{payload[0].payload.model}</strong>
60+
<br />
61+
Time: {payload[0].payload.x}
62+
<br />
63+
Quality: {payload[0].payload.y}
64+
</div>
65+
) : null
66+
}
67+
/>
68+
<Legend />
69+
<Scatter
70+
data={trendLineData}
71+
line={{ stroke: "#0690D1", strokeWidth: 4 }}
72+
shape={() => null}
73+
legendType="none"
74+
/>
75+
</ScatterChart>
76+
);
77+
}

src/components/sd-gym/SpeedTradeoffs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react";
2+
import SpeedTradeoffChart from "./SpeedTradeoffChart";
23

34
const SpeedTradeoffs = () => {
45
return (
@@ -7,6 +8,7 @@ const SpeedTradeoffs = () => {
78
<h1 className="heading-600-lg text-[36px] md:text-5xl text-center">
89
The <span className="text-blue-600">Quality-Speed</span> Tradeoffs
910
</h1>
11+
<SpeedTradeoffChart />
1012
</div>
1113
</div>
1214
);

0 commit comments

Comments
 (0)