@@ -17,6 +17,7 @@ var isNumeric = require('fast-isnumeric');
1717
1818var Lib = require ( '../../lib' ) ;
1919var Axes = require ( '../../plots/cartesian/axes' ) ;
20+ var autoType = require ( '../../plots/cartesian/axis_autotype' ) ;
2021var ErrorBars = require ( '../../components/errorbars' ) ;
2122var str2RGBArray = require ( '../../lib/str2rgbarray' ) ;
2223var truncate = require ( '../../lib/float32_truncate' ) ;
@@ -114,11 +115,13 @@ proto.handlePick = function(pickResult) {
114115 index = this . idToIndex [ pickResult . pointId ] ;
115116 }
116117
118+ var x = this . pickXData [ index ] ;
119+
117120 return {
118121 trace : this ,
119122 dataCoord : pickResult . dataCoord ,
120123 traceCoord : [
121- this . pickXData [ index ] ,
124+ isNumeric ( x ) || ! Lib . isDateTime ( x ) ? x : Lib . dateTime2ms ( x ) ,
122125 this . pickYData [ index ]
123126 ] ,
124127 textLabel : Array . isArray ( this . textLabels ) ?
@@ -135,7 +138,7 @@ proto.handlePick = function(pickResult) {
135138
136139// check if trace is fancy
137140proto . isFancy = function ( options ) {
138- if ( this . scene . xaxis . type !== 'linear' ) return true ;
141+ if ( this . scene . xaxis . type !== 'linear' && this . scene . xaxis . type !== 'date' ) return true ;
139142 if ( this . scene . yaxis . type !== 'linear' ) return true ;
140143
141144 if ( ! options . x || ! options . y ) return true ;
@@ -259,6 +262,29 @@ proto.update = function(options) {
259262 this . color = getTraceColor ( options , { } ) ;
260263} ;
261264
265+ // We'd ideally know that all values are of fast types; sampling gives no certainty but faster
266+ // (for the future, typed arrays can guarantee it, and Date values can be done with
267+ // representing the epoch milliseconds in a typed array;
268+ // also, perhaps the Python / R interfaces take care of String->Date conversions
269+ // such that there's no need to check for string dates in plotly.js)
270+ // Patterned from axis_defaults.js:moreDates
271+ // Code DRYing is not done to preserve the most direct compilation possible for speed;
272+ // also, there are quite a few differences
273+ function allFastTypesLikely ( a ) {
274+ var len = a . length ,
275+ inc = Math . max ( 0 , ( len - 1 ) / Math . min ( Math . max ( len , 1 ) , 1000 ) ) ,
276+ ai ;
277+
278+ for ( var i = 0 ; i < len ; i += inc ) {
279+ ai = a [ Math . floor ( i ) ] ;
280+ if ( ! isNumeric ( ai ) && ! ( ai instanceof Date ) ) {
281+ return false ;
282+ }
283+ }
284+
285+ return true ;
286+ }
287+
262288proto . updateFast = function ( options ) {
263289 var x = this . xData = this . pickXData = options . x ;
264290 var y = this . yData = this . pickYData = options . y ;
@@ -272,24 +298,34 @@ proto.updateFast = function(options) {
272298
273299 var xx , yy ;
274300
301+ var fastType = allFastTypesLikely ( x ) ;
302+ var isDateTime = ! fastType && autoType ( x ) === 'date' ;
303+
275304 // TODO add 'very fast' mode that bypasses this loop
276305 // TODO bypass this on modebar +/- zoom
277- for ( var i = 0 ; i < len ; ++ i ) {
278- xx = x [ i ] ;
279- yy = y [ i ] ;
306+ if ( fastType || isDateTime ) {
280307
281- // check for isNaN is faster but doesn't skip over nulls
282- if ( ! isNumeric ( xx ) || ! isNumeric ( yy ) ) continue ;
308+ for ( var i = 0 ; i < len ; ++ i ) {
309+ xx = x [ i ] ;
310+ yy = y [ i ] ;
283311
284- idToIndex [ pId ++ ] = i ;
312+ if ( isNumeric ( yy ) ) {
285313
286- positions [ ptr ++ ] = xx ;
287- positions [ ptr ++ ] = yy ;
314+ if ( ! fastType ) {
315+ xx = Lib . dateTime2ms ( xx ) ;
316+ }
317+
318+ idToIndex [ pId ++ ] = i ;
288319
289- bounds [ 0 ] = Math . min ( bounds [ 0 ] , xx ) ;
290- bounds [ 1 ] = Math . min ( bounds [ 1 ] , yy ) ;
291- bounds [ 2 ] = Math . max ( bounds [ 2 ] , xx ) ;
292- bounds [ 3 ] = Math . max ( bounds [ 3 ] , yy ) ;
320+ positions [ ptr ++ ] = xx ;
321+ positions [ ptr ++ ] = yy ;
322+
323+ bounds [ 0 ] = Math . min ( bounds [ 0 ] , xx ) ;
324+ bounds [ 1 ] = Math . min ( bounds [ 1 ] , yy ) ;
325+ bounds [ 2 ] = Math . max ( bounds [ 2 ] , xx ) ;
326+ bounds [ 3 ] = Math . max ( bounds [ 3 ] , yy ) ;
327+ }
328+ }
293329 }
294330
295331 positions = truncate ( positions , ptr ) ;
0 commit comments