diff --git a/src/component/axis/AxisBuilder.ts b/src/component/axis/AxisBuilder.ts index 6fad867a6a..d06c0b5710 100644 --- a/src/component/axis/AxisBuilder.ts +++ b/src/component/axis/AxisBuilder.ts @@ -349,9 +349,9 @@ const builders: Record<'axisLine' | 'axisTickLabel' | 'axisName', AxisElementsBu buildAxisMinorTicks(group, transformGroup, axisModel, opt.tickDirection); - // This bit fixes the label overlap issue for the Time chart. + // This bit fixes the label overlap issue for the time chart. // See https://github.com/apache/echarts/issues/14266 for more. - if (axisModel.get('type') === 'time') { + if (axisModel.get(['axisLabel', 'hideOverlap'])) { const labelList = prepareLayoutList(map(labelEls, label => ({ label, priority: label.z2, diff --git a/src/coord/axisCommonTypes.ts b/src/coord/axisCommonTypes.ts index 0997f6716e..509173c033 100644 --- a/src/coord/axisCommonTypes.ts +++ b/src/coord/axisCommonTypes.ts @@ -64,15 +64,19 @@ export interface AxisBaseOptionCommon extends ComponentOption, minorSplitLine?: MinorSplitLineOption; splitArea?: SplitAreaOption; - // Min value of the axis. can be: - // + ScaleDataValue - // + 'dataMin': use the min value in data. - // + null/undefined: auto decide min value (consider pretty look and boundaryGap). + /** + * Min value of the axis. can be: + * + ScaleDataValue + * + 'dataMin': use the min value in data. + * + null/undefined: auto decide min value (consider pretty look and boundaryGap). + */ min?: ScaleDataValue | 'dataMin' | ((extent: {min: number, max: number}) => ScaleDataValue); - // Max value of the axis. can be: - // + ScaleDataValue - // + 'dataMax': use the max value in data. - // + null/undefined: auto decide max value (consider pretty look and boundaryGap). + /** + * Max value of the axis. can be: + * + ScaleDataValue + * + 'dataMax': use the max value in data. + * + null/undefined: auto decide max value (consider pretty look and boundaryGap). + */ max?: ScaleDataValue | 'dataMax' | ((extent: {min: number, max: number}) => ScaleDataValue); // Optional value can be: // + `false`: always include value 0. @@ -209,7 +213,10 @@ interface AxisLabelBaseOption extends Omit { showMaxLabel?: boolean, margin?: number, rich?: Dictionary - + /** + * If hide overlapping labels. + */ + hideOverlap?: boolean; // Color can be callback color?: ColorString | ((value?: string | number, index?: number) => ColorString) } diff --git a/test/timeScale.html b/test/timeScale.html index cf9bfc2cbb..47370f0e8b 100644 --- a/test/timeScale.html +++ b/test/timeScale.html @@ -153,6 +153,7 @@ min: 'dataMin', max: 'dataMax', axisLabel: { + hideOverlap: true } } ],