@@ -167,27 +167,34 @@ exports.drawFramework = function(gd) {
167
167
. data ( subplotData , Lib . identity ) ;
168
168
169
169
subplotLayers . enter ( ) . append ( 'g' )
170
- . classed ( 'subplot ', true ) ;
170
+ . attr ( 'class ', function ( name ) { return 'subplot ' + name ; } ) ;
171
171
172
172
subplotLayers . order ( ) ;
173
173
174
174
subplotLayers . exit ( )
175
175
. call ( purgeSubplotLayers , fullLayout ) ;
176
176
177
- subplotLayers . each ( function ( subplot ) {
178
- var plotgroup = d3 . select ( this ) ,
179
- plotinfo = fullLayout . _plots [ subplot ] ;
177
+ subplotLayers . each ( function ( name ) {
178
+ var plotinfo = fullLayout . _plots [ name ] ;
179
+
180
+ // keep ref to plot group
181
+ plotinfo . plotgroup = d3 . select ( this ) ;
180
182
181
- // references to any subplots overlaid on this one,
182
- // filled in makeSubplotLayer
183
+ // initialize list of overlay subplots
183
184
plotinfo . overlays = [ ] ;
184
185
185
- plotgroup . call ( makeSubplotLayer , gd , subplot ) ;
186
+ makeSubplotLayer ( plotinfo ) ;
187
+
188
+ // fill in list of overlay subplots
189
+ if ( plotinfo . mainplot ) {
190
+ var mainplot = fullLayout . _plots [ plotinfo . mainplot ] ;
191
+ mainplot . overlays . push ( plotinfo ) ;
192
+ }
186
193
187
194
// make separate drag layers for each subplot,
188
195
// but append them to paper rather than the plot groups,
189
196
// so they end up on top of the rest
190
- plotinfo . draglayer = joinLayer ( fullLayout . _draggers , 'g' , subplot ) ;
197
+ plotinfo . draglayer = joinLayer ( fullLayout . _draggers , 'g' , name ) ;
191
198
} ) ;
192
199
} ;
193
200
@@ -225,6 +232,7 @@ function makeSubplotData(gd) {
225
232
var mainplot = xa2 . _id + ya2 . _id ;
226
233
if ( mainplot !== subplot && subplots . indexOf ( mainplot ) !== - 1 ) {
227
234
plotinfo . mainplot = mainplot ;
235
+ plotinfo . mainplotinfo = fullLayout . _plots [ mainplot ] ;
228
236
overlays . push ( subplot ) ;
229
237
230
238
// for now force overlays to overlay completely... so they
@@ -247,15 +255,9 @@ function makeSubplotData(gd) {
247
255
return subplotData ;
248
256
}
249
257
250
- function makeSubplotLayer ( plotgroup , gd , subplot ) {
251
- var fullLayout = gd . _fullLayout ,
252
- plotinfo = fullLayout . _plots [ subplot ] ;
253
-
254
- // keep reference to plotgroup in _plots object
255
- plotinfo . plotgroup = plotgroup ;
256
-
257
- // add class corresponding to the subplot id
258
- plotgroup . classed ( subplot , true ) ;
258
+ function makeSubplotLayer ( plotinfo ) {
259
+ var plotgroup = plotinfo . plotgroup ,
260
+ id = plotinfo . id ;
259
261
260
262
// Layers to keep plot types in the right order.
261
263
// from back to front:
@@ -264,7 +266,7 @@ function makeSubplotLayer(plotgroup, gd, subplot) {
264
266
// 3. errorbars for bars and scatter
265
267
// 4. scatter
266
268
// 5. box plots
267
- function plotLayers ( parent ) {
269
+ function joinPlotLayers ( parent ) {
268
270
joinLayer ( parent , 'g' , 'imagelayer' ) ;
269
271
joinLayer ( parent , 'g' , 'maplayer' ) ;
270
272
joinLayer ( parent , 'g' , 'barlayer' ) ;
@@ -298,27 +300,25 @@ function makeSubplotLayer(plotgroup, gd, subplot) {
298
300
plotinfo . overaxes = joinLayer ( plotgroup , 'g' , 'overaxes' ) ;
299
301
}
300
302
else {
303
+ var mainplotinfo = plotinfo . mainplotinfo ;
301
304
302
305
// now make the components of overlaid subplots
303
306
// overlays don't have backgrounds, and append all
304
307
// their other components to the corresponding
305
308
// extra groups of their main plots.
306
309
307
- var mainplot = fullLayout . _plots [ plotinfo . mainplot ] ;
308
- mainplot . overlays . push ( plotinfo ) ;
310
+ plotinfo . gridlayer = joinLayer ( mainplotinfo . overgrid , 'g' , id ) ;
311
+ plotinfo . zerolinelayer = joinLayer ( mainplotinfo . overzero , 'g' , id ) ;
309
312
310
- plotinfo . gridlayer = joinLayer ( mainplot . overgrid , 'g' , subplot ) ;
311
- plotinfo . zerolinelayer = joinLayer ( mainplot . overzero , 'g' , subplot ) ;
312
-
313
- plotinfo . plot = joinLayer ( mainplot . overplot , 'g' , subplot ) ;
314
- plotinfo . xlines = joinLayer ( mainplot . overlines , 'path' , subplot ) ;
315
- plotinfo . ylines = joinLayer ( mainplot . overlines , 'path' , subplot ) ;
316
- plotinfo . xaxislayer = joinLayer ( mainplot . overaxes , 'g' , subplot ) ;
317
- plotinfo . yaxislayer = joinLayer ( mainplot . overaxes , 'g' , subplot ) ;
313
+ plotinfo . plot = joinLayer ( mainplotinfo . overplot , 'g' , id ) ;
314
+ plotinfo . xlines = joinLayer ( mainplotinfo . overlines , 'path' , id ) ;
315
+ plotinfo . ylines = joinLayer ( mainplotinfo . overlines , 'path' , id ) ;
316
+ plotinfo . xaxislayer = joinLayer ( mainplotinfo . overaxes , 'g' , id ) ;
317
+ plotinfo . yaxislayer = joinLayer ( mainplotinfo . overaxes , 'g' , id ) ;
318
318
}
319
319
320
320
// common attributes for all subplots, overlays or not
321
- plotinfo . plot . call ( plotLayers ) ;
321
+ plotinfo . plot . call ( joinPlotLayers ) ;
322
322
323
323
plotinfo . xlines
324
324
. style ( 'fill' , 'none' )
@@ -345,7 +345,6 @@ function purgeSubplotLayers(layers, fullLayout) {
345
345
} ) ;
346
346
}
347
347
348
-
349
348
function joinLayer ( parent , nodeType , className ) {
350
349
var layer = parent . selectAll ( '.' + className )
351
350
. data ( [ 0 ] ) ;
0 commit comments