@@ -44,7 +44,8 @@ import {
4444 DimensionName ,
4545} from '../../util/types' ;
4646import {
47- AxisBaseOption , AxisBaseOptionCommon , AxisLabelBaseOptionNuance
47+ AxisBaseOption , AxisBaseOptionCommon , AxisLabelBaseOptionNuance ,
48+ AxisShowMinMaxLabelOption ,
4849} from '../../coord/axisCommonTypes' ;
4950import type Element from 'zrender/src/Element' ;
5051import { PathProps , PathStyleProps } from 'zrender/src/graphic/Path' ;
@@ -70,9 +71,11 @@ import BoundingRect from 'zrender/src/core/BoundingRect';
7071import Point from 'zrender/src/core/Point' ;
7172import { copyTransform } from 'zrender/src/core/Transformable' ;
7273import {
74+ AxisLabelInfoDetermined ,
7375 AxisLabelsComputingContext , AxisTickLabelComputingKind , createAxisLabelsComputingContext
7476} from '../../coord/axisTickLabelBuilder' ;
7577import { AxisTickCoord } from '../../coord/Axis' ;
78+ import { isTimeScale } from '../../scale/helper' ;
7679
7780
7881const PI = Math . PI ;
@@ -112,14 +115,13 @@ type AxisLabelText = graphic.Text & {
112115} & ECElement ;
113116
114117export const getLabelInner = makeInner < {
115- break : VisualAxisBreak ;
116- tickValue : number ;
118+ labelInfo : AxisLabelInfoDetermined ; // Never be null/undefined.
117119 layoutRotation : number ;
118120} , graphic . Text > ( ) ;
119121
120122const getTickInner = makeInner < {
121- onBand : AxisTickCoord [ 'onBand' ]
122- tickValue : AxisTickCoord [ 'tickValue' ]
123+ onBand : AxisTickCoord [ 'onBand' ] ;
124+ tickValue : AxisTickCoord [ 'tickValue' ] ;
123125} , graphic . Line > ( ) ;
124126
125127
@@ -1061,7 +1063,10 @@ function fixMinMaxLabelShow(
10611063 labelLayoutList : LabelLayoutData [ ] ,
10621064 optionHideOverlap : AxisBaseOption [ 'axisLabel' ] [ 'hideOverlap' ]
10631065) {
1064- if ( shouldShowAllLabels ( axisModel . axis ) ) {
1066+ const axis = axisModel . axis ;
1067+ const customValuesOption = axisModel . get ( [ 'axisLabel' , 'customValues' ] ) ;
1068+
1069+ if ( shouldShowAllLabels ( axis ) ) {
10651070 return ;
10661071 }
10671072
@@ -1070,7 +1075,7 @@ function fixMinMaxLabelShow(
10701075 // Assert no ignore in labels.
10711076
10721077 function deal (
1073- showMinMaxLabel : boolean ,
1078+ showMinMaxLabelOption : AxisShowMinMaxLabelOption ,
10741079 outmostLabelIdx : number ,
10751080 innerLabelIdx : number ,
10761081 ) {
@@ -1079,8 +1084,18 @@ function fixMinMaxLabelShow(
10791084 if ( ! outmostLabelLayout || ! innerLabelLayout ) {
10801085 return ;
10811086 }
1087+ if ( showMinMaxLabelOption == null ) {
1088+ if ( ! optionHideOverlap && customValuesOption ) {
1089+ // In this case, users are unlikely to expect labels to be hidden.
1090+ return ;
1091+ }
1092+ if ( isTimeScale ( axis . scale ) && getLabelInner ( outmostLabelLayout . label ) . labelInfo . tick . notNice ) {
1093+ // TimeScale does not expand extent to "nice", so eliminate labels that are not nice.
1094+ ignoreEl ( outmostLabelLayout . label ) ;
1095+ }
1096+ }
10821097
1083- if ( showMinMaxLabel === false || outmostLabelLayout . suggestIgnore ) {
1098+ if ( showMinMaxLabelOption === false || outmostLabelLayout . suggestIgnore ) {
10841099 ignoreEl ( outmostLabelLayout . label ) ;
10851100 return ;
10861101 }
@@ -1107,7 +1122,7 @@ function fixMinMaxLabelShow(
11071122 innerLabelLayout = newLabelLayoutWithGeometry ( { marginForce} , innerLabelLayout ) ;
11081123 }
11091124 if ( labelIntersect ( outmostLabelLayout , innerLabelLayout , null , { touchThreshold} ) ) {
1110- if ( showMinMaxLabel ) {
1125+ if ( showMinMaxLabelOption ) {
11111126 ignoreEl ( innerLabelLayout . label ) ;
11121127 }
11131128 else {
@@ -1119,11 +1134,11 @@ function fixMinMaxLabelShow(
11191134 // If min or max are user set, we need to check
11201135 // If the tick on min(max) are overlap on their neighbour tick
11211136 // If they are overlapped, we need to hide the min(max) tick label
1122- const showMinLabel = axisModel . get ( [ 'axisLabel' , 'showMinLabel' ] ) ;
1123- const showMaxLabel = axisModel . get ( [ 'axisLabel' , 'showMaxLabel' ] ) ;
1137+ const showMinLabelOption = axisModel . get ( [ 'axisLabel' , 'showMinLabel' ] ) ;
1138+ const showMaxLabelOption = axisModel . get ( [ 'axisLabel' , 'showMaxLabel' ] ) ;
11241139 const labelsLen = labelLayoutList . length ;
1125- deal ( showMinLabel , 0 , 1 ) ;
1126- deal ( showMaxLabel , labelsLen - 1 , labelsLen - 2 ) ;
1140+ deal ( showMinLabelOption , 0 , 1 ) ;
1141+ deal ( showMaxLabelOption , labelsLen - 1 , labelsLen - 2 ) ;
11271142}
11281143
11291144// PENDING: Is it necessary to display a tick while the corresponding label is ignored?
@@ -1146,7 +1161,7 @@ function syncLabelIgnoreToMajorTicks(
11461161 const labelInner = getLabelInner ( labelLayout . label ) ;
11471162 if ( tickInner . tickValue != null
11481163 && ! tickInner . onBand
1149- && tickInner . tickValue === labelInner . tickValue
1164+ && tickInner . tickValue === labelInner . labelInfo . tick . value
11501165 ) {
11511166 ignoreEl ( tickEl ) ;
11521167 return ;
@@ -1355,9 +1370,11 @@ function buildAxisLabel(
13551370 let z2Max = - Infinity ;
13561371
13571372 each ( labels , function ( labelItem , index ) {
1373+ const labelItemTick = labelItem . tick ;
1374+ const labelItemTickValue = labelItemTick . value ;
13581375 const tickValue = axis . scale . type === 'ordinal'
1359- ? ( axis . scale as OrdinalScale ) . getRawOrdinalNumber ( labelItem . tickValue )
1360- : labelItem . tickValue ;
1376+ ? ( axis . scale as OrdinalScale ) . getRawOrdinalNumber ( labelItemTickValue )
1377+ : labelItemTickValue ;
13611378 const formattedLabel = labelItem . formattedLabel ;
13621379 const rawLabel = labelItem . rawLabel ;
13631380
@@ -1396,7 +1413,7 @@ function buildAxisLabel(
13961413 itemLabelModel . getShallow ( 'verticalAlignMaxLabel' , true ) ,
13971414 verticalAlign
13981415 ) ;
1399- const z2 = 10 + ( labelItem . time ?. level || 0 ) ;
1416+ const z2 = 10 + ( labelItemTick . time ?. level || 0 ) ;
14001417 z2Min = Math . min ( z2Min , z2 ) ;
14011418 z2Max = Math . max ( z2Max , z2 ) ;
14021419
@@ -1443,8 +1460,7 @@ function buildAxisLabel(
14431460 textEl . anid = 'label_' + tickValue ;
14441461
14451462 const inner = getLabelInner ( textEl ) ;
1446- inner . break = labelItem . break ;
1447- inner . tickValue = tickValue ;
1463+ inner . labelInfo = labelItem ;
14481464 inner . layoutRotation = labelLayout . rotation ;
14491465
14501466 graphic . setTooltipConfig ( {
@@ -1464,11 +1480,13 @@ function buildAxisLabel(
14641480 eventData . targetType = 'axisLabel' ;
14651481 eventData . value = rawLabel ;
14661482 eventData . tickIndex = index ;
1467- if ( labelItem . break ) {
1483+ const labelItemTickBreak = labelItem . tick . break ;
1484+ const labelItemTickBreakParsedBreak = labelItemTickBreak . parsedBreak ;
1485+ if ( labelItemTickBreak ) {
14681486 eventData . break = {
14691487 // type: labelItem.break.type,
1470- start : labelItem . break . parsedBreak . vmin ,
1471- end : labelItem . break . parsedBreak . vmax ,
1488+ start : labelItemTickBreakParsedBreak . vmin ,
1489+ end : labelItemTickBreakParsedBreak . vmax ,
14721490 } ;
14731491 }
14741492 if ( axis . type === 'category' ) {
@@ -1477,8 +1495,8 @@ function buildAxisLabel(
14771495
14781496 getECData ( textEl ) . eventData = eventData ;
14791497
1480- if ( labelItem . break ) {
1481- addBreakEventHandler ( axisModel , api , textEl , labelItem . break ) ;
1498+ if ( labelItemTickBreak ) {
1499+ addBreakEventHandler ( axisModel , api , textEl , labelItemTickBreak ) ;
14821500 }
14831501 }
14841502
@@ -1488,7 +1506,7 @@ function buildAxisLabel(
14881506
14891507 const labelLayoutList = map ( labelEls , label => ( {
14901508 label,
1491- priority : getLabelInner ( label ) . break
1509+ priority : getLabelInner ( label ) . labelInfo . tick . break
14921510 ? label . z2 + ( z2Max - z2Min + 1 ) // Make break labels be highest priority.
14931511 : label . z2 ,
14941512 defaultAttr : {
@@ -1537,7 +1555,7 @@ function updateAxisLabelChangableProps(
15371555 labelEl . ignore = false ;
15381556
15391557 copyTransform ( _tmpLayoutEl , _tmpLayoutElReset ) ;
1540- _tmpLayoutEl . x = axisModel . axis . dataToCoord ( inner . tickValue ) ;
1558+ _tmpLayoutEl . x = axisModel . axis . dataToCoord ( inner . labelInfo . tick . value ) ;
15411559 _tmpLayoutEl . y = cfg . labelOffset + cfg . labelDirection * labelMargin ;
15421560 _tmpLayoutEl . rotation = inner . layoutRotation ;
15431561
@@ -1590,7 +1608,7 @@ function adjustBreakLabels(
15901608 }
15911609 const breakLabelIndexPairs = scaleBreakHelper . retrieveAxisBreakPairs (
15921610 labelLayoutList ,
1593- layoutInfo => layoutInfo && getLabelInner ( layoutInfo . label ) . break ,
1611+ layoutInfo => layoutInfo && getLabelInner ( layoutInfo . label ) . labelInfo . tick . break ,
15941612 true
15951613 ) ;
15961614 const moveOverlap = axisModel . get ( [ 'breakLabelLayout' , 'moveOverlap' ] , true ) ;
0 commit comments