@@ -27,10 +27,6 @@ import IntervalScale from './Interval';
2727import SeriesData from '../data/SeriesData' ;
2828import { DimensionName , ScaleTick } from '../util/types' ;
2929
30- const scaleProto = Scale . prototype ;
31- // FIXME:TS refactor: not good to call it directly with `this`?
32- const intervalScaleProto = IntervalScale . prototype ;
33-
3430const roundingErrorFix = numberUtil . round ;
3531
3632const mathFloor = Math . floor ;
@@ -39,14 +35,17 @@ const mathPow = Math.pow;
3935const mathMax = Math . max ;
4036const mathRound = Math . round ;
4137
38+ // LogScale does not have any specific settings
39+ type LogScaleSetting = { } ;
40+
4241/**
4342 * LogScale is a scale that maps values to a logarithmic range.
4443 *
4544 * Support for negative values is implemented by inverting the extents and first handling values as absolute values.
4645 * Then in tick generation, the tick values are multiplied by -1 back to the original values and the normalize function
4746 * uses a reverse extent to get the correct negative values in plot with smaller values at the top of Y axis.
4847 */
49- class LogScale extends Scale {
48+ class LogScale extends IntervalScale < LogScaleSetting > {
5049 static type = 'log' ;
5150 readonly type = 'log' ;
5251
@@ -65,12 +64,6 @@ class LogScale extends Scale {
6564 private _fixMin : boolean ;
6665 private _fixMax : boolean ;
6766
68- // FIXME:TS actually used by `IntervalScale`
69- private _interval : number = 0 ;
70- // FIXME:TS actually used by `IntervalScale`
71- private _niceExtent : [ number , number ] ;
72-
73-
7467 /**
7568 * @param Whether expand the ticks to niced extent.
7669 */
@@ -80,7 +73,7 @@ class LogScale extends Scale {
8073 const originalExtent = originalScale . getExtent ( ) ;
8174 const negativeMultiplier = this . _isNegative ? - 1 : 1 ;
8275
83- const ticks = intervalScaleProto . getTicks . call ( this , expandToNicedExtent ) ;
76+ const ticks = super . getTicks ( expandToNicedExtent ) ;
8477
8578 return zrUtil . map ( ticks , function ( tick ) {
8679 const val = tick . value ;
@@ -110,14 +103,11 @@ class LogScale extends Scale {
110103 end = scaleHelper . absMathLog ( end , this . base ) ;
111104 }
112105
113- intervalScaleProto . setExtent . call ( this , start , end ) ;
106+ super . setExtent ( start , end ) ;
114107 }
115108
116- /**
117- * @return {number } end
118- */
119- getExtent ( ) {
120- const extent = scaleProto . getExtent . call ( this ) ;
109+ getExtent ( ) : [ number , number ] {
110+ const extent = super . getExtent ( ) ;
121111 extent [ 0 ] = mathPow ( this . base , extent [ 0 ] ) ;
122112 extent [ 1 ] = mathPow ( this . base , extent [ 1 ] ) ;
123113
@@ -144,7 +134,8 @@ class LogScale extends Scale {
144134 extent [ 0 ] = logStart ;
145135 extent [ 1 ] = logEnd ;
146136
147- scaleProto . unionExtent . call ( this , extent ) ;
137+ extent [ 0 ] < this . _extent [ 0 ] && ( this . _extent [ 0 ] = extent [ 0 ] ) ;
138+ extent [ 1 ] > this . _extent [ 1 ] && ( this . _extent [ 1 ] = extent [ 1 ] ) ;
148139 }
149140
150141 unionExtentFromData ( data : SeriesData , dim : DimensionName ) : void {
@@ -199,7 +190,7 @@ class LogScale extends Scale {
199190 minInterval ?: number ,
200191 maxInterval ?: number
201192 } ) : void {
202- intervalScaleProto . calcNiceExtent . call ( this , opt ) ;
193+ super . calcNiceExtent ( opt ) ;
203194
204195 this . _fixMin = opt . fixMin ;
205196 this . _fixMax = opt . fixMax ;
@@ -230,9 +221,6 @@ class LogScale extends Scale {
230221 return mathPow ( this . base , val ) ;
231222 }
232223
233- getMinorTicks : IntervalScale [ 'getMinorTicks' ] ;
234- getLabel : IntervalScale [ 'getLabel' ] ;
235-
236224 /**
237225 * Get the extent of the log scale.
238226 * @param start - The start value of the extent.
@@ -254,10 +242,6 @@ class LogScale extends Scale {
254242 }
255243}
256244
257- const proto = LogScale . prototype ;
258- proto . getMinorTicks = intervalScaleProto . getMinorTicks ;
259- proto . getLabel = intervalScaleProto . getLabel ;
260-
261245function fixRoundingError ( val : number , originalVal : number ) : number {
262246 return roundingErrorFix ( val , numberUtil . getPrecision ( originalVal ) ) ;
263247}
0 commit comments