Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a708381

Browse files
committed
make makeSubplotLayer agnostic to fullLayout
- to allow calling outside the drawFramework step
1 parent ae3ab55 commit a708381

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

src/plots/cartesian/index.js

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -167,27 +167,34 @@ exports.drawFramework = function(gd) {
167167
.data(subplotData, Lib.identity);
168168

169169
subplotLayers.enter().append('g')
170-
.classed('subplot', true);
170+
.attr('class', function(name) { return 'subplot ' + name; });
171171

172172
subplotLayers.order();
173173

174174
subplotLayers.exit()
175175
.call(purgeSubplotLayers, fullLayout);
176176

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);
180182

181-
// references to any subplots overlaid on this one,
182-
// filled in makeSubplotLayer
183+
// initialize list of overlay subplots
183184
plotinfo.overlays = [];
184185

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+
}
186193

187194
// make separate drag layers for each subplot,
188195
// but append them to paper rather than the plot groups,
189196
// 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);
191198
});
192199
};
193200

@@ -225,6 +232,7 @@ function makeSubplotData(gd) {
225232
var mainplot = xa2._id + ya2._id;
226233
if(mainplot !== subplot && subplots.indexOf(mainplot) !== -1) {
227234
plotinfo.mainplot = mainplot;
235+
plotinfo.mainplotinfo = fullLayout._plots[mainplot];
228236
overlays.push(subplot);
229237

230238
// for now force overlays to overlay completely... so they
@@ -247,15 +255,9 @@ function makeSubplotData(gd) {
247255
return subplotData;
248256
}
249257

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;
259261

260262
// Layers to keep plot types in the right order.
261263
// from back to front:
@@ -264,7 +266,7 @@ function makeSubplotLayer(plotgroup, gd, subplot) {
264266
// 3. errorbars for bars and scatter
265267
// 4. scatter
266268
// 5. box plots
267-
function plotLayers(parent) {
269+
function joinPlotLayers(parent) {
268270
joinLayer(parent, 'g', 'imagelayer');
269271
joinLayer(parent, 'g', 'maplayer');
270272
joinLayer(parent, 'g', 'barlayer');
@@ -298,27 +300,25 @@ function makeSubplotLayer(plotgroup, gd, subplot) {
298300
plotinfo.overaxes = joinLayer(plotgroup, 'g', 'overaxes');
299301
}
300302
else {
303+
var mainplotinfo = plotinfo.mainplotinfo;
301304

302305
// now make the components of overlaid subplots
303306
// overlays don't have backgrounds, and append all
304307
// their other components to the corresponding
305308
// extra groups of their main plots.
306309

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);
309312

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);
318318
}
319319

320320
// common attributes for all subplots, overlays or not
321-
plotinfo.plot.call(plotLayers);
321+
plotinfo.plot.call(joinPlotLayers);
322322

323323
plotinfo.xlines
324324
.style('fill', 'none')
@@ -345,7 +345,6 @@ function purgeSubplotLayers(layers, fullLayout) {
345345
});
346346
}
347347

348-
349348
function joinLayer(parent, nodeType, className) {
350349
var layer = parent.selectAll('.' + className)
351350
.data([0]);

0 commit comments

Comments
 (0)