Skip to content

Commit

Permalink
fix: drilling on the categorical xaxis on the mixed chart (#21845)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyongjie committed Oct 19, 2022
1 parent f41d0b0 commit f381154
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
* under the License.
*/
import React, { useCallback } from 'react';
import { DataRecordValue, QueryObjectFilterClause } from '@superset-ui/core';
import {
AxisType,
DataRecordValue,
DTTM_ALIAS,
QueryObjectFilterClause,
} from '@superset-ui/core';
import { EchartsMixedTimeseriesChartTransformedProps } from './types';
import Echart from '../components/Echart';
import { EventHandlers } from '../types';
Expand All @@ -37,6 +42,7 @@ export default function EchartsMixedTimeseries({
seriesBreakdown,
onContextMenu,
xValueFormatter,
xAxis,
}: EchartsMixedTimeseriesChartTransformedProps) {
const isFirstQuery = useCallback(
(seriesIndex: number) => seriesIndex < seriesBreakdown,
Expand Down Expand Up @@ -116,18 +122,31 @@ export default function EchartsMixedTimeseries({
const { data, seriesIndex } = eventParams;
if (data) {
const pointerEvent = eventParams.event.event;
const values = labelMap[eventParams.seriesName];
const { queryIndex } = (echartOptions.series as any)[seriesIndex];
const groupby = queryIndex > 0 ? formData.groupbyB : formData.groupby;
const values = [
...(eventParams.name ? [eventParams.name] : []),
...(isFirstQuery(seriesIndex) ? labelMap : labelMapB)[
eventParams.seriesName
],
];
const filters: QueryObjectFilterClause[] = [];
filters.push({
col: formData.granularitySqla,
grain: formData.timeGrainSqla,
op: '==',
val: data[0],
formattedVal: xValueFormatter(data[0]),
});
groupby.forEach((dimension, i) =>
if (xAxis.type === AxisType.time) {
filters.push({
col:
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] : []),
...(isFirstQuery(seriesIndex)
? formData.groupby
: formData.groupbyB),
].forEach((dimension, i) =>
filters.push({
col: dimension,
op: '==',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,5 +499,9 @@ export default function transformProps(
selectedValues: filterState.selectedValues || [],
onContextMenu,
xValueFormatter: tooltipFormatter,
xAxis: {
label: xAxisCol,
type: xAxisType,
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
QueryFormColumn,
ContributionType,
TimeFormatter,
AxisType,
} from '@superset-ui/core';
import {
EchartsLegendFormData,
Expand Down Expand Up @@ -144,4 +145,8 @@ export type EchartsMixedTimeseriesChartTransformedProps =
labelMapB: Record<string, string[]>;
seriesBreakdown: number;
xValueFormatter: TimeFormatter | StringConstructor;
xAxis: {
label: string;
type: AxisType;
};
};

0 comments on commit f381154

Please sign in to comment.