Skip to content

Commit

Permalink
fix(plugin-chart-echarts): support numerical x-axis (apache#26087)
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro authored and sfirke committed Mar 22, 2024
1 parent 44ab386 commit 8df2684
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
import { invert } from 'lodash';
import {
AnnotationLayer,
AxisType,
buildCustomFormatters,
CategoricalColorNamespace,
CurrencyFormatter,
ensureIsArray,
GenericDataType,
getCustomFormatter,
getMetricLabel,
getNumberFormatter,
getXAxisLabel,
Expand All @@ -34,9 +38,6 @@ import {
isTimeseriesAnnotationLayer,
t,
TimeseriesChartDataResponseResult,
buildCustomFormatters,
getCustomFormatter,
CurrencyFormatter,
} from '@superset-ui/core';
import {
extractExtraMetrics,
Expand All @@ -48,8 +49,8 @@ import { ZRLineType } from 'echarts/types/src/util/types';
import {
EchartsTimeseriesChartProps,
EchartsTimeseriesFormData,
TimeseriesChartTransformedProps,
OrientationType,
TimeseriesChartTransformedProps,
} from './types';
import { DEFAULT_FORM_DATA } from './constants';
import { ForecastSeriesEnum, ForecastValue, Refs } from '../types';
Expand Down Expand Up @@ -88,8 +89,8 @@ import {
} from './transformers';
import {
StackControlsValue,
TIMESERIES_CONSTANTS,
TIMEGRAIN_TO_TIMESTAMP,
TIMESERIES_CONSTANTS,
} from '../constants';
import { getDefaultTooltip } from '../utils/tooltip';
import {
Expand Down Expand Up @@ -448,13 +449,13 @@ export default function transformProps(
rotate: xAxisLabelRotation,
},
minInterval:
xAxisType === 'time' && timeGrainSqla
xAxisType === AxisType.time && timeGrainSqla
? TIMEGRAIN_TO_TIMESTAMP[timeGrainSqla]
: 0,
};
let yAxis: any = {
...defaultYAxis,
type: logAxis ? 'log' : 'value',
type: logAxis ? AxisType.log : AxisType.value,
min,
max,
minorTick: { show: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import {
DTTM_ALIAS,
ensureIsArray,
GenericDataType,
LegendState,
normalizeTimestamp,
NumberFormats,
NumberFormatter,
TimeFormatter,
SupersetTheme,
normalizeTimestamp,
LegendState,
TimeFormatter,
ValueFormatter,
} from '@superset-ui/core';
import { SortSeriesType } from '@superset-ui/chart-controls';
Expand Down Expand Up @@ -512,6 +512,9 @@ export function getAxisType(dataType?: GenericDataType): AxisType {
if (dataType === GenericDataType.TEMPORAL) {
return AxisType.time;
}
if (dataType === GenericDataType.NUMERIC) {
return AxisType.value;
}
return AxisType.category;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import { SortSeriesType } from '@superset-ui/chart-controls';
import {
AxisType,
DataRecord,
GenericDataType,
getNumberFormatter,
Expand All @@ -31,6 +32,7 @@ import {
extractSeries,
extractShowValueIndexes,
formatSeriesName,
getAxisType,
getChartPadding,
getLegendProps,
getOverMaxHiddenFormatter,
Expand Down Expand Up @@ -870,3 +872,10 @@ test('calculateLowerLogTick', () => {
expect(calculateLowerLogTick(2)).toEqual(1);
expect(calculateLowerLogTick(0.005)).toEqual(0.001);
});

test('getAxisType', () => {
expect(getAxisType(GenericDataType.TEMPORAL)).toEqual(AxisType.time);
expect(getAxisType(GenericDataType.NUMERIC)).toEqual(AxisType.value);
expect(getAxisType(GenericDataType.BOOLEAN)).toEqual(AxisType.category);
expect(getAxisType(GenericDataType.STRING)).toEqual(AxisType.category);
});

0 comments on commit 8df2684

Please sign in to comment.