1
-
2
- import { Renderer } from './Renderer' ;
1
+ import { Renderer } from './Renderer' ;
3
2
import { AxisBase } from '../components/AxisBase' ;
4
3
import { Align , Canvas , Paint , Style } from '@nativescript-community/ui-canvas' ;
5
4
import { ViewPortHandler } from '../utils/ViewPortHandler' ;
@@ -12,41 +11,39 @@ import { profile } from '@nativescript/core/profiling';
12
11
* @author Philipp Jahoda
13
12
*/
14
13
export abstract class AxisRenderer extends Renderer {
15
-
16
14
/** base axis this axis renderer works with */
17
15
protected mAxis : AxisBase ;
18
16
19
17
/** transformer to transform values to screen pixels and return */
20
- protected mTrans : Transformer ;
18
+ protected mTrans : Transformer ;
21
19
22
20
/**
23
21
* palet object for the grid lines
24
22
*/
25
- protected mGridPaint : Paint ;
23
+ protected mGridPaint : Paint ;
26
24
27
25
/**
28
26
* palet for the x-label values
29
27
*/
30
- protected mAxisLabelPaint : Paint ;
28
+ protected mAxisLabelPaint : Paint ;
31
29
32
30
/**
33
31
* palet for the line surrounding the chart
34
32
*/
35
- protected mAxisLinePaint : Paint ;
33
+ protected mAxisLinePaint : Paint ;
36
34
37
35
/**
38
36
* palet used for the limit lines
39
37
*/
40
- protected mLimitLinePaint : Paint ;
38
+ protected mLimitLinePaint : Paint ;
41
39
42
- constructor ( viewPortHandler : ViewPortHandler , trans : Transformer , axis : AxisBase ) {
40
+ constructor ( viewPortHandler : ViewPortHandler , trans : Transformer , axis : AxisBase ) {
43
41
super ( viewPortHandler ) ;
44
42
45
43
this . mTrans = trans ;
46
44
this . mAxis = axis ;
47
45
48
- if ( this . mViewPortHandler != null ) {
49
-
46
+ if ( this . mViewPortHandler != null ) {
50
47
this . mAxisLabelPaint = new Paint ( ) ;
51
48
this . mAxisLabelPaint . setAntiAlias ( true ) ;
52
49
this . mAxisLabelPaint . setTextAlign ( Align . LEFT ) ;
@@ -73,7 +70,7 @@ export abstract class AxisRenderer extends Renderer {
73
70
*
74
71
* @return
75
72
*/
76
- public getPaintAxisLabels ( ) {
73
+ public getPaintAxisLabels ( ) {
77
74
return this . mAxisLabelPaint ;
78
75
}
79
76
@@ -83,7 +80,7 @@ export abstract class AxisRenderer extends Renderer {
83
80
*
84
81
* @return
85
82
*/
86
- public getPaintGrid ( ) {
83
+ public getPaintGrid ( ) {
87
84
return this . mGridPaint ;
88
85
}
89
86
@@ -93,7 +90,7 @@ export abstract class AxisRenderer extends Renderer {
93
90
*
94
91
* @return
95
92
*/
96
- public getPaintAxisLine ( ) {
93
+ public getPaintAxisLine ( ) {
97
94
return this . mAxisLinePaint ;
98
95
}
99
96
@@ -102,7 +99,7 @@ export abstract class AxisRenderer extends Renderer {
102
99
*
103
100
* @return
104
101
*/
105
- public getTransformer ( ) {
102
+ public getTransformer ( ) {
106
103
return this . mTrans ;
107
104
}
108
105
@@ -112,8 +109,7 @@ export abstract class AxisRenderer extends Renderer {
112
109
* @param min - the minimum value in the data object for this axis
113
110
* @param max - the maximum value in the data object for this axis
114
111
*/
115
- public computeAxis ( min , max , inverted ) {
116
-
112
+ public computeAxis ( min , max , inverted ) {
117
113
// calculate the starting and entry polet of the y-labels (depending on
118
114
// zoom / contentrect bounds)
119
115
if ( this . mViewPortHandler != null && this . mViewPortHandler . contentWidth ( ) > 10 && ! this . mViewPortHandler . isFullyZoomedOutY ( ) ) {
@@ -122,13 +118,11 @@ export abstract class AxisRenderer extends Renderer {
122
118
const p2 = this . mTrans . getValuesByTouchPoint ( rect . left , rect . bottom ) ;
123
119
124
120
if ( ! inverted ) {
125
-
126
- min = p2 . y ;
127
- max = p1 . y ;
121
+ min = p2 . y ;
122
+ max = p1 . y ;
128
123
} else {
129
-
130
- min = p1 . y ;
131
- max = p2 . y ;
124
+ min = p1 . y ;
125
+ max = p2 . y ;
132
126
}
133
127
134
128
// MPPointD.recycleInstance(p1);
@@ -143,7 +137,7 @@ export abstract class AxisRenderer extends Renderer {
143
137
*
144
138
* @return
145
139
*/
146
- protected computeAxisValues ( min , max ) {
140
+ protected computeAxisValues ( min , max ) {
147
141
const yMin = min ;
148
142
const yMax = max ;
149
143
@@ -163,12 +157,13 @@ export abstract class AxisRenderer extends Renderer {
163
157
164
158
// If granularity is enabled, then do not allow the interval to go below specified granularity.
165
159
// This is used to avoid repeated values when rounding values for display.
166
- if ( this . mAxis . isGranularityEnabled ( ) )
167
- { interval = interval < this . mAxis . getGranularity ( ) ? this . mAxis . getGranularity ( ) : interval ; }
160
+ if ( this . mAxis . isGranularityEnabled ( ) ) {
161
+ interval = interval < this . mAxis . getGranularity ( ) ? this . mAxis . getGranularity ( ) : interval ;
162
+ }
168
163
169
164
// Normalize interval
170
- const intervalMagnitude = Utils . roundToNextSignificant ( Math . pow ( 10 , Math . log10 ( interval ) ) ) ;
171
- const intervalSigDigit = ( interval / intervalMagnitude ) ;
165
+ const intervalMagnitude = Utils . roundToNextSignificant ( Math . pow ( 10 , Math . log10 ( interval ) ) ) ;
166
+ const intervalSigDigit = interval / intervalMagnitude ;
172
167
if ( intervalSigDigit > 5 ) {
173
168
// Use one order of magnitude higher, to avoid intervals like 0.9 or
174
169
// 90
@@ -179,8 +174,7 @@ export abstract class AxisRenderer extends Renderer {
179
174
180
175
// force label count
181
176
if ( this . mAxis . isForceLabelsEnabled ( ) ) {
182
-
183
- interval = range / ( labelCount - 1 ) ;
177
+ interval = range / ( labelCount - 1 ) ;
184
178
this . mAxis . mEntryCount = labelCount ;
185
179
186
180
if ( this . mAxis . mEntries . length < labelCount ) {
@@ -199,9 +193,8 @@ export abstract class AxisRenderer extends Renderer {
199
193
200
194
// no forced count
201
195
} else {
202
-
203
196
let first = interval === 0 ? 0 : Math . ceil ( yMin / interval ) * interval ;
204
- if ( this . mAxis . isCenterAxisLabelsEnabled ( ) ) {
197
+ if ( this . mAxis . isCenterAxisLabelsEnabled ( ) ) {
205
198
first -= interval ;
206
199
}
207
200
@@ -224,23 +217,23 @@ export abstract class AxisRenderer extends Renderer {
224
217
}
225
218
226
219
for ( f = first , i = 0 ; i < n ; f += interval , ++ i ) {
220
+ if ( f === 0.0 ) {
221
+ // Fix for negative zero case (Where value == -0.0, and 0.0 == -0.0)
222
+ f = 0.0 ;
223
+ }
227
224
228
- if ( f === 0.0 ) // Fix for negative zero case (Where value == -0.0, and 0.0 == -0.0)
229
- { f = 0.0 ; }
230
-
231
- this . mAxis . mEntries [ i ] = f ;
225
+ this . mAxis . mEntries [ i ] = f ;
232
226
}
233
227
}
234
228
235
229
// set decimals
236
230
if ( interval < 1 ) {
237
- this . mAxis . mDecimals = Math . ceil ( - Math . log10 ( interval ) ) ;
231
+ this . mAxis . mDecimals = Math . ceil ( - Math . log10 ( interval ) ) ;
238
232
} else {
239
233
this . mAxis . mDecimals = 0 ;
240
234
}
241
235
242
236
if ( this . mAxis . isCenterAxisLabelsEnabled ( ) ) {
243
-
244
237
if ( this . mAxis . mCenteredEntries . length < n ) {
245
238
this . mAxis . mCenteredEntries = [ ] ;
246
239
}
@@ -258,26 +251,26 @@ export abstract class AxisRenderer extends Renderer {
258
251
*
259
252
* @param c
260
253
*/
261
- public abstract renderAxisLabels ( c : Canvas ) ;
254
+ public abstract renderAxisLabels ( c : Canvas ) ;
262
255
263
256
/**
264
257
* Draws the grid lines belonging to the axis.
265
258
*
266
259
* @param c
267
260
*/
268
- public abstract renderGridLines ( c : Canvas ) ;
261
+ public abstract renderGridLines ( c : Canvas ) ;
269
262
270
263
/**
271
264
* Draws the line that goes alongside the axis.
272
265
*
273
266
* @param c
274
267
*/
275
- public abstract renderAxisLine ( c : Canvas ) ;
268
+ public abstract renderAxisLine ( c : Canvas ) ;
276
269
277
270
/**
278
271
* Draws the LimitLines associated with this axis to the screen.
279
272
*
280
273
* @param c
281
274
*/
282
- public abstract renderLimitLines ( c : Canvas ) ;
275
+ public abstract renderLimitLines ( c : Canvas ) ;
283
276
}
0 commit comments