mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Move tooltipLabels into chart datasets
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
55f60ff074
commit
a426daeabb
@ -156,16 +156,16 @@ const NonInjectedClusterPieCharts = observer(({ clusterOverviewStore }: Dependen
|
|||||||
],
|
],
|
||||||
id: "podUsage",
|
id: "podUsage",
|
||||||
label: "Usage",
|
label: "Usage",
|
||||||
|
tooltipLabels: [
|
||||||
|
(percent) => `Usage: ${percent}`,
|
||||||
|
(percent) => `Available: ${percent}`,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
labels: [
|
labels: [
|
||||||
`Usage: ${podUsage || 0}`,
|
`Usage: ${podUsage || 0}`,
|
||||||
`Capacity: ${podAllocatableCapacity}`,
|
`Capacity: ${podAllocatableCapacity}`,
|
||||||
],
|
],
|
||||||
tooltipLabels: [
|
|
||||||
(percent) => `Usage: ${percent}`,
|
|
||||||
(percent) => `Available: ${percent}`,
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -13,12 +13,12 @@ import { Badge } from "../badge";
|
|||||||
|
|
||||||
export interface ChartData extends ChartJS.ChartData {
|
export interface ChartData extends ChartJS.ChartData {
|
||||||
datasets?: ChartDataSets[];
|
datasets?: ChartDataSets[];
|
||||||
tooltipLabels?: ChartTooltipLabel[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ChartDataSets extends ChartJS.ChartDataSets {
|
export interface ChartDataSets extends ChartJS.ChartDataSets {
|
||||||
id?: string;
|
id?: string;
|
||||||
tooltip?: string;
|
tooltip?: string;
|
||||||
|
tooltipLabels?: ChartTooltipLabel[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ChartProps {
|
export interface ChartProps {
|
||||||
@ -37,7 +37,7 @@ export interface ChartProps {
|
|||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChartTooltipLabel = (percent: string) => string | string;
|
export type ChartTooltipLabel = (percent: string) => string | string;
|
||||||
|
|
||||||
export enum ChartKind {
|
export enum ChartKind {
|
||||||
PIE = "pie",
|
PIE = "pie",
|
||||||
|
|||||||
@ -34,7 +34,7 @@ export class PieChart extends React.Component<PieChartProps> {
|
|||||||
const total = datasetData.reduce((acc, cur) => acc + cur, 0);
|
const total = datasetData.reduce((acc, cur) => acc + cur, 0);
|
||||||
const percent = Math.round((dataset.data[tooltipItem["index"]] as number / total) * 100);
|
const percent = Math.round((dataset.data[tooltipItem["index"]] as number / total) * 100);
|
||||||
const percentLabel = isNaN(percent) ? "N/A" : `${percent}%`;
|
const percentLabel = isNaN(percent) ? "N/A" : `${percent}%`;
|
||||||
const tooltipLabel = data.tooltipLabels?.[tooltipItem["index"]];
|
const tooltipLabel = dataset.tooltipLabels?.[tooltipItem["index"]];
|
||||||
let tooltip = `${dataset["label"]}: ${percentLabel}`;
|
let tooltip = `${dataset["label"]}: ${percentLabel}`;
|
||||||
|
|
||||||
if (tooltipLabel) {
|
if (tooltipLabel) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user