@@ -27,10 +27,6 @@ import IntervalScale from './Interval';
27
27
import SeriesData from '../data/SeriesData' ;
28
28
import { DimensionName , ScaleTick } from '../util/types' ;
29
29
30
- const scaleProto = Scale . prototype ;
31
- // FIXME:TS refactor: not good to call it directly with `this`?
32
- const intervalScaleProto = IntervalScale . prototype ;
33
-
34
30
const roundingErrorFix = numberUtil . round ;
35
31
36
32
const mathFloor = Math . floor ;
@@ -39,14 +35,17 @@ const mathPow = Math.pow;
39
35
const mathMax = Math . max ;
40
36
const mathRound = Math . round ;
41
37
38
+ // LogScale does not have any specific settings
39
+ type LogScaleSetting = { } ;
40
+
42
41
/**
43
42
* LogScale is a scale that maps values to a logarithmic range.
44
43
*
45
44
* Support for negative values is implemented by inverting the extents and first handling values as absolute values.
46
45
* Then in tick generation, the tick values are multiplied by -1 back to the original values and the normalize function
47
46
* uses a reverse extent to get the correct negative values in plot with smaller values at the top of Y axis.
48
47
*/
49
- class LogScale extends Scale {
48
+ class LogScale extends IntervalScale < LogScaleSetting > {
50
49
static type = 'log' ;
51
50
readonly type = 'log' ;
52
51
@@ -65,12 +64,6 @@ class LogScale extends Scale {
65
64
private _fixMin : boolean ;
66
65
private _fixMax : boolean ;
67
66
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
-
74
67
/**
75
68
* @param Whether expand the ticks to niced extent.
76
69
*/
@@ -80,7 +73,7 @@ class LogScale extends Scale {
80
73
const originalExtent = originalScale . getExtent ( ) ;
81
74
const negativeMultiplier = this . _isNegative ? - 1 : 1 ;
82
75
83
- const ticks = intervalScaleProto . getTicks . call ( this , expandToNicedExtent ) ;
76
+ const ticks = super . getTicks ( expandToNicedExtent ) ;
84
77
85
78
return zrUtil . map ( ticks , function ( tick ) {
86
79
const val = tick . value ;
@@ -110,14 +103,11 @@ class LogScale extends Scale {
110
103
end = scaleHelper . absMathLog ( end , this . base ) ;
111
104
}
112
105
113
- intervalScaleProto . setExtent . call ( this , start , end ) ;
106
+ super . setExtent ( start , end ) ;
114
107
}
115
108
116
- /**
117
- * @return {number } end
118
- */
119
- getExtent ( ) {
120
- const extent = scaleProto . getExtent . call ( this ) ;
109
+ getExtent ( ) : [ number , number ] {
110
+ const extent = super . getExtent ( ) ;
121
111
extent [ 0 ] = mathPow ( this . base , extent [ 0 ] ) ;
122
112
extent [ 1 ] = mathPow ( this . base , extent [ 1 ] ) ;
123
113
@@ -144,7 +134,8 @@ class LogScale extends Scale {
144
134
extent [ 0 ] = logStart ;
145
135
extent [ 1 ] = logEnd ;
146
136
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 ] ) ;
148
139
}
149
140
150
141
unionExtentFromData ( data : SeriesData , dim : DimensionName ) : void {
@@ -199,7 +190,7 @@ class LogScale extends Scale {
199
190
minInterval ?: number ,
200
191
maxInterval ?: number
201
192
} ) : void {
202
- intervalScaleProto . calcNiceExtent . call ( this , opt ) ;
193
+ super . calcNiceExtent ( opt ) ;
203
194
204
195
this . _fixMin = opt . fixMin ;
205
196
this . _fixMax = opt . fixMax ;
@@ -230,9 +221,6 @@ class LogScale extends Scale {
230
221
return mathPow ( this . base , val ) ;
231
222
}
232
223
233
- getMinorTicks : IntervalScale [ 'getMinorTicks' ] ;
234
- getLabel : IntervalScale [ 'getLabel' ] ;
235
-
236
224
/**
237
225
* Get the extent of the log scale.
238
226
* @param start - The start value of the extent.
@@ -254,10 +242,6 @@ class LogScale extends Scale {
254
242
}
255
243
}
256
244
257
- const proto = LogScale . prototype ;
258
- proto . getMinorTicks = intervalScaleProto . getMinorTicks ;
259
- proto . getLabel = intervalScaleProto . getLabel ;
260
-
261
245
function fixRoundingError ( val : number , originalVal : number ) : number {
262
246
return roundingErrorFix ( val , numberUtil . getPrecision ( originalVal ) ) ;
263
247
}
0 commit comments