Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: drilling on the categorical xaxis on the stacked barchart v2 #21844

Merged
merged 2 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,11 @@ export const chartLabelWeight: Record<ChartLabel, { weight: number }> = {
},
};

export enum AxisType {
category = 'category',
value = 'value',
time = 'time',
log = 'log',
}

export default {};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
* under the License.
*/
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { QueryObjectFilterClause } from '@superset-ui/core';
import {
DTTM_ALIAS,
QueryObjectFilterClause,
AxisType,
} from '@superset-ui/core';
import { ViewRootGroup } from 'echarts/types/src/util/types';
import GlobalModel from 'echarts/types/src/model/Global';
import ComponentModel from 'echarts/types/src/model/Component';
Expand All @@ -43,6 +47,7 @@ export default function EchartsTimeseries({
legendData = [],
onContextMenu,
xValueFormatter,
xAxis,
}: TimeseriesChartTransformedProps) {
const { emitFilter, stack } = formData;
const echartRef = useRef<EchartsHandler | null>(null);
Expand Down Expand Up @@ -182,16 +187,28 @@ export default function EchartsTimeseries({
const { data } = eventParams;
if (data) {
const pointerEvent = eventParams.event.event;
const values = labelMap[eventParams.seriesName];
const values = [
...(eventParams.name ? [eventParams.name] : []),
...labelMap[eventParams.seriesName],
];
const filters: QueryObjectFilterClause[] = [];
filters.push({
col: formData.granularitySqla,
grain: formData.timeGrainSqla,
op: '==',
val: data[0],
formattedVal: xValueFormatter(data[0]),
});
formData.groupby.forEach((dimension, i) =>
if (xAxis.type === AxisType.time) {
filters.push({
col:
// if the xAxis is '__timestamp', granularity_sqla will be the column of filter
xAxis.label === DTTM_ALIAS
? formData.granularitySqla
: xAxis.label,
grain: formData.timeGrainSqla,
op: '==',
val: data[0],
formattedVal: xValueFormatter(data[0]),
});
}
[
...(xAxis.type === AxisType.category ? [xAxis.label] : []),
...formData.groupby,
].forEach((dimension, i) =>
filters.push({
col: dimension,
op: '==',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
TimeseriesChartDataResponseResult,
t,
getXAxis,
AxisType,
} from '@superset-ui/core';
import { isDerivedSeries } from '@superset-ui/chart-controls';
import { EChartsCoreOption, SeriesOption } from 'echarts';
Expand All @@ -39,7 +40,6 @@ import {
EchartsTimeseriesSeriesType,
TimeseriesChartTransformedProps,
OrientationType,
AxisType,
} from './types';
import { DEFAULT_FORM_DATA } from './constants';
import { ForecastSeriesEnum, ForecastValue } from '../types';
Expand Down Expand Up @@ -451,5 +451,9 @@ export default function transformProps(
legendData,
onContextMenu,
xValueFormatter: tooltipFormatter,
xAxis: {
label: xAxisCol,
type: xAxisType,
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
TimeFormatter,
TimeseriesAnnotationLayer,
TimeseriesDataRecord,
AxisType,
} from '@superset-ui/core';
import { SeriesOption } from 'echarts';
import {
Expand All @@ -52,12 +53,7 @@ import {
import { MarkLine1DDataItemOption } from 'echarts/types/src/component/marker/MarkLineModel';

import { extractForecastSeriesContext } from '../utils/forecast';
import {
AxisType,
ForecastSeriesEnum,
LegendOrientation,
StackType,
} from '../types';
import { ForecastSeriesEnum, LegendOrientation, StackType } from '../types';
import { EchartsTimeseriesSeriesType } from './types';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
TimeGranularity,
ContributionType,
TimeFormatter,
AxisType,
} from '@superset-ui/core';
import {
EchartsLegendFormData,
Expand Down Expand Up @@ -96,11 +97,8 @@ export interface EchartsTimeseriesChartProps
export type TimeseriesChartTransformedProps =
EChartTransformedProps<EchartsTimeseriesFormData> & {
xValueFormatter: TimeFormatter | StringConstructor;
xAxis: {
label: string;
type: AxisType;
};
};

export enum AxisType {
category = 'category',
value = 'value',
time = 'time',
log = 'log',
}
2 changes: 0 additions & 2 deletions superset-frontend/plugins/plugin-chart-echarts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,4 @@ export interface EchartsTitleFormData {

export type StackType = boolean | null | Partial<AreaChartExtraControlsValue>;

export type AxisType = 'time' | 'value' | 'category';

export * from './Timeseries/types';
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import {
isRecordAnnotationResult,
isTableAnnotationLayer,
isTimeseriesAnnotationResult,
AxisType,
} from '@superset-ui/core';
import { AxisType, EchartsTimeseriesChartProps } from '../types';
import { EchartsTimeseriesChartProps } from '../types';
import { EchartsMixedTimeseriesProps } from '../MixedTimeseries/types';

export function evalFormula(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ import {
NumberFormats,
NumberFormatter,
TimeFormatter,
AxisType,
} from '@superset-ui/core';
import { format, LegendComponentOption, SeriesOption } from 'echarts';
import {
AreaChartExtraControlsValue,
NULL_STRING,
TIMESERIES_CONSTANTS,
} from '../constants';
import { AxisType, LegendOrientation, LegendType, StackType } from '../types';
import { LegendOrientation, LegendType, StackType } from '../types';
import { defaultLegendPadding } from '../defaults';

function isDefined<T>(value: T | undefined | null): boolean {
Expand Down Expand Up @@ -323,9 +324,9 @@ export const currentSeries = {

export function getAxisType(dataType?: GenericDataType): AxisType {
if (dataType === GenericDataType.TEMPORAL) {
return 'time';
return AxisType.time;
}
return 'category';
return AxisType.category;
}

export function getOverMaxHiddenFormatter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
* under the License.
*/
import {
AnnotationLayer,
AnnotationData,
AnnotationLayer,
AnnotationOpacity,
AnnotationSourceType,
AnnotationStyle,
AnnotationType,
AxisType,
DataRecord,
FormulaAnnotationLayer,
TimeseriesDataRecord,
DataRecord,
} from '@superset-ui/core';
import {
evalFormula,
Expand Down Expand Up @@ -161,7 +162,7 @@ describe('evalFormula', () => {
{ __timestamp: 10 },
];

expect(evalFormula(layer, data, '__timestamp', 'time')).toEqual([
expect(evalFormula(layer, data, '__timestamp', AxisType.time)).toEqual([
[0, 1],
[10, 11],
]);
Expand All @@ -178,7 +179,7 @@ describe('evalFormula', () => {
{ ...layer, value: 'y = x* 2 -1' },
data,
'__timestamp',
'time',
AxisType.time,
),
).toEqual([
[0, -1],
Expand All @@ -190,7 +191,12 @@ describe('evalFormula', () => {
const data: DataRecord[] = [{ gender: 'boy' }, { gender: 'girl' }];

expect(
evalFormula({ ...layer, value: 'y = 1000' }, data, 'gender', 'category'),
evalFormula(
{ ...layer, value: 'y = 1000' },
data,
'gender',
AxisType.category,
),
).toEqual([
['boy', 1000],
['girl', 1000],
Expand Down