@@ -53,7 +53,7 @@ interface AxisCategoryLabelCreated {
5353 labelCategoryInterval : number
5454}
5555interface AxisCategoryTickCreated {
56- ticks : number [ ]
56+ ticks : ScaleTick [ ]
5757 tickCategoryInterval ?: number
5858}
5959
@@ -105,15 +105,17 @@ export function createAxisLabelsComputingContext(kind: AxisTickLabelComputingKin
105105 } ;
106106}
107107
108+ /**
109+ * CAUTION: Do not modify the result.
110+ */
108111export function createAxisLabels ( axis : Axis , ctx : AxisLabelsComputingContext ) : {
109112 labels : AxisLabelInfoDetermined [ ]
110113} {
111114 const custom = axis . getLabelModel ( ) . get ( 'customValues' ) ;
112115 if ( custom ) {
113116 const scale = axis . scale ;
114117 return {
115- labels : zrUtil . map ( parseTickLabelCustomValues ( custom , scale ) , ( numval , index ) => {
116- const tick = { value : numval } ;
118+ labels : zrUtil . map ( parseTickLabelCustomValues ( custom , scale ) , ( tick , index ) => {
117119 return {
118120 formattedLabel : makeLabelFormatter ( axis ) ( tick , index ) ,
119121 rawLabel : scale . getLabel ( tick ) ,
@@ -129,16 +131,15 @@ export function createAxisLabels(axis: Axis, ctx: AxisLabelsComputingContext): {
129131}
130132
131133/**
134+ * CAUTION: Do not modify the result.
135+ *
132136 * @param tickModel For example, can be axisTick, splitLine, splitArea.
133137 */
134138export function createAxisTicks (
135139 axis : Axis ,
136140 tickModel : AxisBaseModel ,
137141 opt ?: Pick < ScaleGetTicksOpt , 'breakTicks' | 'pruneByBreak' >
138- ) : {
139- ticks : number [ ] ,
140- tickCategoryInterval ?: number
141- } {
142+ ) : AxisCategoryTickCreated {
142143 const scale = axis . scale ;
143144 const custom = axis . getTickModel ( ) . get ( 'customValues' ) ;
144145 if ( custom ) {
@@ -149,13 +150,13 @@ export function createAxisTicks(
149150 // Only ordinal scale support tick interval
150151 return axis . type === 'category'
151152 ? makeCategoryTicks ( axis , tickModel )
152- : { ticks : zrUtil . map ( scale . getTicks ( opt ) , tick => tick . value ) } ;
153+ : { ticks : scale . getTicks ( opt ) } ;
153154}
154155
155156function parseTickLabelCustomValues (
156157 customValues : AxisTickLabelCustomValuesOption ,
157158 scale : Scale ,
158- ) : number [ ] {
159+ ) : ScaleTick [ ] {
159160 const extent = scale . getExtent ( ) ;
160161 const tickNumbers : number [ ] = [ ] ;
161162 zrUtil . each ( customValues , function ( val ) {
@@ -166,7 +167,9 @@ function parseTickLabelCustomValues(
166167 } ) ;
167168 removeDuplicates ( tickNumbers , removeDuplicatesGetKeyFromItemItself , null ) ;
168169 asc ( tickNumbers ) ;
169- return tickNumbers ;
170+ return zrUtil . map ( tickNumbers , function ( tickVal ) {
171+ return { value : tickVal } ;
172+ } ) ;
170173}
171174
172175function makeCategoryLabels ( axis : Axis , ctx : AxisLabelsComputingContext ) : ReturnType < typeof createAxisLabels > {
@@ -182,10 +185,7 @@ function makeCategoryLabelsActually(
182185 axis : Axis ,
183186 labelModel : Model < AxisBaseOption [ 'axisLabel' ] > ,
184187 ctx : AxisLabelsComputingContext
185- ) : {
186- labels : AxisLabelInfoDetermined [ ]
187- labelCategoryInterval : number
188- } {
188+ ) : AxisCategoryLabelCreated {
189189 const labelsCache = ensureCategoryLabelCache ( axis ) ;
190190 const optionLabelInterval = getOptionCategoryInterval ( labelModel ) ;
191191 const isEstimate = ctx . kind === AxisTickLabelComputingKind . estimate ;
@@ -226,7 +226,7 @@ function makeCategoryLabelsActually(
226226 return result ;
227227}
228228
229- function makeCategoryTicks ( axis : Axis , tickModel : AxisBaseModel ) {
229+ function makeCategoryTicks ( axis : Axis , tickModel : AxisBaseModel ) : AxisCategoryTickCreated {
230230 const ticksCache = ensureCategoryTickCache ( axis ) ;
231231 const optionTickInterval = getOptionCategoryInterval ( tickModel ) ;
232232 const result = axisCacheGet ( ticksCache , optionTickInterval ) ;
@@ -235,7 +235,7 @@ function makeCategoryTicks(axis: Axis, tickModel: AxisBaseModel) {
235235 return result ;
236236 }
237237
238- let ticks : number [ ] ;
238+ let ticks : ScaleTick [ ] ;
239239 let tickCategoryInterval ;
240240
241241 // Optimize for the case that large category data and no label displayed,
@@ -256,7 +256,7 @@ function makeCategoryTicks(axis: Axis, tickModel: AxisBaseModel) {
256256 ) ;
257257 tickCategoryInterval = labelsResult . labelCategoryInterval ;
258258 ticks = zrUtil . map ( labelsResult . labels , function ( labelItem ) {
259- return labelItem . tick . value ;
259+ return labelItem . tick ;
260260 } ) ;
261261 }
262262 else {
@@ -338,7 +338,7 @@ function makeAutoCategoryInterval(axis: Axis, ctx: AxisLabelsComputingContext):
338338 * To get precise result, at least one of `getRotate` and `isHorizontal`
339339 * should be implemented in axis.
340340 */
341- export function calculateCategoryInterval ( axis : Axis , ctx : AxisLabelsComputingContext ) {
341+ export function calculateCategoryInterval ( axis : Axis , ctx : AxisLabelsComputingContext ) : number {
342342 const kind = ctx . kind ;
343343
344344 const params = fetchAutoCategoryIntervalCalculationParams ( axis ) ;
@@ -474,14 +474,14 @@ function makeLabelsByNumericCategoryInterval(
474474) : AxisLabelInfoDetermined [ ] ;
475475function makeLabelsByNumericCategoryInterval (
476476 axis : Axis , categoryInterval : number , onlyTick : true
477- ) : number [ ] ;
477+ ) : ScaleTick [ ] ;
478478function makeLabelsByNumericCategoryInterval (
479479 axis : Axis , categoryInterval : number , onlyTick ?: boolean
480480) {
481481 const labelFormatter = makeLabelFormatter ( axis ) ;
482482 const ordinalScale = axis . scale as OrdinalScale ;
483483 const ordinalExtent = ordinalScale . getExtent ( ) ;
484- const result : ( AxisLabelInfoDetermined | number ) [ ] = [ ] ;
484+ const result : ( AxisLabelInfoDetermined | ScaleTick ) [ ] = [ ] ;
485485
486486 // TODO: axisType: ordinalTime, pick the tick from each month/day/year/...
487487
@@ -500,23 +500,23 @@ function makeLabelsByNumericCategoryInterval(
500500 // But they should be always included and the display strategy is adopted uniformly
501501 // later in `AxisBuilder`.
502502 if ( startTick !== ordinalExtent [ 0 ] ) {
503- addItem ( ordinalExtent [ 0 ] ) ;
503+ addItem ( ordinalExtent [ 0 ] , true ) ;
504504 }
505505
506506 // Optimize: avoid generating large array by `ordinalScale.getTicks()`.
507507 let tickValue = startTick ;
508508 for ( ; tickValue <= ordinalExtent [ 1 ] ; tickValue += step ) {
509- addItem ( tickValue ) ;
509+ addItem ( tickValue , false ) ;
510510 }
511511
512512 if ( tickValue - step !== ordinalExtent [ 1 ] ) {
513- addItem ( ordinalExtent [ 1 ] ) ;
513+ addItem ( ordinalExtent [ 1 ] , true ) ;
514514 }
515515
516- function addItem ( tickValue : number ) {
517- const tickObj = { value : tickValue } ;
516+ function addItem ( tickValue : number , offInterval : boolean ) {
517+ const tickObj : ScaleTick = { value : tickValue , offInterval } ;
518518 result . push ( onlyTick
519- ? tickValue
519+ ? tickObj
520520 : {
521521 formattedLabel : labelFormatter ( tickObj ) ,
522522 rawLabel : ordinalScale . getLabel ( tickObj ) ,
@@ -540,21 +540,24 @@ function makeLabelsByCustomizedCategoryInterval(
540540) : AxisLabelInfoDetermined [ ] ;
541541function makeLabelsByCustomizedCategoryInterval (
542542 axis : Axis , categoryInterval : CategoryIntervalCb , onlyTick : true
543- ) : number [ ] ;
543+ ) : ScaleTick [ ] ;
544544function makeLabelsByCustomizedCategoryInterval (
545545 axis : Axis , categoryInterval : CategoryIntervalCb , onlyTick ?: boolean
546546) {
547547 const ordinalScale = axis . scale ;
548548 const labelFormatter = makeLabelFormatter ( axis ) ;
549- const result : ( AxisLabelInfoDetermined | number ) [ ] = [ ] ;
549+ const result : ( AxisLabelInfoDetermined | ScaleTick ) [ ] = [ ] ;
550550
551- zrUtil . each ( ordinalScale . getTicks ( ) , function ( tick ) {
551+ const ticks = ordinalScale . getTicks ( ) ;
552+ zrUtil . each ( ticks , function ( tick , idx ) {
552553 const rawLabel = ordinalScale . getLabel ( tick ) ;
553- const tickValue = tick . value ;
554- if ( categoryInterval ( tickValue , rawLabel ) ) {
555- result . push (
556- onlyTick
557- ? tickValue
554+ const isOnInterval = categoryInterval ( tick . value , rawLabel ) ;
555+ tick . offInterval = ! isOnInterval ;
556+ // axis extent min max labels should be always included and the display strategy
557+ // is adopted uniformly later in `AxisBuilder`.
558+ if ( isOnInterval || idx === 0 || idx === ticks . length - 1 ) {
559+ result . push ( onlyTick
560+ ? tick
558561 : {
559562 formattedLabel : labelFormatter ( tick ) ,
560563 rawLabel : rawLabel ,
0 commit comments