@@ -13,6 +13,8 @@ var d3 = require('d3');
13
13
14
14
var Registry = require ( '../../registry' ) ;
15
15
var Lib = require ( '../../lib' ) ;
16
+ var ensureSingle = Lib . ensureSingle ;
17
+ var identity = Lib . identity ;
16
18
var Drawing = require ( '../../components/drawing' ) ;
17
19
18
20
var subTypes = require ( './subtypes' ) ;
@@ -43,7 +45,7 @@ module.exports = function plot(gd, plotinfo, cdscatter, scatterLayer, transition
43
45
// the z-order of fill layers is correct.
44
46
linkTraces ( gd , plotinfo , cdscatter ) ;
45
47
46
- createFills ( gd , scatterLayer , plotinfo ) ;
48
+ createFills ( gd , join , plotinfo ) ;
47
49
48
50
// Sort the traces, once created, so that the ordering is preserved even when traces
49
51
// are shown and hidden. This is needed since we're not just wiping everything out
@@ -52,10 +54,10 @@ module.exports = function plot(gd, plotinfo, cdscatter, scatterLayer, transition
52
54
uids [ cdscatter [ i ] [ 0 ] . trace . uid ] = i ;
53
55
}
54
56
55
- scatterLayer . selectAll ( 'g.trace' ) . sort ( function ( a , b ) {
57
+ join . sort ( function ( a , b ) {
56
58
var idx1 = uids [ a [ 0 ] . trace . uid ] ;
57
59
var idx2 = uids [ b [ 0 ] . trace . uid ] ;
58
- return idx1 > idx2 ? 1 : - 1 ;
60
+ return idx1 - idx2 ;
59
61
} ) ;
60
62
61
63
if ( hasTransition ) {
@@ -97,51 +99,45 @@ module.exports = function plot(gd, plotinfo, cdscatter, scatterLayer, transition
97
99
scatterLayer . selectAll ( 'path:not([d])' ) . remove ( ) ;
98
100
} ;
99
101
100
- function createFills ( gd , scatterLayer , plotinfo ) {
101
- var trace ;
102
+ function createFills ( gd , traceJoin , plotinfo ) {
103
+ traceJoin . each ( function ( d ) {
104
+ var fills = ensureSingle ( d3 . select ( this ) , 'g' , 'fills' ) ;
105
+ Drawing . setClipUrl ( fills , plotinfo . layerClipId ) ;
102
106
103
- scatterLayer . selectAll ( 'g.trace' ) . each ( function ( d ) {
104
- var tr = d3 . select ( this ) ;
105
-
106
- // Loop only over the traces being redrawn:
107
- trace = d [ 0 ] . trace ;
107
+ var trace = d [ 0 ] . trace ;
108
108
109
- // make the fill-to-next path now for the NEXT trace, so it shows
110
- // behind both lines.
109
+ var fillData = [ ] ;
110
+ if ( trace . fill && ( trace . fill . substr ( 0 , 6 ) === 'tozero' || trace . fill === 'toself' ||
111
+ ( trace . fill . substr ( 0 , 2 ) === 'to' && ! trace . _prevtrace ) )
112
+ ) {
113
+ fillData = [ '_ownFill' ] ;
114
+ }
111
115
if ( trace . _nexttrace ) {
112
- trace . _nextFill = tr . select ( '.js-fill.js-tonext' ) ;
113
- if ( ! trace . _nextFill . size ( ) ) {
116
+ // make the fill-to-next path now for the NEXT trace, so it shows
117
+ // behind both lines.
118
+ fillData . push ( '_nextFill' ) ;
119
+ }
114
120
115
- // If there is an existing tozero fill, we must insert this *after* that fill:
116
- var loc = ':first-child' ;
117
- if ( tr . select ( '.js-fill.js-tozero' ) . size ( ) ) {
118
- loc += ' + *' ;
119
- }
121
+ var fillJoin = fills . selectAll ( 'g' )
122
+ . data ( fillData , identity ) ;
120
123
121
- trace . _nextFill = tr . insert ( 'path' , loc ) . attr ( 'class' , 'js-fill js-tonext' ) ;
122
- }
123
- } else {
124
- tr . selectAll ( '.js-fill.js-tonext' ) . remove ( ) ;
125
- trace . _nextFill = null ;
126
- }
124
+ fillJoin . enter ( ) . append ( 'g' ) ;
127
125
128
- if ( trace . fill && ( trace . fill . substr ( 0 , 6 ) === 'tozero' || trace . fill === 'toself' ||
129
- ( trace . fill . substr ( 0 , 2 ) === 'to' && ! trace . _prevtrace ) ) ) {
130
- trace . _ownFill = tr . select ( '.js-fill.js-tozero' ) ;
131
- if ( ! trace . _ownFill . size ( ) ) {
132
- trace . _ownFill = tr . insert ( 'path' , ':first-child' ) . attr ( 'class' , 'js-fill js-tozero' ) ;
133
- }
134
- } else {
135
- tr . selectAll ( '.js-fill.js-tozero' ) . remove ( ) ;
136
- trace . _ownFill = null ;
137
- }
126
+ fillJoin . exit ( )
127
+ . each ( function ( d ) { trace [ d ] = null ; } )
128
+ . remove ( ) ;
138
129
139
- tr . selectAll ( '.js-fill' ) . call ( Drawing . setClipUrl , plotinfo . layerClipId ) ;
130
+ fillJoin . order ( ) . each ( function ( d ) {
131
+ // make a path element inside the fill group, just so
132
+ // we can give it its own data later on and the group can
133
+ // keep its simple '_*Fill' data
134
+ trace [ d ] = ensureSingle ( d3 . select ( this ) , 'path' , 'js-fill' ) ;
135
+ } ) ;
140
136
} ) ;
141
137
}
142
138
143
139
function plotOne ( gd , idx , plotinfo , cdscatter , cdscatterAll , element , transitionOpts ) {
144
- var join , i ;
140
+ var i ;
145
141
146
142
// Since this has been reorganized and we're executing this on individual traces,
147
143
// we need to pass it the full list of cdscatter as well as this trace's index (idx)
@@ -157,12 +153,17 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
157
153
var xa = plotinfo . xaxis ,
158
154
ya = plotinfo . yaxis ;
159
155
160
- var trace = cdscatter [ 0 ] . trace ,
161
- line = trace . line ,
162
- tr = d3 . select ( element ) ;
156
+ var trace = cdscatter [ 0 ] . trace ;
157
+ var line = trace . line ;
158
+ var tr = d3 . select ( element ) ;
159
+
160
+ var errorBarGroup = ensureSingle ( tr , 'g' , 'errorbars' ) ;
161
+ var lines = ensureSingle ( tr , 'g' , 'lines' ) ;
162
+ var points = ensureSingle ( tr , 'g' , 'points' ) ;
163
+ var text = ensureSingle ( tr , 'g' , 'text' ) ;
163
164
164
165
// error bars are at the bottom
165
- Registry . getComponentMethod ( 'errorbars' , 'plot' ) ( tr , plotinfo , transitionOpts ) ;
166
+ Registry . getComponentMethod ( 'errorbars' , 'plot' ) ( errorBarGroup , plotinfo , transitionOpts ) ;
166
167
167
168
if ( trace . visible !== true ) return ;
168
169
@@ -303,7 +304,7 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
303
304
} ;
304
305
}
305
306
306
- var lineJoin = tr . selectAll ( '.js-line' ) . data ( segments ) ;
307
+ var lineJoin = lines . selectAll ( '.js-line' ) . data ( segments ) ;
307
308
308
309
transition ( lineJoin . exit ( ) )
309
310
. style ( 'opacity' , 0 )
@@ -325,6 +326,7 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
325
326
326
327
if ( segments . length ) {
327
328
if ( ownFillEl3 ) {
329
+ ownFillEl3 . datum ( cdscatter ) ;
328
330
if ( pt0 && pt1 ) {
329
331
if ( ownFillDir ) {
330
332
if ( ownFillDir === 'y' ) {
@@ -404,11 +406,10 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
404
406
return false ;
405
407
}
406
408
407
- function makePoints ( d ) {
409
+ function makePoints ( points , text , cdscatter ) {
408
410
var join , selection , hasNode ;
409
411
410
- var trace = d [ 0 ] . trace ;
411
- var s = d3 . select ( this ) ;
412
+ var trace = cdscatter [ 0 ] . trace ;
412
413
var showMarkers = subTypes . hasMarkers ( trace ) ;
413
414
var showText = subTypes . hasText ( trace ) ;
414
415
@@ -417,16 +418,16 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
417
418
var textFilter = hideFilter ;
418
419
419
420
if ( showMarkers ) {
420
- markerFilter = ( trace . marker . maxdisplayed || trace . _needsCull ) ? visFilter : Lib . identity ;
421
+ markerFilter = ( trace . marker . maxdisplayed || trace . _needsCull ) ? visFilter : identity ;
421
422
}
422
423
423
424
if ( showText ) {
424
- textFilter = ( trace . marker . maxdisplayed || trace . _needsCull ) ? visFilter : Lib . identity ;
425
+ textFilter = ( trace . marker . maxdisplayed || trace . _needsCull ) ? visFilter : identity ;
425
426
}
426
427
427
428
// marker points
428
429
429
- selection = s . selectAll ( 'path.point' ) ;
430
+ selection = points . selectAll ( 'path.point' ) ;
430
431
431
432
join = selection . data ( markerFilter , keyFunc ) ;
432
433
@@ -478,7 +479,7 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
478
479
}
479
480
480
481
// text points
481
- selection = s . selectAll ( 'g' ) ;
482
+ selection = text . selectAll ( 'g' ) ;
482
483
join = selection . data ( textFilter , keyFunc ) ;
483
484
484
485
// each text needs to go in its own 'g' in case
@@ -517,28 +518,16 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
517
518
join . exit ( ) . remove ( ) ;
518
519
}
519
520
520
- // NB: selectAll is evaluated on instantiation:
521
- var pointSelection = tr . selectAll ( '.points' ) ;
522
-
523
- // Join with new data
524
- join = pointSelection . data ( [ cdscatter ] ) ;
525
-
526
- // Transition existing, but don't defer this to an async .transition since
527
- // there's no timing involved:
528
- pointSelection . each ( makePoints ) ;
529
-
530
- join . enter ( ) . append ( 'g' )
531
- . classed ( 'points' , true )
532
- . each ( makePoints ) ;
533
-
534
- join . exit ( ) . remove ( ) ;
521
+ points . datum ( cdscatter ) ;
522
+ text . datum ( cdscatter ) ;
523
+ makePoints ( points , text , cdscatter ) ;
535
524
536
525
// lastly, clip points groups of `cliponaxis !== false` traces
537
526
// on `plotinfo._hasClipOnAxisFalse === true` subplots
538
- join . each ( function ( d ) {
539
- var hasClipOnAxisFalse = d [ 0 ] . trace . cliponaxis === false ;
540
- Drawing . setClipUrl ( d3 . select ( this ) , hasClipOnAxisFalse ? null : plotinfo . layerClipId ) ;
541
- } ) ;
527
+ var hasClipOnAxisFalse = trace . cliponaxis === false ;
528
+ var clipUrl = hasClipOnAxisFalse ? null : plotinfo . layerClipId ;
529
+ Drawing . setClipUrl ( points , clipUrl ) ;
530
+ Drawing . setClipUrl ( text , clipUrl ) ;
542
531
}
543
532
544
533
function selectMarkers ( gd , idx , plotinfo , cdscatter , cdscatterAll ) {
0 commit comments