From 441945e075b4048bf1cc8e4239c97e3071dfdd0d Mon Sep 17 00:00:00 2001 From: Pablo Lara Date: Mon, 19 Aug 2024 10:52:44 +0200 Subject: [PATCH] feat: Status chart is ready --- components/charts/StatusChart.tsx | 64 ++++++++++++++++++++++++++++--- styles/globals.css | 4 +- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/components/charts/StatusChart.tsx b/components/charts/StatusChart.tsx index 7f68ae2842..ec0253b529 100644 --- a/components/charts/StatusChart.tsx +++ b/components/charts/StatusChart.tsx @@ -1,9 +1,11 @@ "use client"; +import { Chip, Divider, Spacer } from "@nextui-org/react"; import { TrendingUp } from "lucide-react"; import * as React from "react"; import { Label, Pie, PieChart } from "recharts"; +import { NotificationIcon, SuccessIcon } from "../icons"; import { ChartConfig, ChartContainer, @@ -11,11 +13,28 @@ import { ChartTooltipContent, } from "../ui"; +const calculatePercent = ( + chartData: { findings: string; number: number; fill: string }[], +) => { + const total = chartData.reduce((sum, item) => sum + item.number, 0); + + return chartData.map((item) => ({ + ...item, + percent: Math.round((item.number / total) * 100) + "%", + })); +}; + const chartData = [ - { findings: "Success", number: 436, fill: "var(--color-success)" }, + { + findings: "Success", + number: 436, + fill: "var(--color-success)", + }, { findings: "Fail", number: 293, fill: "var(--color-fail)" }, ]; +const updatedChartData = calculatePercent(chartData); + const chartConfig = { number: { label: "Findings", @@ -51,7 +70,7 @@ export function StatusChart() {
} /> @@ -94,12 +113,45 @@ export function StatusChart() { -
-
+
+
+ } + color="success" + radius="lg" + size="md" + > + {chartData[0].number} + + + {updatedChartData[0].percent} + +
+
No change from last scan
-
- +2 findings from last scan + +
+
+ } + color="danger" + radius="lg" + size="md" + > + {chartData[1].number} + + + {updatedChartData[1].percent} + +
+
+ +2 findings from last scan +
diff --git a/styles/globals.css b/styles/globals.css index ddd03cc1db..5998e6242c 100644 --- a/styles/globals.css +++ b/styles/globals.css @@ -4,8 +4,8 @@ @layer base { :root { - --chart-success: 149 80% 35%; - --chart-fail: 348 83% 50%; + --chart-success: 146 80% 35%; + --chart-fail: 339 90% 51%; --chart-1: 12 76% 61%; --chart-3: 197 37% 24%; --chart-4: 43 74% 66%;