feat(plugin-chart-echarts): support non-timeseries x-axis (#17917)

* feat(plugin-chart-echarts): support non-timeseries x-axis

* fix tests

* change formula return type from Date to number

* add x_axis test coverage

* rename func and improve coverage

* add x-axis control to bar chart

* remove redundant console.log

* fix description

* make x-axis control mandatory

* 🙃

* fix x-axis formatter

* fix showValues

* fix implicit rDTTM_ALIAS references in postProcessing

* replace TIME_COLUMN with DTTM_ALIAS

* fix remaining implicit indexes

* fix: Disable filtering on wide result sets (#18021)

* fix: handle null values in time-series table (#18039)

* cleanup column_type_mappings (#17569)

Signed-off-by: Đặng Minh Dũng <dungdm93@live.com>

* important change to MakeFile (#18037)

* add missing is_timeseries to pivot op

Co-authored-by: Erik Ritter <erik.ritter@airbnb.com>
Co-authored-by: Grace Guo <grace.guo@airbnb.com>
Co-authored-by: Đặng Minh Dũng <dungdm93@live.com>
Co-authored-by: AAfghahi <48933336+AAfghahi@users.noreply.github.com>
This commit is contained in:
Ville Brofeldt
2022-01-21 21:23:23 +02:00
committed by GitHub
parent b083b3421f
commit e9651ea52f
42 changed files with 489 additions and 201 deletions

View File

@@ -18,8 +18,8 @@
*/
import {
AnnotationLayer,
AnnotationData,
AnnotationOpacity,
AnnotationResult,
AnnotationSourceType,
AnnotationStyle,
AnnotationType,
@@ -88,6 +88,7 @@ describe('extractAnnotationLabels', () => {
show: true,
style: AnnotationStyle.Solid,
value: 'sin(x)',
showLabel: true,
},
{
annotationType: AnnotationType.Formula,
@@ -95,6 +96,7 @@ describe('extractAnnotationLabels', () => {
show: false,
style: AnnotationStyle.Solid,
value: 'sin(2x)',
showLabel: true,
},
{
annotationType: AnnotationType.Interval,
@@ -103,6 +105,7 @@ describe('extractAnnotationLabels', () => {
show: true,
style: AnnotationStyle.Solid,
value: 1,
showLabel: true,
},
{
annotationType: AnnotationType.Timeseries,
@@ -111,6 +114,7 @@ describe('extractAnnotationLabels', () => {
style: AnnotationStyle.Dashed,
sourceType: AnnotationSourceType.Line,
value: 1,
showLabel: true,
},
{
annotationType: AnnotationType.Timeseries,
@@ -119,9 +123,10 @@ describe('extractAnnotationLabels', () => {
style: AnnotationStyle.Dashed,
sourceType: AnnotationSourceType.Line,
value: 1,
showLabel: true,
},
];
const results: AnnotationResult = {
const results: AnnotationData = {
'My Interval': {
columns: ['col'],
records: [{ col: 1 }],
@@ -147,6 +152,7 @@ describe('evalFormula', () => {
show: true,
style: AnnotationStyle.Solid,
value: 'x+1',
showLabel: true,
};
it('Should evaluate a regular formula', () => {
const data: TimeseriesDataRecord[] = [
@@ -155,8 +161,8 @@ describe('evalFormula', () => {
];
expect(evalFormula(layer, data)).toEqual([
[new Date(0), 1],
[new Date(10), 11],
[0, 1],
[10, 11],
]);
});
@@ -167,8 +173,8 @@ describe('evalFormula', () => {
];
expect(evalFormula({ ...layer, value: 'y = x* 2 -1' }, data)).toEqual([
[new Date(0), -1],
[new Date(10), 19],
[0, -1],
[10, 19],
]);
});
});

View File

@@ -20,7 +20,7 @@ import { getNumberFormatter, getTimeFormatter } from '@superset-ui/core';
import {
dedupSeries,
extractGroupbyLabel,
extractTimeseriesSeries,
extractSeries,
formatSeriesName,
getChartPadding,
getLegendProps,
@@ -30,7 +30,7 @@ import { LegendOrientation, LegendType } from '../../src/types';
import { defaultLegendPadding } from '../../src/defaults';
import { NULL_STRING } from '../../src/constants';
describe('extractTimeseriesSeries', () => {
describe('extractSeries', () => {
it('should generate a valid ECharts timeseries series object', () => {
const data = [
{
@@ -49,23 +49,58 @@ describe('extractTimeseriesSeries', () => {
abc: 5,
},
];
expect(extractTimeseriesSeries(data)).toEqual([
expect(extractSeries(data)).toEqual([
{
id: 'Hulk',
name: 'Hulk',
data: [
[new Date('2000-01-01'), null],
[new Date('2000-02-01'), 2],
[new Date('2000-03-01'), 1],
['2000-01-01', null],
['2000-02-01', 2],
['2000-03-01', 1],
],
},
{
id: 'abc',
name: 'abc',
data: [
[new Date('2000-01-01'), 2],
[new Date('2000-02-01'), 10],
[new Date('2000-03-01'), 5],
['2000-01-01', 2],
['2000-02-01', 10],
['2000-03-01', 5],
],
},
]);
});
it('should remove rows that have a null x-value', () => {
const data = [
{
x: 1,
Hulk: null,
abc: 2,
},
{
x: null,
Hulk: 2,
abc: 10,
},
{
x: 2,
Hulk: 1,
abc: 5,
},
];
expect(extractSeries(data, { xAxis: 'x', removeNulls: true })).toEqual([
{
id: 'Hulk',
name: 'Hulk',
data: [[2, 1]],
},
{
id: 'abc',
name: 'abc',
data: [
[1, 2],
[2, 5],
],
},
]);
@@ -114,21 +149,21 @@ describe('extractTimeseriesSeries', () => {
abc: null,
},
];
expect(extractTimeseriesSeries(data, { fillNeighborValue: 0 })).toEqual([
expect(extractSeries(data, { fillNeighborValue: 0 })).toEqual([
{
id: 'abc',
name: 'abc',
data: [
[new Date('2000-01-01'), null],
[new Date('2000-02-01'), 0],
[new Date('2000-03-01'), 1],
[new Date('2000-04-01'), 0],
[new Date('2000-05-01'), null],
[new Date('2000-06-01'), 0],
[new Date('2000-07-01'), 2],
[new Date('2000-08-01'), 3],
[new Date('2000-09-01'), 0],
[new Date('2000-10-01'), null],
['2000-01-01', null],
['2000-02-01', 0],
['2000-03-01', 1],
['2000-04-01', 0],
['2000-05-01', null],
['2000-06-01', 0],
['2000-07-01', 2],
['2000-08-01', 3],
['2000-09-01', 0],
['2000-10-01', null],
],
},
]);