@@ -16,6 +16,7 @@ var Lib = require('../../lib');
16
16
var cleanNumber = Lib . cleanNumber ;
17
17
var ms2DateTime = Lib . ms2DateTime ;
18
18
var dateTime2ms = Lib . dateTime2ms ;
19
+ var num = Lib . num ;
19
20
20
21
var numConstants = require ( '../../constants/numerical' ) ;
21
22
var FP_SAFE = numConstants . FP_SAFE ;
@@ -28,13 +29,6 @@ function fromLog(v) {
28
29
return Math . pow ( 10 , v ) ;
29
30
}
30
31
31
- function num ( v ) {
32
- if ( ! isNumeric ( v ) ) return BADNUM ;
33
- v = Number ( v ) ;
34
- if ( v < - FP_SAFE || v > FP_SAFE ) return BADNUM ;
35
- return isNumeric ( v ) ? Number ( v ) : BADNUM ;
36
- }
37
-
38
32
/**
39
33
* Define the conversion functions for an axis data is used in 5 ways:
40
34
*
@@ -152,7 +146,7 @@ module.exports = function setConvert(ax, fullLayout) {
152
146
if ( index !== undefined ) return index ;
153
147
}
154
148
155
- if ( typeof v === 'number' ) { return v ; }
149
+ if ( isNumeric ( v ) ) return + v ;
156
150
}
157
151
158
152
function l2p ( v ) {
@@ -186,6 +180,8 @@ module.exports = function setConvert(ax, fullLayout) {
186
180
187
181
ax . d2p = ax . r2p = function ( v ) { return ax . l2p ( cleanNumber ( v ) ) ; } ;
188
182
ax . p2d = ax . p2r = p2l ;
183
+
184
+ ax . cleanPos = num ;
189
185
}
190
186
else if ( ax . type === 'log' ) {
191
187
// d and c are data vals, r and l are logged (but d and r need cleaning)
@@ -203,6 +199,8 @@ module.exports = function setConvert(ax, fullLayout) {
203
199
204
200
ax . r2p = function ( v ) { return ax . l2p ( cleanNumber ( v ) ) ; } ;
205
201
ax . p2r = p2l ;
202
+
203
+ ax . cleanPos = num ;
206
204
}
207
205
else if ( ax . type === 'date' ) {
208
206
// r and d are date strings, l and c are ms
@@ -222,24 +220,31 @@ module.exports = function setConvert(ax, fullLayout) {
222
220
223
221
ax . d2p = ax . r2p = function ( v , _ , calendar ) { return ax . l2p ( dt2ms ( v , 0 , calendar ) ) ; } ;
224
222
ax . p2d = ax . p2r = function ( px , r , calendar ) { return ms2dt ( p2l ( px ) , r , calendar ) ; } ;
223
+
224
+ ax . cleanPos = function ( v ) { return Lib . cleanDate ( v , BADNUM , ax . calendar ) ; } ;
225
225
}
226
226
else if ( ax . type === 'category' ) {
227
- // d is categories; r, c, and l are indices
228
- // TODO: should r accept category names too?
229
- // ie r2c and r2l would be getCategoryIndex (and r2p would change)
227
+ // d is categories (string)
228
+ // c and l are indices (numbers)
229
+ // r is categories or numbers
230
230
231
- ax . d2r = ax . d2c = ax . d2l = setCategoryIndex ;
231
+ ax . d2c = ax . d2l = setCategoryIndex ;
232
232
ax . r2d = ax . c2d = ax . l2d = getCategoryName ;
233
233
234
- // special d2l variant that won't add categories
235
- ax . d2l_noadd = getCategoryIndex ;
234
+ ax . d2r = ax . d2l_noadd = getCategoryIndex ;
236
235
237
- ax . r2l = ax . l2r = ax . r2c = ax . c2r = num ;
236
+ ax . l2r = ax . r2c = ax . c2r = num ;
237
+ ax . r2l = getCategoryIndex ;
238
238
239
239
ax . d2p = function ( v ) { return ax . l2p ( getCategoryIndex ( v ) ) ; } ;
240
240
ax . p2d = function ( px ) { return getCategoryName ( p2l ( px ) ) ; } ;
241
- ax . r2p = ax . l2p ;
241
+ ax . r2p = ax . d2p ;
242
242
ax . p2r = p2l ;
243
+
244
+ ax . cleanPos = function ( v ) {
245
+ if ( typeof v === 'string' && v !== '' ) return v ;
246
+ return num ( v ) ;
247
+ } ;
243
248
}
244
249
245
250
// find the range value at the specified (linear) fraction of the axis
0 commit comments