Skip to content

Commit

Permalink
SRV-920 feat - calculating correct date for 'X ... ago' tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
nyohasstium committed Jan 6, 2025
1 parent 166aabb commit 75062f9
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import {
getXAxisFormatter,
getYAxisFormatter,
} from '../utils/formatters';
import moment from 'moment';

const getFormatter = (
customFormatters: Record<string, ValueFormatter>,
Expand Down Expand Up @@ -580,7 +581,7 @@ export default function transformProps(
show: !inContextMenu,
trigger: richTooltip ? 'axis' : 'item',
formatter: (params: any) => {
const xValue: number = richTooltip
let xValue: number = richTooltip
? params[0].value[0]
: params.value[0];
const forecastValue: any[] = richTooltip ? params : [params];
Expand Down Expand Up @@ -639,6 +640,15 @@ export default function transformProps(
focusedRow = rows.length - 1;
}
});
const { seriesName } = params
if (seriesName) {
const regex = new RegExp(".*(\\d+) (\\w+) ago")
const result = seriesName.match(regex)
if (result && result.length == 3) {
const [_, diff, diffType] = result
xValue = moment.utc(xValue).subtract(Number(diff), diffType).valueOf()
}
}
return tooltipHtml(rows, tooltipFormatter(xValue), focusedRow);
},
},
Expand Down

0 comments on commit 75062f9

Please sign in to comment.