@@ -33,12 +33,15 @@ function LineWithMarkers(scene, uid) {
3333 this . scene = scene ;
3434 this . uid = uid ;
3535
36+ this . pickXData = [ ] ;
37+ this . pickYData = [ ] ;
3638 this . xData = [ ] ;
3739 this . yData = [ ] ;
3840 this . textLabels = [ ] ;
3941 this . color = 'rgb(0, 0, 0)' ;
4042 this . name = '' ;
4143 this . hoverinfo = 'all' ;
44+ this . connectgaps = true ;
4245
4346 this . idToIndex = [ ] ;
4447 this . bounds = [ 0 , 0 , 0 , 0 ] ;
@@ -103,14 +106,17 @@ function LineWithMarkers(scene, uid) {
103106var proto = LineWithMarkers . prototype ;
104107
105108proto . handlePick = function ( pickResult ) {
106- var index = this . idToIndex [ pickResult . pointId ] ;
109+ var index = pickResult . pointId ;
110+ if ( pickResult . object !== this . line || this . connectgaps ) {
111+ index = this . idToIndex [ pickResult . pointId ] ;
112+ }
107113
108114 return {
109115 trace : this ,
110116 dataCoord : pickResult . dataCoord ,
111117 traceCoord : [
112- this . xData [ index ] ,
113- this . yData [ index ]
118+ this . pickXData [ index ] ,
119+ this . pickYData [ index ]
114120 ] ,
115121 textLabel : Array . isArray ( this . textLabels ) ?
116122 this . textLabels [ index ] :
@@ -248,6 +254,7 @@ proto.update = function(options) {
248254 this . name = options . name ;
249255 this . hoverinfo = options . hoverinfo ;
250256 this . bounds = [ Infinity , Infinity , - Infinity , - Infinity ] ;
257+ this . connectgaps = ! ! options . connectgaps ;
251258
252259 if ( this . isFancy ( options ) ) {
253260 this . updateFancy ( options ) ;
@@ -262,8 +269,8 @@ proto.update = function(options) {
262269} ;
263270
264271proto . updateFast = function ( options ) {
265- var x = this . xData = options . x ;
266- var y = this . yData = options . y ;
272+ var x = this . xData = this . pickXData = options . x ;
273+ var y = this . yData = this . pickYData = options . y ;
267274
268275 var len = x . length ,
269276 idToIndex = new Array ( len ) ,
@@ -344,8 +351,11 @@ proto.updateFancy = function(options) {
344351 bounds = this . bounds ;
345352
346353 // makeCalcdata runs d2c (data-to-coordinate) on every point
347- var x = this . xData = xaxis . makeCalcdata ( options , 'x' ) ;
348- var y = this . yData = yaxis . makeCalcdata ( options , 'y' ) ;
354+ var x = this . pickXData = xaxis . makeCalcdata ( options , 'x' ) . slice ( ) ;
355+ var y = this . pickYData = yaxis . makeCalcdata ( options , 'y' ) . slice ( ) ;
356+
357+ this . xData = x . slice ( ) ;
358+ this . yData = y . slice ( ) ;
349359
350360 // get error values
351361 var errorVals = ErrorBars . calcFromTrace ( options , scene . fullLayout ) ;
@@ -370,8 +380,8 @@ proto.updateFancy = function(options) {
370380 var i , j , xx , yy , ex0 , ex1 , ey0 , ey1 ;
371381
372382 for ( i = 0 ; i < len ; ++ i ) {
373- xx = getX ( x [ i ] ) ;
374- yy = getY ( y [ i ] ) ;
383+ this . xData [ i ] = xx = getX ( x [ i ] ) ;
384+ this . yData [ i ] = yy = getY ( y [ i ] ) ;
375385
376386 if ( isNaN ( xx ) || isNaN ( yy ) ) continue ;
377387
@@ -460,16 +470,29 @@ proto.updateFancy = function(options) {
460470} ;
461471
462472proto . updateLines = function ( options , positions ) {
473+ var i ;
463474 if ( this . hasLines ) {
464- this . lineOptions . positions = positions ;
475+ var linePositions = positions ;
476+ if ( ! options . connectgaps ) {
477+ var p = 0 ;
478+ var x = this . xData ;
479+ var y = this . yData ;
480+ linePositions = new Float32Array ( 2 * x . length ) ;
481+
482+ for ( i = 0 ; i < x . length ; ++ i ) {
483+ linePositions [ p ++ ] = x [ i ] ;
484+ linePositions [ p ++ ] = y [ i ] ;
485+ }
486+ }
487+ this . lineOptions . positions = linePositions ;
465488
466489 var lineColor = str2RGBArray ( options . line . color ) ;
467490 if ( this . hasMarkers ) lineColor [ 3 ] *= options . marker . opacity ;
468491
469492 var lineWidth = Math . round ( 0.5 * this . lineOptions . width ) ,
470493 dashes = ( DASHES [ options . line . dash ] || [ 1 ] ) . slice ( ) ;
471494
472- for ( var i = 0 ; i < dashes . length ; ++ i ) dashes [ i ] *= lineWidth ;
495+ for ( i = 0 ; i < dashes . length ; ++ i ) dashes [ i ] *= lineWidth ;
473496
474497 switch ( options . fill ) {
475498 case 'tozeroy' :
0 commit comments