Skip to content

Commit

Permalink
Revert "remove pie element"
Browse files Browse the repository at this point in the history
This reverts commit f939fcd.
  • Loading branch information
erikologic committed Oct 26, 2024
1 parent f939fcd commit 1fe4a03
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const defaultConf: Config = [
labels: [Label.amt, Label.uv],
},
},
{
type: "pie",
props: {
labels: [Label.pv, Label.uv, Label.amt],
},
},
{
type: "gauge",
props: {
Expand Down
45 changes: 45 additions & 0 deletions src/lib/chartComponents/StraightAnglePieChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { PieChart } from "@mui/x-charts";
import { getLatest } from "../helpers";
import { Type, type Static } from "@sinclair/typebox";
import { labelSchema } from "../../labels";

export const slug = "pie";

export const jsonSchema = Type.Object(
{
type: Type.Literal(slug),
props: Type.Object({
labels: Type.Array(labelSchema, {
title: "Pie Chart Labels",
description: "The labels to display on the pie chart",
}),
fullPage: Type.Optional(
Type.Boolean({
title: "Should the chart occupy the full page?",
}),
),
}),
},
{
title: "Pie Chart",
description: "A simple pie chart",
},
);

type PieChartSchema = Static<typeof jsonSchema>;

export function Component({ labels, fullPage }: PieChartSchema["props"]) {
return (
<PieChart
series={[
{
arcLabel: (item) => `${item.value}`,
startAngle: -90,
endAngle: 90,
data: labels.map((label) => ({ label, value: getLatest(label) })),
},
]}
height={fullPage ? 800 : 300}
/>
);
}
2 changes: 2 additions & 0 deletions src/lib/chartComponents/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import * as SimpleLineChart from "./SimpleLineChart";
import * as SimpleGauge from "./SimpleGauge";
import * as SimpleBarChart from "./SimpleBarChart";
import * as StackedAreaChart from "./StackedAreaChart";
import * as StraightAnglePieChart from "./StraightAnglePieChart";

export const charts = [
SimpleLineChart,
SimpleGauge,
SimpleBarChart,
StackedAreaChart,
StraightAnglePieChart,
] as const;

0 comments on commit 1fe4a03

Please sign in to comment.