Skip to content

Commit

Permalink
add annotation data to mixed timeseries chart
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyongjie committed Jul 11, 2022
1 parent 82f5d43 commit df054bd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ import {
getColtypesMapping,
getLegendProps,
} from '../utils/series';
import { extractAnnotationLabels } from '../utils/annotation';
import {
extractAnnotationLabels,
getAnnotationData,
} from '../utils/annotation';
import {
extractForecastSeriesContext,
extractForecastValuesFromTooltipParams,
Expand Down Expand Up @@ -81,11 +84,11 @@ export default function transformProps(
filterState,
datasource,
theme,
annotationData = {},
} = chartProps;
const { verboseMap = {} } = datasource;
const data1 = (queriesData[0].data || []) as TimeseriesDataRecord[];
const data2 = (queriesData[1].data || []) as TimeseriesDataRecord[];
const annotationData = getAnnotationData(chartProps);

const {
area,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/
/* eslint-disable camelcase */
import { isEmpty } from 'lodash';
import {
AnnotationLayer,
CategoricalColorNamespace,
Expand All @@ -32,7 +31,6 @@ import {
isTimeseriesAnnotationLayer,
TimeseriesChartDataResponseResult,
t,
AnnotationData,
} from '@superset-ui/core';
import { isDerivedSeries } from '@superset-ui/chart-controls';
import { EChartsCoreOption, SeriesOption } from 'echarts';
Expand All @@ -57,7 +55,10 @@ import {
extractDataTotalValues,
extractShowValueIndexes,
} from '../utils/series';
import { extractAnnotationLabels } from '../utils/annotation';
import {
extractAnnotationLabels,
getAnnotationData,
} from '../utils/annotation';
import {
extractForecastSeriesContext,
extractForecastSeriesContexts,
Expand All @@ -83,16 +84,6 @@ import {
TIMEGRAIN_TO_TIMESTAMP,
} from '../constants';

function getAnnotationData(
chartProps: EchartsTimeseriesChartProps,
): AnnotationData {
const data = chartProps?.queriesData[0]?.annotation_data as AnnotationData;
if (!isEmpty(data)) {
return data;
}
return {};
}

export default function transformProps(
chartProps: EchartsTimeseriesChartProps,
): TimeseriesChartTransformedProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* specific language governing permissions and limitations
* under the License.
*/
import { isEmpty } from 'lodash';

import {
Annotation,
AnnotationData,
Expand All @@ -30,6 +32,8 @@ import {
isTimeseriesAnnotationResult,
TimeseriesDataRecord,
} from '@superset-ui/core';
import { EchartsTimeseriesChartProps } from '../types';
import { EchartsMixedTimeseriesProps } from '../MixedTimeseries/types';

export function evalFormula(
formula: FormulaAnnotationLayer,
Expand Down Expand Up @@ -130,3 +134,13 @@ export function extractAnnotationLabels(

return formulaAnnotationLabels.concat(timeseriesAnnotationLabels);
}

export function getAnnotationData(
chartProps: EchartsTimeseriesChartProps | EchartsMixedTimeseriesProps,
): AnnotationData {
const data = chartProps?.queriesData[0]?.annotation_data as AnnotationData;
if (!isEmpty(data)) {
return data;
}
return {};
}

0 comments on commit df054bd

Please sign in to comment.