@@ -28,8 +28,8 @@ import { DimensionIndex, DimensionName, NullUndefined, ScaleDataValue } from '..
2828import { isIntervalScale , isLogScale , isOrdinalScale , isTimeScale } from '../scale/helper' ;
2929import type Axis from './Axis' ;
3030import type SeriesModel from '../model/Series' ;
31- import { makeInner , initExtentForUnion } from '../util/model' ;
32- import { getDataDimensionsOnAxis , unionExtent } from './axisHelper' ;
31+ import { makeInner , initExtentForUnion , unionExtent } from '../util/model' ;
32+ import { getDataDimensionsOnAxis } from './axisHelper' ;
3333import {
3434 getCoordForCoordSysUsageKindBox
3535} from '../core/CoordinateSystem' ;
@@ -83,7 +83,7 @@ export interface ScaleRawExtentResult {
8383export class ScaleRawExtentInfo {
8484
8585 private _needCrossZero : ValueAxisBaseOption [ 'scale' ] ;
86- private _isOrdinal : boolean ;
86+ private _scale : Scale ;
8787 private _axisDataLen : number ;
8888 private _boundaryGapInner : number [ ] ;
8989
@@ -118,26 +118,14 @@ export class ScaleRawExtentInfo {
118118 // Typically: data extent from all series on this axis.
119119 dataExtent : number [ ]
120120 ) {
121- this . _prepareParams ( scale , model , dataExtent ) ;
122- }
121+ this . _scale = scale ;
123122
124- /**
125- * Parameters depending on outside (like model, user callback)
126- * are prepared and fixed here.
127- */
128- private _prepareParams (
129- scale : Scale ,
130- model : AxisBaseModel ,
131- // Usually: data extent from all series on this axis.
132- dataExtent : number [ ]
133- ) {
134123 if ( dataExtent [ 1 ] < dataExtent [ 0 ] ) {
135124 dataExtent = [ NaN , NaN ] ;
136125 }
137126 this . _dataMin = dataExtent [ 0 ] ;
138127 this . _dataMax = dataExtent [ 1 ] ;
139128
140- const isOrdinal = this . _isOrdinal = isOrdinalScale ( scale ) ;
141129 this . _needCrossZero = isIntervalScale ( scale ) && model . getNeedCrossZero && model . getNeedCrossZero ( ) ;
142130
143131 if ( isIntervalScale ( scale ) || isLogScale ( scale ) || isTimeScale ( scale ) ) {
@@ -181,7 +169,7 @@ export class ScaleRawExtentInfo {
181169 this . _modelMaxNum = parseAxisModelMinMax ( scale , modelMaxRaw ) ;
182170 }
183171
184- if ( isOrdinal ) {
172+ if ( isOrdinalScale ( scale ) ) {
185173 // FIXME: there is a flaw here: if there is no "block" data processor like `dataZoom`,
186174 // and progressive rendering is using, here the category result might just only contain
187175 // the processed chunk rather than the entire result.
@@ -227,7 +215,8 @@ export class ScaleRawExtentInfo {
227215 // be the result that originalExtent enlarged by boundaryGap.
228216 // (3) If no data, it should be ensured that `scale.setBlank` is set.
229217
230- const isOrdinal = this . _isOrdinal ;
218+ const scale = this . _scale ;
219+ const isOrdinal = isOrdinalScale ( scale ) ;
231220 let dataMin = this . _dataMin ;
232221 let dataMax = this . _dataMax ;
233222
@@ -313,6 +302,11 @@ export class ScaleRawExtentInfo {
313302 maxFixed = maxDetermined = true ;
314303 }
315304
305+ if ( isLogScale ( scale ) ) {
306+ min = clampForLogScale ( min ) ;
307+ max = clampForLogScale ( max ) ;
308+ }
309+
316310 // Ensure min/max be finite number or NaN here. (not to be null/undefined)
317311 // `NaN` means min/max axis is blank.
318312 return {
@@ -338,6 +332,9 @@ export class ScaleRawExtentInfo {
338332 if ( __DEV__ ) {
339333 assert ( this [ attr ] == null ) ;
340334 }
335+ if ( isLogScale ( this . _scale ) ) {
336+ val = clampForLogScale ( val ) ;
337+ }
341338 this [ attr ] = val ;
342339 }
343340}
@@ -457,8 +454,9 @@ export function axisExtentInfoFinalBuild(
457454 // NOTE: This data may have been filtered by dataZoom on orthogonal axes.
458455 const data = seriesModel . getData ( ) ;
459456 if ( data ) {
457+ const filter = isLogScale ( scale ) ? { g : 0 } : null ;
460458 each ( getDataDimensionsOnAxis ( data , axis . dim ) , function ( dim ) {
461- const seriesExtent = data . getApproximateExtent ( dim ) ;
459+ const seriesExtent = data . getApproximateExtent ( dim , filter ) ;
462460 unionExtent ( extent , seriesExtent [ 0 ] ) ;
463461 unionExtent ( extent , seriesExtent [ 1 ] ) ;
464462 } ) ;
@@ -503,3 +501,9 @@ function injectScaleRawExtentInfo(
503501 // @ts -ignore
504502 scaleRawExtentInfo . from = from ;
505503}
504+
505+ export function clampForLogScale ( val : number ) {
506+ // Avoid `NaN` for log scale.
507+ // See also `DataStore#getDataExtent`.
508+ return val < 0 ? 0 : val ;
509+ }
0 commit comments