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,26 +25,31 @@ import {
AnnotationLayer,
AnnotationOpacity,
AnnotationType,
DataRecord,
evalExpression,
FormulaAnnotationLayer,
isRecordAnnotationResult,
isTableAnnotationLayer,
isTimeseriesAnnotationResult,
TimeseriesDataRecord,
} from '@superset-ui/core';
import { EchartsTimeseriesChartProps } from '../types';
import { AxisType, EchartsTimeseriesChartProps } from '../types';
import { EchartsMixedTimeseriesProps } from '../MixedTimeseries/types';
export function evalFormula(
formula: FormulaAnnotationLayer,
data: TimeseriesDataRecord[],
): [number, number][] {
data: DataRecord[],
xAxis: string,
xAxisType: AxisType,
): [any, number][] {
const { value: expression } = formula;
return data.map(row => [
Number(row.__timestamp),
evalExpression(expression, row.__timestamp as number),
]);
return data.map(row => {
let value = row[xAxis];
if (xAxisType === 'time') {
value = new Date(value as string).getTime();
}
return [value, evalExpression(expression, (value || 0) as number)];
});
}
export function parseAnnotationOpacity(opacity?: AnnotationOpacity): number {

View File

@@ -33,7 +33,7 @@ import {
NULL_STRING,
TIMESERIES_CONSTANTS,
} from '../constants';
import { LegendOrientation, LegendType, StackType } from '../types';
import { AxisType, LegendOrientation, LegendType, StackType } from '../types';
import { defaultLegendPadding } from '../defaults';
function isDefined<T>(value: T | undefined | null): boolean {
@@ -307,9 +307,7 @@ export const currentSeries = {
legend: '',
};
export function getAxisType(
dataType?: GenericDataType,
): 'time' | 'value' | 'category' {
export function getAxisType(dataType?: GenericDataType): AxisType {
if (dataType === GenericDataType.TEMPORAL) {
return 'time';
}