fix(plugin-chart-echarts): use scale for truncating x-axis (#26269)

This commit is contained in:
Ville Brofeldt
2023-12-14 10:13:39 -08:00
committed by GitHub
parent 429e2a33c3
commit 67468c46c0
7 changed files with 172 additions and 39 deletions

View File

@@ -20,32 +20,32 @@
import { invert } from 'lodash';
import {
AnnotationLayer,
buildCustomFormatters,
CategoricalColorNamespace,
CurrencyFormatter,
ensureIsArray,
GenericDataType,
getCustomFormatter,
getNumberFormatter,
getXAxisLabel,
isDefined,
isEventAnnotationLayer,
isFormulaAnnotationLayer,
isIntervalAnnotationLayer,
isPhysicalColumn,
isTimeseriesAnnotationLayer,
QueryFormData,
QueryFormMetric,
TimeseriesChartDataResponseResult,
TimeseriesDataRecord,
getXAxisLabel,
isPhysicalColumn,
isDefined,
ensureIsArray,
buildCustomFormatters,
ValueFormatter,
QueryFormMetric,
getCustomFormatter,
CurrencyFormatter,
} from '@superset-ui/core';
import { getOriginalSeries } from '@superset-ui/chart-controls';
import { EChartsCoreOption, SeriesOption } from 'echarts';
import {
DEFAULT_FORM_DATA,
EchartsMixedTimeseriesFormData,
EchartsMixedTimeseriesChartTransformedProps,
EchartsMixedTimeseriesFormData,
EchartsMixedTimeseriesProps,
} from './types';
import {
@@ -55,14 +55,15 @@ import {
} from '../types';
import { parseAxisBound } from '../utils/controls';
import {
getOverMaxHiddenFormatter,
dedupSeries,
extractDataTotalValues,
extractSeries,
extractShowValueIndexes,
getAxisType,
getColtypesMapping,
getLegendProps,
extractDataTotalValues,
extractShowValueIndexes,
getMinAndMaxFromBounds,
getOverMaxHiddenFormatter,
} from '../utils/series';
import {
extractAnnotationLabels,
@@ -84,7 +85,7 @@ import {
transformSeries,
transformTimeseriesAnnotation,
} from '../Timeseries/transformers';
import { TIMESERIES_CONSTANTS, TIMEGRAIN_TO_TIMESTAMP } from '../constants';
import { TIMEGRAIN_TO_TIMESTAMP, TIMESERIES_CONSTANTS } from '../constants';
import { getDefaultTooltip } from '../utils/tooltip';
import {
getTooltipTimeFormatter,
@@ -166,6 +167,7 @@ export default function transformProps(
showValueB,
stack,
stackB,
truncateXAxis,
truncateYAxis,
tooltipTimeFormat,
yAxisFormat,
@@ -181,6 +183,7 @@ export default function transformProps(
zoomable,
richTooltip,
tooltipSortByMetric,
xAxisBounds,
xAxisLabelRotation,
groupby,
groupbyB,
@@ -345,7 +348,8 @@ export default function transformProps(
});
// yAxisBounds need to be parsed to replace incompatible values with undefined
let [min, max] = (yAxisBounds || []).map(parseAxisBound);
const [xAxisMin, xAxisMax] = (xAxisBounds || []).map(parseAxisBound);
let [yAxisMin, yAxisMax] = (yAxisBounds || []).map(parseAxisBound);
let [minSecondary, maxSecondary] = (yAxisBoundsSecondary || []).map(
parseAxisBound,
);
@@ -386,7 +390,7 @@ export default function transformProps(
formatter:
seriesType === EchartsTimeseriesSeriesType.Bar
? getOverMaxHiddenFormatter({
max,
max: yAxisMax,
formatter: seriesFormatter,
})
: seriesFormatter,
@@ -447,8 +451,8 @@ export default function transformProps(
// default to 0-100% range when doing row-level contribution chart
if (contributionMode === 'row' && stack) {
if (min === undefined) min = 0;
if (max === undefined) max = 1;
if (yAxisMin === undefined) yAxisMin = 0;
if (yAxisMax === undefined) yAxisMax = 1;
if (minSecondary === undefined) minSecondary = 0;
if (maxSecondary === undefined) maxSecondary = 1;
}
@@ -499,13 +503,23 @@ export default function transformProps(
xAxisType === 'time' && timeGrainSqla
? TIMEGRAIN_TO_TIMESTAMP[timeGrainSqla]
: 0,
...getMinAndMaxFromBounds(
xAxisType,
truncateXAxis,
xAxisMin,
xAxisMax,
seriesType === EchartsTimeseriesSeriesType.Bar ||
seriesTypeB === EchartsTimeseriesSeriesType.Bar
? EchartsTimeseriesSeriesType.Bar
: undefined,
),
},
yAxis: [
{
...defaultYAxis,
type: logAxis ? 'log' : 'value',
min,
max,
min: yAxisMin,
max: yAxisMax,
minorTick: { show: true },
minorSplitLine: { show: minorSplitLine },
axisLabel: {