@@ -16,6 +16,7 @@ var Lib = require('../../lib');
1616var cleanNumber = Lib . cleanNumber ;
1717var ms2DateTime = Lib . ms2DateTime ;
1818var dateTime2ms = Lib . dateTime2ms ;
19+ var ensureNumber = Lib . ensureNumber ;
1920
2021var numConstants = require ( '../../constants/numerical' ) ;
2122var FP_SAFE = numConstants . FP_SAFE ;
@@ -28,13 +29,6 @@ function fromLog(v) {
2829 return Math . pow ( 10 , v ) ;
2930}
3031
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-
3832/**
3933 * Define the conversion functions for an axis data is used in 5 ways:
4034 *
@@ -152,7 +146,7 @@ module.exports = function setConvert(ax, fullLayout) {
152146 if ( index !== undefined ) return index ;
153147 }
154148
155- if ( typeof v === 'number' ) { return v ; }
149+ if ( isNumeric ( v ) ) return + v ;
156150 }
157151
158152 function l2p ( v ) {
@@ -165,8 +159,8 @@ module.exports = function setConvert(ax, fullLayout) {
165159 function p2l ( px ) { return ( px - ax . _b ) / ax . _m ; }
166160
167161 // conversions among c/l/p are fairly simple - do them together for all axis types
168- ax . c2l = ( ax . type === 'log' ) ? toLog : num ;
169- ax . l2c = ( ax . type === 'log' ) ? fromLog : num ;
162+ ax . c2l = ( ax . type === 'log' ) ? toLog : ensureNumber ;
163+ ax . l2c = ( ax . type === 'log' ) ? fromLog : ensureNumber ;
170164
171165 ax . l2p = l2p ;
172166 ax . p2l = p2l ;
@@ -182,18 +176,20 @@ module.exports = function setConvert(ax, fullLayout) {
182176 if ( [ 'linear' , '-' ] . indexOf ( ax . type ) !== - 1 ) {
183177 // all are data vals, but d and r need cleaning
184178 ax . d2r = ax . r2d = ax . d2c = ax . r2c = ax . d2l = ax . r2l = cleanNumber ;
185- ax . c2d = ax . c2r = ax . l2d = ax . l2r = num ;
179+ ax . c2d = ax . c2r = ax . l2d = ax . l2r = ensureNumber ;
186180
187181 ax . d2p = ax . r2p = function ( v ) { return ax . l2p ( cleanNumber ( v ) ) ; } ;
188182 ax . p2d = ax . p2r = p2l ;
183+
184+ ax . cleanPos = ensureNumber ;
189185 }
190186 else if ( ax . type === 'log' ) {
191187 // d and c are data vals, r and l are logged (but d and r need cleaning)
192188 ax . d2r = ax . d2l = function ( v , clip ) { return toLog ( cleanNumber ( v ) , clip ) ; } ;
193189 ax . r2d = ax . r2c = function ( v ) { return fromLog ( cleanNumber ( v ) ) ; } ;
194190
195191 ax . d2c = ax . r2l = cleanNumber ;
196- ax . c2d = ax . l2r = num ;
192+ ax . c2d = ax . l2r = ensureNumber ;
197193
198194 ax . c2r = toLog ;
199195 ax . l2d = fromLog ;
@@ -203,6 +199,8 @@ module.exports = function setConvert(ax, fullLayout) {
203199
204200 ax . r2p = function ( v ) { return ax . l2p ( cleanNumber ( v ) ) ; } ;
205201 ax . p2r = p2l ;
202+
203+ ax . cleanPos = ensureNumber ;
206204 }
207205 else if ( ax . type === 'date' ) {
208206 // r and d are date strings, l and c are ms
@@ -222,24 +220,31 @@ module.exports = function setConvert(ax, fullLayout) {
222220
223221 ax . d2p = ax . r2p = function ( v , _ , calendar ) { return ax . l2p ( dt2ms ( v , 0 , calendar ) ) ; } ;
224222 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 ) ; } ;
225225 }
226226 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
230230
231- ax . d2r = ax . d2c = ax . d2l = setCategoryIndex ;
231+ ax . d2c = ax . d2l = setCategoryIndex ;
232232 ax . r2d = ax . c2d = ax . l2d = getCategoryName ;
233233
234- // special d2l variant that won't add categories
235- ax . d2l_noadd = getCategoryIndex ;
234+ ax . d2r = ax . d2l_noadd = getCategoryIndex ;
236235
237- ax . r2l = ax . l2r = ax . r2c = ax . c2r = num ;
236+ ax . l2r = ax . r2c = ax . c2r = ensureNumber ;
237+ ax . r2l = getCategoryIndex ;
238238
239239 ax . d2p = function ( v ) { return ax . l2p ( getCategoryIndex ( v ) ) ; } ;
240240 ax . p2d = function ( px ) { return getCategoryName ( p2l ( px ) ) ; } ;
241- ax . r2p = ax . l2p ;
241+ ax . r2p = ax . d2p ;
242242 ax . p2r = p2l ;
243+
244+ ax . cleanPos = function ( v ) {
245+ if ( typeof v === 'string' && v !== '' ) return v ;
246+ return ensureNumber ( v ) ;
247+ } ;
243248 }
244249
245250 // find the range value at the specified (linear) fraction of the axis
0 commit comments