Skip to content

Commit 937c54b

Browse files
committed
add baseModule drawFramework step
- after several failed attempts at getting cartesian subplot creation/update/removal into the Cartesian.plot (like the other base plot module), I decide to go with a less ambitious refactoring where a drawFramework update step is added to the main Plotly.plot code path - Main reason: several layout components require the cartesian framework to be present in order to work properly.
1 parent 43d227a commit 937c54b

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/plot_api/plot_api.js

+25-10
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,24 @@ Plotly.plot = function(gd, data, layout, config) {
154154

155155
var oldmargins = JSON.stringify(fullLayout._size);
156156

157+
// draw framework first so that margin-pushing
158+
// components can position themselves correctly
159+
function drawFramework() {
160+
var basePlotModules = fullLayout._basePlotModules;
161+
162+
for(var i = 0; i < basePlotModules.length; i++) {
163+
if(basePlotModules[i].drawFramework) {
164+
basePlotModules[i].drawFramework(gd);
165+
}
166+
}
167+
168+
return Lib.syncOrAsync([
169+
subroutines.layoutStyles,
170+
drawAxes,
171+
Fx.init
172+
], gd);
173+
}
174+
157175
// draw anything that can affect margins.
158176
// currently this is legend and colorbars
159177
function marginPushers() {
@@ -227,6 +245,11 @@ Plotly.plot = function(gd, data, layout, config) {
227245
}
228246
}
229247

248+
// draw ticks, titles, and calculate axis scaling (._b, ._m)
249+
function drawAxes() {
250+
return Plotly.Axes.doTicks(gd, 'redraw');
251+
}
252+
230253
// Now plot the data
231254
function drawData() {
232255
var calcdata = gd.calcdata,
@@ -279,15 +302,6 @@ Plotly.plot = function(gd, data, layout, config) {
279302
return Plots.previousPromises(gd);
280303
}
281304

282-
// draw ticks, titles, and calculate axis scaling (._b, ._m)
283-
function drawAxes() {
284-
Lib.syncOrAsync([
285-
subroutines.layoutStyles,
286-
function() { return Plotly.Axes.doTicks(gd, 'redraw'); },
287-
Fx.init,
288-
], gd);
289-
}
290-
291305
// An initial paint must be completed before these components can be
292306
// correctly sized and the whole plot re-margined. gd._replotting must
293307
// be set to false before these will work properly.
@@ -309,12 +323,13 @@ Plotly.plot = function(gd, data, layout, config) {
309323

310324
Lib.syncOrAsync([
311325
Plots.previousPromises,
326+
drawFramework,
312327
marginPushers,
313328
marginPushersAgain,
314329
positionAndAutorange,
315330
subroutines.layoutStyles,
316-
drawData,
317331
drawAxes,
332+
drawData,
318333
finalDraw
319334
], gd, cleanUp);
320335

src/plots/cartesian/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
3737
calcdata = gd.calcdata,
3838
modules = fullLayout._modules;
3939

40-
updateSubplots(gd);
41-
4240
if(!Array.isArray(traces)) {
4341
// If traces is not provided, then it's a complete replot and missing
4442
// traces are removed
@@ -151,7 +149,7 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
151149
}
152150
};
153151

154-
function updateSubplots(gd) {
152+
exports.drawFramework = function(gd) {
155153
var fullLayout = gd._fullLayout,
156154
subplotData = makeSubplotData(gd);
157155

@@ -178,7 +176,7 @@ function updateSubplots(gd) {
178176
// so they end up on top of the rest
179177
plotinfo.draglayer = joinLayer(fullLayout._draggers, 'g', subplot);
180178
});
181-
}
179+
};
182180

183181
function makeSubplotData(gd) {
184182
var fullLayout = gd._fullLayout,

0 commit comments

Comments
 (0)