mirror of
https://github.com/apache/superset.git
synced 2024-09-20 04:29:47 -04:00
e9651ea52f
* 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>
181 lines
5.2 KiB
TypeScript
181 lines
5.2 KiB
TypeScript
/**
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
* or more contributor license agreements. See the NOTICE file
|
|
* distributed with this work for additional information
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
* to you under the Apache License, Version 2.0 (the
|
|
* "License"); you may not use this file except in compliance
|
|
* with the License. You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing,
|
|
* software distributed under the License is distributed on an
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
* KIND, either express or implied. See the License for the
|
|
* specific language governing permissions and limitations
|
|
* under the License.
|
|
*/
|
|
import {
|
|
AnnotationLayer,
|
|
AnnotationData,
|
|
AnnotationOpacity,
|
|
AnnotationSourceType,
|
|
AnnotationStyle,
|
|
AnnotationType,
|
|
FormulaAnnotationLayer,
|
|
TimeseriesDataRecord,
|
|
} from '@superset-ui/core';
|
|
import {
|
|
evalFormula,
|
|
extractAnnotationLabels,
|
|
formatAnnotationLabel,
|
|
parseAnnotationOpacity,
|
|
} from '../../src/utils/annotation';
|
|
|
|
describe('formatAnnotationLabel', () => {
|
|
it('should handle default cases properly', () => {
|
|
expect(formatAnnotationLabel('name')).toEqual('name');
|
|
expect(formatAnnotationLabel('name', 'title')).toEqual('name - title');
|
|
expect(formatAnnotationLabel('name', 'title', ['description'])).toEqual(
|
|
'name - title\n\ndescription',
|
|
);
|
|
});
|
|
|
|
it('should handle missing cases properly', () => {
|
|
expect(formatAnnotationLabel()).toEqual('');
|
|
expect(formatAnnotationLabel(undefined, 'title')).toEqual('title');
|
|
expect(formatAnnotationLabel('name', undefined, ['description'])).toEqual(
|
|
'name\n\ndescription',
|
|
);
|
|
expect(
|
|
formatAnnotationLabel(undefined, undefined, ['description']),
|
|
).toEqual('description');
|
|
});
|
|
|
|
it('should handle multiple descriptions properly', () => {
|
|
expect(
|
|
formatAnnotationLabel('name', 'title', [
|
|
'description 1',
|
|
'description 2',
|
|
]),
|
|
).toEqual('name - title\n\ndescription 1\ndescription 2');
|
|
expect(
|
|
formatAnnotationLabel(undefined, undefined, [
|
|
'description 1',
|
|
'description 2',
|
|
]),
|
|
).toEqual('description 1\ndescription 2');
|
|
});
|
|
});
|
|
|
|
describe('extractForecastSeriesContext', () => {
|
|
it('should extract the correct series name and type', () => {
|
|
expect(parseAnnotationOpacity(AnnotationOpacity.Low)).toEqual(0.2);
|
|
expect(parseAnnotationOpacity(AnnotationOpacity.Medium)).toEqual(0.5);
|
|
expect(parseAnnotationOpacity(AnnotationOpacity.High)).toEqual(0.8);
|
|
expect(parseAnnotationOpacity(AnnotationOpacity.Undefined)).toEqual(1);
|
|
expect(parseAnnotationOpacity(undefined)).toEqual(1);
|
|
});
|
|
});
|
|
|
|
describe('extractAnnotationLabels', () => {
|
|
it('should extract all annotations that can be added to the legend', () => {
|
|
const layers: AnnotationLayer[] = [
|
|
{
|
|
annotationType: AnnotationType.Formula,
|
|
name: 'My Formula',
|
|
show: true,
|
|
style: AnnotationStyle.Solid,
|
|
value: 'sin(x)',
|
|
showLabel: true,
|
|
},
|
|
{
|
|
annotationType: AnnotationType.Formula,
|
|
name: 'My Hidden Formula',
|
|
show: false,
|
|
style: AnnotationStyle.Solid,
|
|
value: 'sin(2x)',
|
|
showLabel: true,
|
|
},
|
|
{
|
|
annotationType: AnnotationType.Interval,
|
|
name: 'My Interval',
|
|
sourceType: AnnotationSourceType.Table,
|
|
show: true,
|
|
style: AnnotationStyle.Solid,
|
|
value: 1,
|
|
showLabel: true,
|
|
},
|
|
{
|
|
annotationType: AnnotationType.Timeseries,
|
|
name: 'My Line',
|
|
show: true,
|
|
style: AnnotationStyle.Dashed,
|
|
sourceType: AnnotationSourceType.Line,
|
|
value: 1,
|
|
showLabel: true,
|
|
},
|
|
{
|
|
annotationType: AnnotationType.Timeseries,
|
|
name: 'My Hidden Line',
|
|
show: false,
|
|
style: AnnotationStyle.Dashed,
|
|
sourceType: AnnotationSourceType.Line,
|
|
value: 1,
|
|
showLabel: true,
|
|
},
|
|
];
|
|
const results: AnnotationData = {
|
|
'My Interval': {
|
|
columns: ['col'],
|
|
records: [{ col: 1 }],
|
|
},
|
|
'My Line': [
|
|
{ key: 'Line 1', values: [] },
|
|
{ key: 'Line 2', values: [] },
|
|
],
|
|
};
|
|
|
|
expect(extractAnnotationLabels(layers, results)).toEqual([
|
|
'My Formula',
|
|
'Line 1',
|
|
'Line 2',
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe('evalFormula', () => {
|
|
const layer: FormulaAnnotationLayer = {
|
|
annotationType: AnnotationType.Formula,
|
|
name: 'My Formula',
|
|
show: true,
|
|
style: AnnotationStyle.Solid,
|
|
value: 'x+1',
|
|
showLabel: true,
|
|
};
|
|
it('Should evaluate a regular formula', () => {
|
|
const data: TimeseriesDataRecord[] = [
|
|
{ __timestamp: 0 },
|
|
{ __timestamp: 10 },
|
|
];
|
|
|
|
expect(evalFormula(layer, data)).toEqual([
|
|
[0, 1],
|
|
[10, 11],
|
|
]);
|
|
});
|
|
|
|
it('Should evaluate a formula containing redundant characters', () => {
|
|
const data: TimeseriesDataRecord[] = [
|
|
{ __timestamp: 0 },
|
|
{ __timestamp: 10 },
|
|
];
|
|
|
|
expect(evalFormula({ ...layer, value: 'y = x* 2 -1' }, data)).toEqual([
|
|
[0, -1],
|
|
[10, 19],
|
|
]);
|
|
});
|
|
});
|