fix(line-chart): Formula Annotations on Line Charts are broken (#20687)

This commit is contained in:
Stephen Liu
2022-07-13 16:42:11 +08:00
committed by GitHub
parent bd6037ef50
commit acdb271422
7 changed files with 63 additions and 18 deletions

View File

@@ -25,6 +25,7 @@ import {
AnnotationType,
FormulaAnnotationLayer,
TimeseriesDataRecord,
DataRecord,
} from '@superset-ui/core';
import {
evalFormula,
@@ -160,7 +161,7 @@ describe('evalFormula', () => {
{ __timestamp: 10 },
];
expect(evalFormula(layer, data)).toEqual([
expect(evalFormula(layer, data, '__timestamp', 'time')).toEqual([
[0, 1],
[10, 11],
]);
@@ -172,9 +173,27 @@ describe('evalFormula', () => {
{ __timestamp: 10 },
];
expect(evalFormula({ ...layer, value: 'y = x* 2 -1' }, data)).toEqual([
expect(
evalFormula(
{ ...layer, value: 'y = x* 2 -1' },
data,
'__timestamp',
'time',
),
).toEqual([
[0, -1],
[10, 19],
]);
});
it('Should evaluate a formula if axis type is category', () => {
const data: DataRecord[] = [{ gender: 'boy' }, { gender: 'girl' }];
expect(
evalFormula({ ...layer, value: 'y = 1000' }, data, 'gender', 'category'),
).toEqual([
['boy', 1000],
['girl', 1000],
]);
});
});