From e22f8216e881195d1782911efb791d546e308ef2 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Fri, 8 Apr 2022 10:27:55 +0300 Subject: [PATCH] Move tooltipLabels prop to PieCharts Signed-off-by: Alex Andreev --- .../components/+cluster/cluster-pie-charts.tsx | 8 ++++---- .../overview-workload-status.tsx | 6 +++--- src/renderer/components/chart/chart.tsx | 3 --- src/renderer/components/chart/pie-chart.tsx | 15 +++++++++++++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/renderer/components/+cluster/cluster-pie-charts.tsx b/src/renderer/components/+cluster/cluster-pie-charts.tsx index abf469e979..259a0e4741 100644 --- a/src/renderer/components/+cluster/cluster-pie-charts.tsx +++ b/src/renderer/components/+cluster/cluster-pie-charts.tsx @@ -12,7 +12,7 @@ import { MetricNodeRole } from "./cluster-overview-store/cluster-overview-store" import { Spinner } from "../spinner"; import { Icon } from "../icon"; import { nodesStore } from "../+nodes/nodes.store"; -import type { ChartData } from "../chart"; +import type { PieChartData } from "../chart"; import { PieChart } from "../chart"; import { ClusterNoMetrics } from "./cluster-no-metrics"; import { bytesToUnits, cssNames } from "../../utils"; @@ -49,7 +49,7 @@ const NonInjectedClusterPieCharts = observer(({ clusterOverviewStore }: Dependen const defaultColor = ThemeStore.getInstance().activeTheme.colors.pieChartDefaultColor; if (!memoryCapacity || !cpuCapacity || !podCapacity || !memoryAllocatableCapacity || !cpuAllocatableCapacity || !podAllocatableCapacity) return null; - const cpuData: ChartData = { + const cpuData: PieChartData = { datasets: [ { data: [ @@ -96,7 +96,7 @@ const NonInjectedClusterPieCharts = observer(({ clusterOverviewStore }: Dependen ["Capacity", cpuCapacity], ]), }; - const memoryData: ChartData = { + const memoryData: PieChartData = { datasets: [ { data: [ @@ -143,7 +143,7 @@ const NonInjectedClusterPieCharts = observer(({ clusterOverviewStore }: Dependen `Capacity: ${bytesToUnits(memoryCapacity)}`, ], }; - const podsData: ChartData = { + const podsData: PieChartData = { datasets: [ { data: [ diff --git a/src/renderer/components/+workloads-overview/overview-workload-status.tsx b/src/renderer/components/+workloads-overview/overview-workload-status.tsx index 1d174203a3..e2092e61c0 100644 --- a/src/renderer/components/+workloads-overview/overview-workload-status.tsx +++ b/src/renderer/components/+workloads-overview/overview-workload-status.tsx @@ -8,7 +8,7 @@ import "./overview-workload-status.scss"; import React from "react"; import capitalize from "lodash/capitalize"; import { observer } from "mobx-react"; -import type { ChartData, ChartTooltipLabel } from "../chart"; +import type { DatasetTooltipLabel, PieChartData } from "../chart"; import { PieChart } from "../chart"; import { cssVar } from "../../utils"; import { ThemeStore } from "../../theme.store"; @@ -27,7 +27,7 @@ export class OverviewWorkloadStatus extends React.Component = { + const chartData: Required = { labels: [], datasets: [], }; @@ -43,7 +43,7 @@ export class OverviewWorkloadStatus extends React.Component string | string; - export enum ChartKind { PIE = "pie", BAR = "bar", diff --git a/src/renderer/components/chart/pie-chart.tsx b/src/renderer/components/chart/pie-chart.tsx index 57aafa84b2..a117e03137 100644 --- a/src/renderer/components/chart/pie-chart.tsx +++ b/src/renderer/components/chart/pie-chart.tsx @@ -8,7 +8,7 @@ import React from "react"; import { observer } from "mobx-react"; import type { ChartOptions } from "chart.js"; import ChartJS from "chart.js"; -import type { ChartData, ChartProps } from "./chart"; +import type { ChartProps } from "./chart"; import { Chart } from "./chart"; import { cssNames } from "../../utils"; import { ThemeStore } from "../../theme.store"; @@ -16,6 +16,17 @@ import { ThemeStore } from "../../theme.store"; export interface PieChartProps extends ChartProps { } +export interface PieChartData extends ChartJS.ChartData { + datasets?: PieChartDataSets[]; +} + +export type DatasetTooltipLabel = (percent: string) => string | string; + +interface PieChartDataSets extends ChartJS.ChartDataSets { + id?: string; + tooltipLabels?: DatasetTooltipLabel[]; +} + @observer export class PieChart extends React.Component { render() { @@ -28,7 +39,7 @@ export class PieChart extends React.Component { mode: "index", callbacks: { title: () => "", - label: (tooltipItem, data: ChartData) => { + label: (tooltipItem, data: PieChartData) => { const dataset = data.datasets[tooltipItem.datasetIndex]; const datasetData = dataset.data as number[]; const total = datasetData.reduce((acc, cur) => acc + cur, 0);