From 7256abd846f3809b3ffc1e3b18db4236a42adbc4 Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 18 Feb 2021 20:28:42 +0200 Subject: [PATCH] fix: proper bar-chart tooltip callback Signed-off-by: Roman --- src/renderer/components/chart/bar-chart.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/renderer/components/chart/bar-chart.tsx b/src/renderer/components/chart/bar-chart.tsx index 62c71cae93..74ee203d4c 100644 --- a/src/renderer/components/chart/bar-chart.tsx +++ b/src/renderer/components/chart/bar-chart.tsx @@ -3,7 +3,7 @@ import merge from "lodash/merge"; import moment from "moment"; import Color from "color"; import { observer } from "mobx-react"; -import { ChartData, ChartOptions, ChartPoint, Scriptable } from "chart.js"; +import { ChartData, ChartOptions, ChartPoint, ChartTooltipItem, Scriptable } from "chart.js"; import { Chart, ChartKind, ChartProps } from "./chart"; import { bytesToUnits, cssNames } from "../../utils"; import { ZebraStripes } from "./zebra-stripes.plugin"; @@ -115,10 +115,13 @@ export class BarChart extends React.Component { mode: "index", position: "cursor", callbacks: { - title: tooltipItems => { - if (new Date(tooltipItems[0].xLabel).getTime() > Date.now()) return ""; + title([tooltip]: ChartTooltipItem[]) { + const xLabel = tooltip?.xLabel; + const skipLabel = xLabel == null || new Date(xLabel).getTime() > Date.now(); - return `${tooltipItems[0].xLabel}`; + if (skipLabel) return ""; + + return String(xLabel); }, labelColor: ({ datasetIndex }) => { return {