fix: Time-series Line Chart Display unnecessary total (#31181)

This commit is contained in:
Michael S. Molina
2024-11-27 15:29:09 -03:00
committed by GitHub
parent f0811c8863
commit dbcb473040
3 changed files with 45 additions and 5 deletions

View File

@@ -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));