Skip to content

Commit

Permalink
add baseModule drawFramework step
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
etpinard committed Sep 16, 2016
1 parent 43d227a commit 937c54b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
35 changes: 25 additions & 10 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ Plotly.plot = function(gd, data, layout, config) {

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

// draw framework first so that margin-pushing
// components can position themselves correctly
function drawFramework() {
var basePlotModules = fullLayout._basePlotModules;

for(var i = 0; i < basePlotModules.length; i++) {
if(basePlotModules[i].drawFramework) {
basePlotModules[i].drawFramework(gd);
}
}

return Lib.syncOrAsync([
subroutines.layoutStyles,
drawAxes,
Fx.init
], gd);
}

// draw anything that can affect margins.
// currently this is legend and colorbars
function marginPushers() {
Expand Down Expand Up @@ -227,6 +245,11 @@ Plotly.plot = function(gd, data, layout, config) {
}
}

// draw ticks, titles, and calculate axis scaling (._b, ._m)
function drawAxes() {
return Plotly.Axes.doTicks(gd, 'redraw');
}

// Now plot the data
function drawData() {
var calcdata = gd.calcdata,
Expand Down Expand Up @@ -279,15 +302,6 @@ Plotly.plot = function(gd, data, layout, config) {
return Plots.previousPromises(gd);
}

// draw ticks, titles, and calculate axis scaling (._b, ._m)
function drawAxes() {
Lib.syncOrAsync([
subroutines.layoutStyles,
function() { return Plotly.Axes.doTicks(gd, 'redraw'); },
Fx.init,
], gd);
}

// An initial paint must be completed before these components can be
// correctly sized and the whole plot re-margined. gd._replotting must
// be set to false before these will work properly.
Expand All @@ -309,12 +323,13 @@ Plotly.plot = function(gd, data, layout, config) {

Lib.syncOrAsync([
Plots.previousPromises,
drawFramework,
marginPushers,
marginPushersAgain,
positionAndAutorange,
subroutines.layoutStyles,
drawData,
drawAxes,
drawData,
finalDraw
], gd, cleanUp);

Expand Down
6 changes: 2 additions & 4 deletions src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
calcdata = gd.calcdata,
modules = fullLayout._modules;

updateSubplots(gd);

if(!Array.isArray(traces)) {
// If traces is not provided, then it's a complete replot and missing
// traces are removed
Expand Down Expand Up @@ -151,7 +149,7 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
}
};

function updateSubplots(gd) {
exports.drawFramework = function(gd) {
var fullLayout = gd._fullLayout,
subplotData = makeSubplotData(gd);

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

function makeSubplotData(gd) {
var fullLayout = gd._fullLayout,
Expand Down

0 comments on commit 937c54b

Please sign in to comment.