You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2023/12/04 17:09:34 UTC
(superset) 07/16: fix(plugin-chart-echarts): support numerical x-axis (#26087)
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/superset.git
commit b900cb7c3ab198b252e3b65988271b6d2b912af8
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Fri Nov 24 07:36:32 2023 -0800
fix(plugin-chart-echarts): support numerical x-axis (#26087)
(cherry picked from commit aad67e43dbabadad9a5e4accb29ecefb39315f6e)
---
.../plugin-chart-echarts/src/Timeseries/transformProps.ts | 15 ++++++++-------
.../plugins/plugin-chart-echarts/src/utils/series.ts | 9 ++++++---
.../plugin-chart-echarts/test/utils/series.test.ts | 9 +++++++++
3 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
index f76c457e1c..d59da861a0 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
@@ -20,9 +20,13 @@
import { invert } from 'lodash';
import {
AnnotationLayer,
+ AxisType,
+ buildCustomFormatters,
CategoricalColorNamespace,
+ CurrencyFormatter,
ensureIsArray,
GenericDataType,
+ getCustomFormatter,
getMetricLabel,
getNumberFormatter,
getXAxisLabel,
@@ -34,9 +38,6 @@ import {
isTimeseriesAnnotationLayer,
t,
TimeseriesChartDataResponseResult,
- buildCustomFormatters,
- getCustomFormatter,
- CurrencyFormatter,
} from '@superset-ui/core';
import {
extractExtraMetrics,
@@ -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';
@@ -90,8 +91,8 @@ import {
} from './transformers';
import {
StackControlsValue,
- TIMESERIES_CONSTANTS,
TIMEGRAIN_TO_TIMESTAMP,
+ TIMESERIES_CONSTANTS,
} from '../constants';
import { getDefaultTooltip } from '../utils/tooltip';
import { getYAxisFormatter } from '../utils/getYAxisFormatter';
@@ -446,13 +447,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 },
diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts b/superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts
index 663548f25d..bd4e329d0b 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts
@@ -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';
@@ -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;
}
diff --git a/superset-frontend/plugins/plugin-chart-echarts/test/utils/series.test.ts b/superset-frontend/plugins/plugin-chart-echarts/test/utils/series.test.ts
index 75faee93e5..927ee49e8c 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/test/utils/series.test.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/test/utils/series.test.ts
@@ -18,6 +18,7 @@
*/
import { SortSeriesType } from '@superset-ui/chart-controls';
import {
+ AxisType,
DataRecord,
GenericDataType,
getNumberFormatter,
@@ -31,6 +32,7 @@ import {
extractSeries,
extractShowValueIndexes,
formatSeriesName,
+ getAxisType,
getChartPadding,
getLegendProps,
getOverMaxHiddenFormatter,
@@ -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);
+});