1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

fix: proper bar-chart tooltip callback

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-02-18 20:28:42 +02:00
parent 9ef6c28902
commit 7256abd846

View File

@ -3,7 +3,7 @@ import merge from "lodash/merge";
import moment from "moment"; import moment from "moment";
import Color from "color"; import Color from "color";
import { observer } from "mobx-react"; 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 { Chart, ChartKind, ChartProps } from "./chart";
import { bytesToUnits, cssNames } from "../../utils"; import { bytesToUnits, cssNames } from "../../utils";
import { ZebraStripes } from "./zebra-stripes.plugin"; import { ZebraStripes } from "./zebra-stripes.plugin";
@ -115,10 +115,13 @@ export class BarChart extends React.Component<Props> {
mode: "index", mode: "index",
position: "cursor", position: "cursor",
callbacks: { callbacks: {
title: tooltipItems => { title([tooltip]: ChartTooltipItem[]) {
if (new Date(tooltipItems[0].xLabel).getTime() > Date.now()) return ""; 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 }) => { labelColor: ({ datasetIndex }) => {
return { return {