fix: Time-series Line Chart Display unnecessary total (#31181)
This commit is contained in:
parent
f0811c8863
commit
dbcb473040
|
|
@ -171,6 +171,8 @@ export default function transformProps(
|
|||
stack,
|
||||
tooltipTimeFormat,
|
||||
tooltipSortByMetric,
|
||||
showTooltipTotal,
|
||||
showTooltipPercentage,
|
||||
truncateXAxis,
|
||||
truncateYAxis,
|
||||
xAxis: xAxisOrig,
|
||||
|
|
@ -192,7 +194,9 @@ export default function transformProps(
|
|||
}: EchartsTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData };
|
||||
const refs: Refs = {};
|
||||
const groupBy = ensureIsArray(groupby);
|
||||
const labelMap = Object.entries(label_map).reduce((acc, entry) => {
|
||||
const labelMap: { [key: string]: string[] } = Object.entries(
|
||||
label_map,
|
||||
).reduce((acc, entry) => {
|
||||
if (
|
||||
entry[1].length > groupBy.length &&
|
||||
Array.isArray(timeCompare) &&
|
||||
|
|
@ -487,7 +491,9 @@ export default function transformProps(
|
|||
minorTick: { show: minorTicks },
|
||||
minInterval:
|
||||
xAxisType === AxisType.Time && timeGrainSqla
|
||||
? TIMEGRAIN_TO_TIMESTAMP[timeGrainSqla]
|
||||
? TIMEGRAIN_TO_TIMESTAMP[
|
||||
timeGrainSqla as keyof typeof TIMEGRAIN_TO_TIMESTAMP
|
||||
]
|
||||
: 0,
|
||||
...getMinAndMaxFromBounds(
|
||||
xAxisType,
|
||||
|
|
@ -567,8 +573,9 @@ export default function transformProps(
|
|||
value.observation !== undefined ? acc + value.observation : acc,
|
||||
0,
|
||||
);
|
||||
const showTotal = Boolean(isMultiSeries) && richTooltip && !isForecast;
|
||||
const showPercentage = showTotal && !forcePercentFormatter;
|
||||
const allowTotal = Boolean(isMultiSeries) && richTooltip && !isForecast;
|
||||
const showPercentage =
|
||||
allowTotal && !forcePercentFormatter && showTooltipPercentage;
|
||||
const keys = Object.keys(forecastValues);
|
||||
let focusedRow;
|
||||
sortedKeys
|
||||
|
|
@ -599,7 +606,7 @@ export default function transformProps(
|
|||
focusedRow = rows.length - focusedRow - 1;
|
||||
}
|
||||
}
|
||||
if (showTotal) {
|
||||
if (allowTotal && showTooltipTotal) {
|
||||
const totalRow = ['Total', formatter.format(total)];
|
||||
if (showPercentage) {
|
||||
totalRow.push(percentFormatter.format(1));
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ export type EchartsTimeseriesFormData = QueryFormData & {
|
|||
stack: StackType;
|
||||
timeCompare?: string[];
|
||||
tooltipTimeFormat?: string;
|
||||
showTooltipTotal?: boolean;
|
||||
showTooltipPercentage?: boolean;
|
||||
truncateXAxis: boolean;
|
||||
truncateYAxis: boolean;
|
||||
yAxisFormat?: string;
|
||||
|
|
|
|||
|
|
@ -210,9 +210,40 @@ const tooltipSortByMetricControl: ControlSetItem = {
|
|||
},
|
||||
};
|
||||
|
||||
const tooltipTotalControl: ControlSetItem = {
|
||||
name: 'showTooltipTotal',
|
||||
config: {
|
||||
type: 'CheckboxControl',
|
||||
label: t('Show total'),
|
||||
renderTrigger: true,
|
||||
default: true,
|
||||
description: t('Whether to display the total value in the tooltip'),
|
||||
visibility: ({ controls, form_data }: ControlPanelsContainerProps) =>
|
||||
Boolean(controls?.rich_tooltip?.value) &&
|
||||
form_data.viz_type !== 'mixed_timeseries',
|
||||
},
|
||||
};
|
||||
|
||||
const tooltipPercentageControl: ControlSetItem = {
|
||||
name: 'showTooltipPercentage',
|
||||
config: {
|
||||
type: 'CheckboxControl',
|
||||
label: t('Show percentage'),
|
||||
renderTrigger: true,
|
||||
default: true,
|
||||
description: t('Whether to display the percentage value in the tooltip'),
|
||||
visibility: ({ controls, form_data }: ControlPanelsContainerProps) =>
|
||||
Boolean(controls?.rich_tooltip?.value) &&
|
||||
!controls?.contributionMode?.value &&
|
||||
form_data.viz_type !== 'mixed_timeseries',
|
||||
},
|
||||
};
|
||||
|
||||
export const richTooltipSection: ControlSetRow[] = [
|
||||
[<ControlSubSectionHeader>{t('Tooltip')}</ControlSubSectionHeader>],
|
||||
[richTooltipControl],
|
||||
[tooltipTotalControl],
|
||||
[tooltipPercentageControl],
|
||||
[tooltipSortByMetricControl],
|
||||
[tooltipTimeFormatControl],
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in New Issue