@@ -41,6 +41,7 @@ import {
4141 AxisLabelCategoryFormatter ,
4242 AxisLabelValueFormatter ,
4343 AxisLabelFormatterExtraParams ,
44+ OptionAxisType ,
4445} from './axisCommonTypes' ;
4546import CartesianAxisModel from './cartesian/AxisModel' ;
4647import SeriesData from '../data/SeriesData' ;
@@ -50,7 +51,8 @@ import { ensureScaleRawExtentInfo, ScaleRawExtentResult } from './scaleRawExtent
5051import { parseTimeAxisLabelFormatter } from '../util/time' ;
5152import { getScaleBreakHelper } from '../scale/break' ;
5253import { error } from '../util/log' ;
53- import { isIntervalScale , isTimeScale } from '../scale/helper' ;
54+ import { isTimeScale } from '../scale/helper' ;
55+ import { AxisModelExtendedInCreator } from './axisModelCreator' ;
5456
5557
5658type BarWidthAndOffset = ReturnType < typeof makeColumnLayout > ;
@@ -157,43 +159,22 @@ function adjustScaleForOverflow(
157159 return { min : min , max : max } ;
158160}
159161
160- export function niceScaleExtent (
161- scale : Scale ,
162- inModel : AxisBaseModel ,
163- // Typically: data extent from all series on this axis, which can be obtained by
164- // `scale.unionExtentFromData(...); scale.getExtent();`.
165- dataExtent : number [ ] ,
166- ) : void {
167- const model = inModel as AxisBaseModel < LogAxisBaseOption > ;
168- const extentInfo = adoptScaleExtentOptionAndPrepare ( scale , model , dataExtent ) ;
169-
170- const isInterval = isIntervalScale ( scale ) ;
171- const isIntervalOrTime = isInterval || isTimeScale ( scale ) ;
172-
173- scale . setBreaksFromOption ( retrieveAxisBreaksOption ( model ) ) ;
174- scale . setExtent ( extentInfo . min , extentInfo . max ) ;
175- scale . calcNiceExtent ( {
176- splitNumber : model . get ( 'splitNumber' ) ,
177- fixMinMax : [ extentInfo . minFixed , extentInfo . maxFixed ] ,
178- minInterval : isIntervalOrTime ? model . get ( 'minInterval' ) : null ,
179- maxInterval : isIntervalOrTime ? model . get ( 'maxInterval' ) : null
180- } ) ;
181-
182- // If some one specified the min, max. And the default calculated interval
183- // is not good enough. He can specify the interval. It is often appeared
184- // in angle axis with angle 0 - 360. Interval calculated in interval scale is hard
185- // to be 60.
186- // In `xxxAxis.type: 'log'`, ec option `xxxAxis.interval` requires a logarithm-applied
187- // value rather than a value in the raw scale.
188- const interval = model . get ( 'interval' ) ;
189- if ( interval != null && ( scale as IntervalScale ) . setInterval ) {
190- ( scale as IntervalScale ) . setInterval ( { interval} ) ;
191- }
192- }
193-
194- export function createScaleByModel ( model : AxisBaseModel ) : Scale {
195- const axisType = model . get ( 'type' ) ;
196- switch ( axisType ) {
162+ export function createScaleByModel (
163+ model :
164+ Model <
165+ // Expect `Pick<AxisBaseOptionCommon, 'type'>`,
166+ // but be lenient for user's invalid input.
167+ { type ?: string }
168+ & Pick < LogAxisBaseOption , 'logBase' >
169+ >
170+ & Partial < Pick <
171+ AxisModelExtendedInCreator ,
172+ 'getOrdinalMeta' | 'getCategories'
173+ > > ,
174+ axisType ?: OptionAxisType
175+ ) : Scale {
176+ const type = axisType || model . get ( 'type' ) ;
177+ switch ( type ) {
197178 case 'category' :
198179 return new OrdinalScale ( {
199180 ordinalMeta : model . getOrdinalMeta
@@ -208,10 +189,10 @@ export function createScaleByModel(model: AxisBaseModel): Scale {
208189 } ) ;
209190 case 'log' :
210191 // See also #3749
211- return new LogScale ( ( model as AxisBaseModel < LogAxisBaseOption > ) . get ( 'logBase' ) ) ;
192+ return new LogScale ( model . get ( 'logBase' ) ) ;
212193 default :
213194 // case 'value'/'interval', or others.
214- return new ( Scale . getClass ( axisType ) || IntervalScale ) ( ) ;
195+ return new ( Scale . getClass ( type ) || IntervalScale ) ( ) ;
215196 }
216197}
217198
0 commit comments