Skip to content

Commit 7436c24

Browse files
committed
fix: Use variables from css styles instead hard coded one's for charts
1 parent 52e374c commit 7436c24

2 files changed

Lines changed: 42 additions & 15 deletions

File tree

app/(website)/user/[id]/components/UserPlayHistoryChart.tsx

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import {
1010
} from "recharts";
1111

1212
import { useT } from "@/lib/i18n/utils";
13-
import type {
14-
GetUserByUserIdPlayHistoryGraphResponse,
15-
} from "@/lib/types/api";
13+
import type { GetUserByUserIdPlayHistoryGraphResponse } from "@/lib/types/api";
1614

1715
interface Props {
1816
data: GetUserByUserIdPlayHistoryGraphResponse;
@@ -31,21 +29,41 @@ export default function UserPlayHistoryChart({ data }: Props) {
3129

3230
let { snapshots } = data;
3331

34-
for (let date = firstDate; date <= lastDate; date.setMonth(date.getMonth() + 1)) {
35-
const dateString = date.toLocaleString(locale, { year: "numeric", month: "short" });
36-
if (!snapshots.some(s => new Date(s.saved_at).toLocaleString(locale, { year: "numeric", month: "short" }) === dateString)) {
32+
for (
33+
let date = firstDate;
34+
date <= lastDate;
35+
date.setMonth(date.getMonth() + 1)
36+
) {
37+
const dateString = date.toLocaleString(locale, {
38+
year: "numeric",
39+
month: "short",
40+
});
41+
if (
42+
!snapshots.some(
43+
s =>
44+
new Date(s.saved_at).toLocaleString(locale, {
45+
year: "numeric",
46+
month: "short",
47+
}) === dateString,
48+
)
49+
) {
3750
snapshots.push({
3851
saved_at: date.toISOString(),
3952
play_count: 0,
4053
});
4154
}
4255
}
4356

44-
snapshots = snapshots.sort((b, a) => new Date(b.saved_at).getTime() - new Date(a.saved_at).getTime());
57+
snapshots = snapshots.sort(
58+
(b, a) => new Date(b.saved_at).getTime() - new Date(a.saved_at).getTime(),
59+
);
4560

4661
const chartData = snapshots.map((s) => {
4762
return {
48-
date: new Date(s.saved_at).toLocaleString(locale, { year: "numeric", month: "short" }),
63+
date: new Date(s.saved_at).toLocaleString(locale, {
64+
year: "numeric",
65+
month: "short",
66+
}),
4967
play_count: s.play_count,
5068
};
5169
});
@@ -60,7 +78,10 @@ export default function UserPlayHistoryChart({ data }: Props) {
6078
height="100%"
6179
className="h-52 max-h-52 min-h-52"
6280
>
63-
<LineChart data={chartData} margin={{ top: 5, right: 20, bottom: 40, left: 0 }}>
81+
<LineChart
82+
data={chartData}
83+
margin={{ top: 5, right: 20, bottom: 40, left: 0 }}
84+
>
6485
<CartesianGrid stroke="#e0e0e0" strokeOpacity={0.3} vertical={false} />
6586
<XAxis
6687
dataKey="date"
@@ -76,18 +97,24 @@ export default function UserPlayHistoryChart({ data }: Props) {
7697
return (Math.round(value / 10) * 10).toString();
7798
}}
7899
domain={[
79-
(dataMin: number) => Math.floor(Math.max(0, dataMin - leewayForDomain) / 10) * 10,
80-
(dataMax: number) => Math.ceil((dataMax + leewayForDomain) / 10) * 10,
100+
(dataMin: number) =>
101+
Math.floor(Math.max(0, dataMin - leewayForDomain) / 10) * 10,
102+
(dataMax: number) =>
103+
Math.ceil((dataMax + leewayForDomain) / 10) * 10,
81104
]}
82105
stroke="#666"
83106
tick={{ fontSize: 12 }}
84107
/>
85108

86109
<Line
87110
dataKey="play_count"
88-
stroke="#E0C097"
111+
stroke="hsl(var(--chart-1))"
89112
strokeWidth={2}
90-
dot={{ fill: "#E0C097", strokeWidth: 1, r: isSingleMonthDataPoint ? 2 : 0 }}
113+
dot={{
114+
fill: "hsl(var(--chart-1))",
115+
strokeWidth: 1,
116+
r: isSingleMonthDataPoint ? 2 : 0,
117+
}}
91118
activeDot={{ r: 6 }}
92119
isAnimationActive={false}
93120
/>

app/(website)/user/[id]/components/UserStatsChart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ export default function UserStatsChart({ data, value: chartValue }: Props) {
150150
<Area
151151
type="monotone"
152152
dataKey={chartValue}
153-
stroke="#E0C097"
154-
fill="#E0C097"
153+
stroke="hsl(var(--chart-1))"
154+
fill="hsl(var(--chart-2))"
155155
baseValue={isChartReversed ? "dataMax" : "dataMin"}
156156
isAnimationActive={false}
157157
/>

0 commit comments

Comments
 (0)