mirror of
https://github.com/apache/superset.git
synced 2024-09-06 13:57:40 -04:00
fix: drilling on the categorical xaxis on the stacked barchart v2 (#21844)
This commit is contained in:
parent
383dc29ad1
commit
f41d0b0cbf
@ -73,4 +73,11 @@ export const chartLabelWeight: Record<ChartLabel, { weight: number }> = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export enum AxisType {
|
||||||
|
category = 'category',
|
||||||
|
value = 'value',
|
||||||
|
time = 'time',
|
||||||
|
log = 'log',
|
||||||
|
}
|
||||||
|
|
||||||
export default {};
|
export default {};
|
||||||
|
@ -17,7 +17,11 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
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 { ViewRootGroup } from 'echarts/types/src/util/types';
|
||||||
import GlobalModel from 'echarts/types/src/model/Global';
|
import GlobalModel from 'echarts/types/src/model/Global';
|
||||||
import ComponentModel from 'echarts/types/src/model/Component';
|
import ComponentModel from 'echarts/types/src/model/Component';
|
||||||
@ -43,6 +47,7 @@ export default function EchartsTimeseries({
|
|||||||
legendData = [],
|
legendData = [],
|
||||||
onContextMenu,
|
onContextMenu,
|
||||||
xValueFormatter,
|
xValueFormatter,
|
||||||
|
xAxis,
|
||||||
}: TimeseriesChartTransformedProps) {
|
}: TimeseriesChartTransformedProps) {
|
||||||
const { emitFilter, stack } = formData;
|
const { emitFilter, stack } = formData;
|
||||||
const echartRef = useRef<EchartsHandler | null>(null);
|
const echartRef = useRef<EchartsHandler | null>(null);
|
||||||
@ -182,16 +187,28 @@ export default function EchartsTimeseries({
|
|||||||
const { data } = eventParams;
|
const { data } = eventParams;
|
||||||
if (data) {
|
if (data) {
|
||||||
const pointerEvent = eventParams.event.event;
|
const pointerEvent = eventParams.event.event;
|
||||||
const values = labelMap[eventParams.seriesName];
|
const values = [
|
||||||
|
...(eventParams.name ? [eventParams.name] : []),
|
||||||
|
...labelMap[eventParams.seriesName],
|
||||||
|
];
|
||||||
const filters: QueryObjectFilterClause[] = [];
|
const filters: QueryObjectFilterClause[] = [];
|
||||||
|
if (xAxis.type === AxisType.time) {
|
||||||
filters.push({
|
filters.push({
|
||||||
col: formData.granularitySqla,
|
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,
|
grain: formData.timeGrainSqla,
|
||||||
op: '==',
|
op: '==',
|
||||||
val: data[0],
|
val: data[0],
|
||||||
formattedVal: xValueFormatter(data[0]),
|
formattedVal: xValueFormatter(data[0]),
|
||||||
});
|
});
|
||||||
formData.groupby.forEach((dimension, i) =>
|
}
|
||||||
|
[
|
||||||
|
...(xAxis.type === AxisType.category ? [xAxis.label] : []),
|
||||||
|
...formData.groupby,
|
||||||
|
].forEach((dimension, i) =>
|
||||||
filters.push({
|
filters.push({
|
||||||
col: dimension,
|
col: dimension,
|
||||||
op: '==',
|
op: '==',
|
||||||
|
@ -29,6 +29,7 @@ import {
|
|||||||
TimeseriesChartDataResponseResult,
|
TimeseriesChartDataResponseResult,
|
||||||
t,
|
t,
|
||||||
getXAxis,
|
getXAxis,
|
||||||
|
AxisType,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { isDerivedSeries } from '@superset-ui/chart-controls';
|
import { isDerivedSeries } from '@superset-ui/chart-controls';
|
||||||
import { EChartsCoreOption, SeriesOption } from 'echarts';
|
import { EChartsCoreOption, SeriesOption } from 'echarts';
|
||||||
@ -39,7 +40,6 @@ import {
|
|||||||
EchartsTimeseriesSeriesType,
|
EchartsTimeseriesSeriesType,
|
||||||
TimeseriesChartTransformedProps,
|
TimeseriesChartTransformedProps,
|
||||||
OrientationType,
|
OrientationType,
|
||||||
AxisType,
|
|
||||||
} from './types';
|
} from './types';
|
||||||
import { DEFAULT_FORM_DATA } from './constants';
|
import { DEFAULT_FORM_DATA } from './constants';
|
||||||
import { ForecastSeriesEnum, ForecastValue } from '../types';
|
import { ForecastSeriesEnum, ForecastValue } from '../types';
|
||||||
@ -451,5 +451,9 @@ export default function transformProps(
|
|||||||
legendData,
|
legendData,
|
||||||
onContextMenu,
|
onContextMenu,
|
||||||
xValueFormatter: tooltipFormatter,
|
xValueFormatter: tooltipFormatter,
|
||||||
|
xAxis: {
|
||||||
|
label: xAxisCol,
|
||||||
|
type: xAxisType,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import {
|
|||||||
TimeFormatter,
|
TimeFormatter,
|
||||||
TimeseriesAnnotationLayer,
|
TimeseriesAnnotationLayer,
|
||||||
TimeseriesDataRecord,
|
TimeseriesDataRecord,
|
||||||
|
AxisType,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { SeriesOption } from 'echarts';
|
import { SeriesOption } from 'echarts';
|
||||||
import {
|
import {
|
||||||
@ -52,12 +53,7 @@ import {
|
|||||||
import { MarkLine1DDataItemOption } from 'echarts/types/src/component/marker/MarkLineModel';
|
import { MarkLine1DDataItemOption } from 'echarts/types/src/component/marker/MarkLineModel';
|
||||||
|
|
||||||
import { extractForecastSeriesContext } from '../utils/forecast';
|
import { extractForecastSeriesContext } from '../utils/forecast';
|
||||||
import {
|
import { ForecastSeriesEnum, LegendOrientation, StackType } from '../types';
|
||||||
AxisType,
|
|
||||||
ForecastSeriesEnum,
|
|
||||||
LegendOrientation,
|
|
||||||
StackType,
|
|
||||||
} from '../types';
|
|
||||||
import { EchartsTimeseriesSeriesType } from './types';
|
import { EchartsTimeseriesSeriesType } from './types';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -25,6 +25,7 @@ import {
|
|||||||
TimeGranularity,
|
TimeGranularity,
|
||||||
ContributionType,
|
ContributionType,
|
||||||
TimeFormatter,
|
TimeFormatter,
|
||||||
|
AxisType,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import {
|
import {
|
||||||
EchartsLegendFormData,
|
EchartsLegendFormData,
|
||||||
@ -96,11 +97,8 @@ export interface EchartsTimeseriesChartProps
|
|||||||
export type TimeseriesChartTransformedProps =
|
export type TimeseriesChartTransformedProps =
|
||||||
EChartTransformedProps<EchartsTimeseriesFormData> & {
|
EChartTransformedProps<EchartsTimeseriesFormData> & {
|
||||||
xValueFormatter: TimeFormatter | StringConstructor;
|
xValueFormatter: TimeFormatter | StringConstructor;
|
||||||
|
xAxis: {
|
||||||
|
label: string;
|
||||||
|
type: AxisType;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum AxisType {
|
|
||||||
category = 'category',
|
|
||||||
value = 'value',
|
|
||||||
time = 'time',
|
|
||||||
log = 'log',
|
|
||||||
}
|
|
||||||
|
@ -132,6 +132,4 @@ export interface EchartsTitleFormData {
|
|||||||
|
|
||||||
export type StackType = boolean | null | Partial<AreaChartExtraControlsValue>;
|
export type StackType = boolean | null | Partial<AreaChartExtraControlsValue>;
|
||||||
|
|
||||||
export type AxisType = 'time' | 'value' | 'category';
|
|
||||||
|
|
||||||
export * from './Timeseries/types';
|
export * from './Timeseries/types';
|
||||||
|
@ -31,8 +31,9 @@ import {
|
|||||||
isRecordAnnotationResult,
|
isRecordAnnotationResult,
|
||||||
isTableAnnotationLayer,
|
isTableAnnotationLayer,
|
||||||
isTimeseriesAnnotationResult,
|
isTimeseriesAnnotationResult,
|
||||||
|
AxisType,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { AxisType, EchartsTimeseriesChartProps } from '../types';
|
import { EchartsTimeseriesChartProps } from '../types';
|
||||||
import { EchartsMixedTimeseriesProps } from '../MixedTimeseries/types';
|
import { EchartsMixedTimeseriesProps } from '../MixedTimeseries/types';
|
||||||
|
|
||||||
export function evalFormula(
|
export function evalFormula(
|
||||||
|
@ -27,6 +27,7 @@ import {
|
|||||||
NumberFormats,
|
NumberFormats,
|
||||||
NumberFormatter,
|
NumberFormatter,
|
||||||
TimeFormatter,
|
TimeFormatter,
|
||||||
|
AxisType,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { format, LegendComponentOption, SeriesOption } from 'echarts';
|
import { format, LegendComponentOption, SeriesOption } from 'echarts';
|
||||||
import {
|
import {
|
||||||
@ -34,7 +35,7 @@ import {
|
|||||||
NULL_STRING,
|
NULL_STRING,
|
||||||
TIMESERIES_CONSTANTS,
|
TIMESERIES_CONSTANTS,
|
||||||
} from '../constants';
|
} from '../constants';
|
||||||
import { AxisType, LegendOrientation, LegendType, StackType } from '../types';
|
import { LegendOrientation, LegendType, StackType } from '../types';
|
||||||
import { defaultLegendPadding } from '../defaults';
|
import { defaultLegendPadding } from '../defaults';
|
||||||
|
|
||||||
function isDefined<T>(value: T | undefined | null): boolean {
|
function isDefined<T>(value: T | undefined | null): boolean {
|
||||||
@ -323,9 +324,9 @@ export const currentSeries = {
|
|||||||
|
|
||||||
export function getAxisType(dataType?: GenericDataType): AxisType {
|
export function getAxisType(dataType?: GenericDataType): AxisType {
|
||||||
if (dataType === GenericDataType.TEMPORAL) {
|
if (dataType === GenericDataType.TEMPORAL) {
|
||||||
return 'time';
|
return AxisType.time;
|
||||||
}
|
}
|
||||||
return 'category';
|
return AxisType.category;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getOverMaxHiddenFormatter(
|
export function getOverMaxHiddenFormatter(
|
||||||
|
@ -17,15 +17,16 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
AnnotationLayer,
|
|
||||||
AnnotationData,
|
AnnotationData,
|
||||||
|
AnnotationLayer,
|
||||||
AnnotationOpacity,
|
AnnotationOpacity,
|
||||||
AnnotationSourceType,
|
AnnotationSourceType,
|
||||||
AnnotationStyle,
|
AnnotationStyle,
|
||||||
AnnotationType,
|
AnnotationType,
|
||||||
|
AxisType,
|
||||||
|
DataRecord,
|
||||||
FormulaAnnotationLayer,
|
FormulaAnnotationLayer,
|
||||||
TimeseriesDataRecord,
|
TimeseriesDataRecord,
|
||||||
DataRecord,
|
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import {
|
import {
|
||||||
evalFormula,
|
evalFormula,
|
||||||
@ -161,7 +162,7 @@ describe('evalFormula', () => {
|
|||||||
{ __timestamp: 10 },
|
{ __timestamp: 10 },
|
||||||
];
|
];
|
||||||
|
|
||||||
expect(evalFormula(layer, data, '__timestamp', 'time')).toEqual([
|
expect(evalFormula(layer, data, '__timestamp', AxisType.time)).toEqual([
|
||||||
[0, 1],
|
[0, 1],
|
||||||
[10, 11],
|
[10, 11],
|
||||||
]);
|
]);
|
||||||
@ -178,7 +179,7 @@ describe('evalFormula', () => {
|
|||||||
{ ...layer, value: 'y = x* 2 -1' },
|
{ ...layer, value: 'y = x* 2 -1' },
|
||||||
data,
|
data,
|
||||||
'__timestamp',
|
'__timestamp',
|
||||||
'time',
|
AxisType.time,
|
||||||
),
|
),
|
||||||
).toEqual([
|
).toEqual([
|
||||||
[0, -1],
|
[0, -1],
|
||||||
@ -190,7 +191,12 @@ describe('evalFormula', () => {
|
|||||||
const data: DataRecord[] = [{ gender: 'boy' }, { gender: 'girl' }];
|
const data: DataRecord[] = [{ gender: 'boy' }, { gender: 'girl' }];
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
evalFormula({ ...layer, value: 'y = 1000' }, data, 'gender', 'category'),
|
evalFormula(
|
||||||
|
{ ...layer, value: 'y = 1000' },
|
||||||
|
data,
|
||||||
|
'gender',
|
||||||
|
AxisType.category,
|
||||||
|
),
|
||||||
).toEqual([
|
).toEqual([
|
||||||
['boy', 1000],
|
['boy', 1000],
|
||||||
['girl', 1000],
|
['girl', 1000],
|
||||||
|
Loading…
Reference in New Issue
Block a user