♻ Refactor Bar charts
This commit is contained in:
1 parent
5f7a4e6ff2
commit
a9f81737d5
1 file changed
+19
-33
@@ -1,5 +1,5 @@
|
|||||||
import { useQuery } from "@apollo/client";
|
import { useQuery } from "@apollo/client";
|
||||||
import { Bar } from "@nivo/bar";
|
import { Bar, BarDatum } from "@nivo/bar";
|
||||||
import { Pie } from "@nivo/pie";
|
import { Pie } from "@nivo/pie";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
@@ -27,6 +27,20 @@ const months = {
|
|||||||
11: "November",
|
11: "November",
|
||||||
12: "Desember",
|
12: "Desember",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const OrderBar = ({ data }: { data: BarDatum[] }) => (
|
||||||
|
<Bar
|
||||||
|
data={data}
|
||||||
|
margin={{ left: 60, bottom: 40 }}
|
||||||
|
width={1200}
|
||||||
|
height={400}
|
||||||
|
colorBy="indexValue"
|
||||||
|
enableLabel={false}
|
||||||
|
tooltipLabel={(d) => d.id.toString()}
|
||||||
|
axisLeft={{ legend: "Ordre", legendPosition: "middle", legendOffset: -50 }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
export const Stats = () => {
|
export const Stats = () => {
|
||||||
const { data: productData, loading: productLoading } = useQuery(ProductStatsDocument, {
|
const { data: productData, loading: productLoading } = useQuery(ProductStatsDocument, {
|
||||||
variables: { active: true },
|
variables: { active: true },
|
||||||
@@ -61,66 +75,38 @@ export const Stats = () => {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<h3>Ordre per time</h3>
|
<h3>Ordre per time</h3>
|
||||||
<Bar
|
<OrderBar
|
||||||
data={(orderData?.orderStats?.hourly || []).map((stat: OrderStatsByTime) => ({
|
data={(orderData?.orderStats?.hourly || []).map((stat: OrderStatsByTime) => ({
|
||||||
id: `${stat.period.toString().padStart(2, "0")}:00`,
|
id: `${stat.period.toString().padStart(2, "0")}:00`,
|
||||||
label: stat.period,
|
label: stat.period,
|
||||||
value: stat.count,
|
value: stat.count,
|
||||||
}))}
|
}))}
|
||||||
margin={{ left: 60, bottom: 40 }}
|
|
||||||
width={1200}
|
|
||||||
height={400}
|
|
||||||
colorBy="indexValue"
|
|
||||||
enableLabel={false}
|
|
||||||
tooltipLabel={(d) => d.id.toString()}
|
|
||||||
axisLeft={{ legend: "Ordre", legendPosition: "middle", legendOffset: -50 }}
|
|
||||||
/>
|
/>
|
||||||
<h3>Ordre per ukedag</h3>
|
<h3>Ordre per ukedag</h3>
|
||||||
<Bar
|
<OrderBar
|
||||||
data={(orderData?.orderStats?.daily || []).map((stat: OrderStatsByTime) => ({
|
data={(orderData?.orderStats?.daily || []).map((stat: OrderStatsByTime) => ({
|
||||||
/* @ts-expect-error Here, stat.period can only be a key in days range. */
|
/* @ts-expect-error Here, stat.period can only be a key in days range. */
|
||||||
id: days[stat.period],
|
id: days[stat.period],
|
||||||
label: stat.period,
|
label: stat.period,
|
||||||
value: stat.count,
|
value: stat.count,
|
||||||
}))}
|
}))}
|
||||||
margin={{ left: 60, bottom: 40 }}
|
|
||||||
width={1200}
|
|
||||||
height={400}
|
|
||||||
colorBy="indexValue"
|
|
||||||
enableLabel={false}
|
|
||||||
tooltipLabel={(d) => d.id.toString()}
|
|
||||||
axisLeft={{ legend: "Ordre", legendPosition: "middle", legendOffset: -50 }}
|
|
||||||
/>
|
/>
|
||||||
<h3>Ordre per måned</h3>
|
<h3>Ordre per måned</h3>
|
||||||
<Bar
|
<OrderBar
|
||||||
data={(orderData?.orderStats?.monthly || []).map((stat: OrderStatsByTime) => ({
|
data={(orderData?.orderStats?.monthly || []).map((stat: OrderStatsByTime) => ({
|
||||||
/* @ts-expect-error Here, stat.period can only be a key in months range. */
|
/* @ts-expect-error Here, stat.period can only be a key in months range. */
|
||||||
id: months[stat.period],
|
id: months[stat.period],
|
||||||
label: stat.period,
|
label: stat.period,
|
||||||
value: stat.count,
|
value: stat.count,
|
||||||
}))}
|
}))}
|
||||||
margin={{ left: 60, bottom: 40 }}
|
|
||||||
width={1200}
|
|
||||||
height={400}
|
|
||||||
colorBy="indexValue"
|
|
||||||
enableLabel={false}
|
|
||||||
tooltipLabel={(d) => d.id.toString()}
|
|
||||||
axisLeft={{ legend: "Ordre", legendPosition: "middle", legendOffset: -50 }}
|
|
||||||
/>
|
/>
|
||||||
<h3>Ordre per år</h3>
|
<h3>Ordre per år</h3>
|
||||||
<Bar
|
<OrderBar
|
||||||
data={(orderData?.orderStats?.yearly || []).map((stat: OrderStatsByTime) => ({
|
data={(orderData?.orderStats?.yearly || []).map((stat: OrderStatsByTime) => ({
|
||||||
id: stat.period,
|
id: stat.period,
|
||||||
label: stat.period,
|
label: stat.period,
|
||||||
value: stat.count,
|
value: stat.count,
|
||||||
}))}
|
}))}
|
||||||
margin={{ left: 60, bottom: 40 }}
|
|
||||||
width={1200}
|
|
||||||
height={400}
|
|
||||||
colorBy="indexValue"
|
|
||||||
enableLabel={false}
|
|
||||||
tooltipLabel={(d) => d.id.toString()}
|
|
||||||
axisLeft={{ legend: "Ordre", legendPosition: "middle", legendOffset: -50 }}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user