-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters