mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
fix(plugin-chart-echarts): support forced categorical x-axis (#26404)
This commit is contained in:
committed by
Michael S. Molina
parent
333b18db5a
commit
52109e5f24
@@ -187,6 +187,7 @@ export default function transformProps(
|
||||
groupby,
|
||||
groupbyB,
|
||||
xAxis: xAxisOrig,
|
||||
xAxisForceCategorical,
|
||||
xAxisTitle,
|
||||
yAxisTitle,
|
||||
xAxisTitleMargin,
|
||||
@@ -225,7 +226,7 @@ export default function transformProps(
|
||||
|
||||
const dataTypes = getColtypesMapping(queriesData[0]);
|
||||
const xAxisDataType = dataTypes?.[xAxisLabel] ?? dataTypes?.[xAxisOrig];
|
||||
const xAxisType = getAxisType(stack, xAxisDataType);
|
||||
const xAxisType = getAxisType(stack, xAxisForceCategorical, xAxisDataType);
|
||||
const series: SeriesOption[] = [];
|
||||
const formatter = contributionMode
|
||||
? getNumberFormatter(',.0%')
|
||||
|
||||
@@ -106,6 +106,7 @@ export const DEFAULT_FORM_DATA: EchartsMixedTimeseriesFormData = {
|
||||
yAxisTitleSecondary: DEFAULT_TITLE_FORM_DATA.yAxisTitle,
|
||||
tooltipTimeFormat: TIMESERIES_DEFAULTS.tooltipTimeFormat,
|
||||
xAxisBounds: TIMESERIES_DEFAULTS.xAxisBounds,
|
||||
xAxisForceCategorical: TIMESERIES_DEFAULTS.xAxisForceCategorical,
|
||||
xAxisTimeFormat: TIMESERIES_DEFAULTS.xAxisTimeFormat,
|
||||
area: TIMESERIES_DEFAULTS.area,
|
||||
areaB: TIMESERIES_DEFAULTS.area,
|
||||
|
||||
@@ -63,6 +63,7 @@ export const DEFAULT_FORM_DATA: EchartsTimeseriesFormData = {
|
||||
zoomable: false,
|
||||
richTooltip: true,
|
||||
xAxisLabelRotation: 0,
|
||||
xAxisForceCategorical: false,
|
||||
groupby: [],
|
||||
showValue: false,
|
||||
onlyTotal: false,
|
||||
|
||||
@@ -165,6 +165,7 @@ export default function transformProps(
|
||||
truncateYAxis,
|
||||
xAxis: xAxisOrig,
|
||||
xAxisBounds,
|
||||
xAxisForceCategorical,
|
||||
xAxisLabelRotation,
|
||||
xAxisSortSeries,
|
||||
xAxisSortSeriesAscending,
|
||||
@@ -246,7 +247,7 @@ export default function transformProps(
|
||||
const isAreaExpand = stack === StackControlsValue.Expand;
|
||||
const xAxisDataType = dataTypes?.[xAxisLabel] ?? dataTypes?.[xAxisOrig];
|
||||
|
||||
const xAxisType = getAxisType(stack, xAxisDataType);
|
||||
const xAxisType = getAxisType(stack, xAxisForceCategorical, xAxisDataType);
|
||||
const series: SeriesOption[] = [];
|
||||
|
||||
const forcePercentFormatter = Boolean(contributionMode || isAreaExpand);
|
||||
|
||||
@@ -79,6 +79,7 @@ export type EchartsTimeseriesFormData = QueryFormData & {
|
||||
truncateXAxis: boolean;
|
||||
truncateYAxis: boolean;
|
||||
yAxisFormat?: string;
|
||||
xAxisForceCategorical?: boolean;
|
||||
xAxisTimeFormat?: string;
|
||||
timeGrainSqla?: TimeGranularity;
|
||||
xAxisBounds: [number | undefined | null, number | undefined | null];
|
||||
|
||||
@@ -290,3 +290,14 @@ export const minorTicks: ControlSetItem = {
|
||||
description: t('Show minor ticks on axes.'),
|
||||
},
|
||||
};
|
||||
|
||||
export const forceCategorical: ControlSetItem = {
|
||||
name: 'forceCategorical',
|
||||
config: {
|
||||
type: 'CheckboxControl',
|
||||
label: t('Force categorical'),
|
||||
default: false,
|
||||
renderTrigger: true,
|
||||
description: t('Make the x-axis categorical'),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -229,8 +229,10 @@ export function sortRows(
|
||||
}
|
||||
|
||||
const value =
|
||||
xAxisSortSeries === SortSeriesType.Name && typeof sortKey === 'string'
|
||||
? sortKey.toLowerCase()
|
||||
xAxisSortSeries === SortSeriesType.Name
|
||||
? typeof sortKey === 'string'
|
||||
? sortKey.toLowerCase()
|
||||
: sortKey
|
||||
: aggregate;
|
||||
|
||||
return {
|
||||
@@ -515,8 +517,12 @@ export function sanitizeHtml(text: string): string {
|
||||
|
||||
export function getAxisType(
|
||||
stack: StackType,
|
||||
forceCategorical?: boolean,
|
||||
dataType?: GenericDataType,
|
||||
): AxisType {
|
||||
if (forceCategorical) {
|
||||
return AxisType.category;
|
||||
}
|
||||
if (dataType === GenericDataType.TEMPORAL) {
|
||||
return AxisType.time;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user