mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
fix(plugin-chart-echarts): force min y-tick for log axis with zero (#24186)
This commit is contained in:
@@ -247,7 +247,7 @@ export function extractSeries(
|
||||
xAxisSortSeries?: SortSeriesType;
|
||||
xAxisSortSeriesAscending?: boolean;
|
||||
} = {},
|
||||
): [SeriesOption[], number[]] {
|
||||
): [SeriesOption[], number[], number | undefined] {
|
||||
const {
|
||||
fillNeighborValue,
|
||||
xAxis = DTTM_ALIAS,
|
||||
@@ -261,7 +261,7 @@ export function extractSeries(
|
||||
xAxisSortSeries,
|
||||
xAxisSortSeriesAscending,
|
||||
} = opts;
|
||||
if (data.length === 0) return [[], []];
|
||||
if (data.length === 0) return [[], [], undefined];
|
||||
const rows: DataRecord[] = data.map(datum => ({
|
||||
...datum,
|
||||
[xAxis]: datum[xAxis],
|
||||
@@ -287,18 +287,27 @@ export function extractSeries(
|
||||
totalStackedValue: totalStackedValues[idx],
|
||||
}));
|
||||
|
||||
let minPositiveValue: number | undefined;
|
||||
const finalSeries = sortedSeries.map(name => ({
|
||||
id: name,
|
||||
name,
|
||||
data: sortedRows
|
||||
.map(({ row, totalStackedValue }, idx) => {
|
||||
const currentValue = row[name];
|
||||
if (
|
||||
typeof currentValue === 'number' &&
|
||||
currentValue > 0 &&
|
||||
(minPositiveValue === undefined || minPositiveValue > currentValue)
|
||||
) {
|
||||
minPositiveValue = currentValue;
|
||||
}
|
||||
const isNextToDefinedValue =
|
||||
isDefined(rows[idx - 1]?.[name]) || isDefined(rows[idx + 1]?.[name]);
|
||||
const isFillNeighborValue =
|
||||
!isDefined(row[name]) &&
|
||||
!isDefined(currentValue) &&
|
||||
isNextToDefinedValue &&
|
||||
fillNeighborValue !== undefined;
|
||||
let value: DataRecordValue | undefined = row[name];
|
||||
let value: DataRecordValue | undefined = currentValue;
|
||||
if (isFillNeighborValue) {
|
||||
value = fillNeighborValue;
|
||||
} else if (
|
||||
@@ -315,6 +324,7 @@ export function extractSeries(
|
||||
return [
|
||||
finalSeries,
|
||||
sortedRows.map(({ totalStackedValue }) => totalStackedValue),
|
||||
minPositiveValue,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -518,3 +528,8 @@ export function getOverMaxHiddenFormatter(
|
||||
id: NumberFormats.OVER_MAX_HIDDEN,
|
||||
});
|
||||
}
|
||||
|
||||
export function calculateLowerLogTick(minPositiveValue: number) {
|
||||
const logBase10 = Math.floor(Math.log10(minPositiveValue));
|
||||
return Math.pow(10, logBase10);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user