mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
feat: Utility function to render chart tooltips (#27950)
This commit is contained in:
committed by
GitHub
parent
467e612533
commit
b549977f05
@@ -22,13 +22,11 @@ import {
|
||||
NumberFormats,
|
||||
GenericDataType,
|
||||
getMetricLabel,
|
||||
t,
|
||||
smartDateVerboseFormatter,
|
||||
TimeFormatter,
|
||||
getXAxisLabel,
|
||||
Metric,
|
||||
ValueFormatter,
|
||||
getValueFormatter,
|
||||
t,
|
||||
tooltipHtml,
|
||||
} from '@superset-ui/core';
|
||||
import { EChartsCoreOption, graphic } from 'echarts';
|
||||
import {
|
||||
@@ -41,24 +39,6 @@ import { getDateFormatter, parseMetricValue } from '../utils';
|
||||
import { getDefaultTooltip } from '../../utils/tooltip';
|
||||
import { Refs } from '../../types';
|
||||
|
||||
const defaultNumberFormatter = getNumberFormatter();
|
||||
export function renderTooltipFactory(
|
||||
formatDate: TimeFormatter = smartDateVerboseFormatter,
|
||||
formatValue: ValueFormatter | TimeFormatter = defaultNumberFormatter,
|
||||
) {
|
||||
return function renderTooltip(params: { data: TimeSeriesDatum }[]) {
|
||||
return `
|
||||
${formatDate(params[0].data[0])}
|
||||
<br />
|
||||
<strong>
|
||||
${
|
||||
params[0].data[1] === null ? t('N/A') : formatValue(params[0].data[1])
|
||||
}
|
||||
</strong>
|
||||
`;
|
||||
};
|
||||
}
|
||||
|
||||
const formatPercentChange = getNumberFormatter(
|
||||
NumberFormats.PERCENT_SIGNED_1_POINT,
|
||||
);
|
||||
@@ -249,7 +229,18 @@ export default function transformProps(
|
||||
...getDefaultTooltip(refs),
|
||||
show: !inContextMenu,
|
||||
trigger: 'axis',
|
||||
formatter: renderTooltipFactory(formatTime, headerFormatter),
|
||||
formatter: (params: { data: TimeSeriesDatum }[]) =>
|
||||
tooltipHtml(
|
||||
[
|
||||
[
|
||||
metricName,
|
||||
params[0].data[1] === null
|
||||
? t('N/A')
|
||||
: headerFormatter.format(params[0].data[1]),
|
||||
],
|
||||
],
|
||||
formatTime(params[0].data[0]),
|
||||
),
|
||||
},
|
||||
aria: {
|
||||
enabled: true,
|
||||
|
||||
Reference in New Issue
Block a user