Skip to content

Commit

Permalink
Merge pull request #3506 from plotly/matching-axes-final
Browse files Browse the repository at this point in the history
Implementing matching axes
  • Loading branch information
etpinard authored Feb 18, 2019
2 parents 12097a2 + 1713c83 commit 25fa0c2
Show file tree
Hide file tree
Showing 30 changed files with 3,612 additions and 666 deletions.
43 changes: 33 additions & 10 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1940,22 +1940,34 @@ exports.relayout = relayout;
// Optimization mostly for large splom traces where
// Plots.supplyDefaults can take > 100ms
function axRangeSupplyDefaultsByPass(gd, flags, specs) {
var k;
var fullLayout = gd._fullLayout;

if(!flags.axrange) return false;

for(k in flags) {
for(var k in flags) {
if(k !== 'axrange' && flags[k]) return false;
}

for(k in specs.rangesAltered) {
var axName = Axes.id2name(k);
for(var axId in specs.rangesAltered) {
var axName = Axes.id2name(axId);
var axIn = gd.layout[axName];
var axOut = gd._fullLayout[axName];
var axOut = fullLayout[axName];
axOut.autorange = axIn.autorange;
axOut.range = axIn.range.slice();
axOut.cleanRange();

if(axOut._matchGroup) {
for(var axId2 in axOut._matchGroup) {
if(axId2 !== axId) {
var ax2 = fullLayout[Axes.id2name(axId2)];
ax2.autorange = axOut.autorange;
ax2.range = axOut.range.slice();
ax2._input.range = axOut.range.slice();
}
}
}
}

return true;
}

Expand All @@ -1965,14 +1977,25 @@ function addAxRangeSequence(seq, rangesAltered) {
// executed after drawData
var drawAxes = rangesAltered ?
function(gd) {
var opts = {skipTitle: true};
var axIds = [];
var skipTitle = true;

for(var id in rangesAltered) {
if(Axes.getFromId(gd, id).automargin) {
opts = {};
break;
var ax = Axes.getFromId(gd, id);
axIds.push(id);

if(ax._matchGroup) {
for(var id2 in ax._matchGroup) {
if(!rangesAltered[id2]) {
axIds.push(id2);
}
}
}

if(ax.automargin) skipTitle = false;
}
return Axes.draw(gd, Object.keys(rangesAltered), opts);

return Axes.draw(gd, axIds, {skipTitle: skipTitle});
} :
function(gd) {
return Axes.draw(gd, 'redraw');
Expand Down
38 changes: 35 additions & 3 deletions src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,17 +697,49 @@ exports.redrawReglTraces = function(gd) {
};

exports.doAutoRangeAndConstraints = function(gd) {
var fullLayout = gd._fullLayout;
var axList = Axes.list(gd, '', true);
var matchGroups = fullLayout._axisMatchGroups || [];
var ax;

for(var i = 0; i < axList.length; i++) {
var ax = axList[i];
ax = axList[i];
cleanAxisConstraints(gd, ax);
// in case margins changed, update scale
ax.setScale();
doAutoRange(gd, ax);
}

enforceAxisConstraints(gd);

groupLoop:
for(var j = 0; j < matchGroups.length; j++) {
var group = matchGroups[j];
var rng = null;
var id;

for(id in group) {
ax = Axes.getFromId(gd, id);
if(ax.autorange === false) continue groupLoop;

if(rng) {
if(rng[0] < rng[1]) {
rng[0] = Math.min(rng[0], ax.range[0]);
rng[1] = Math.max(rng[1], ax.range[1]);
} else {
rng[0] = Math.max(rng[0], ax.range[0]);
rng[1] = Math.min(rng[1], ax.range[1]);
}
} else {
rng = ax.range;
}
}

for(id in group) {
ax = Axes.getFromId(gd, id);
ax.range = rng.slice();
ax._input.range = rng.slice();
ax.setScale();
}
}
};

// An initial paint must be completed before these components can be
Expand Down
2 changes: 2 additions & 0 deletions src/plots/cartesian/autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ function concatExtremes(gd, ax) {
}

function doAutoRange(gd, ax) {
ax.setScale();

if(ax.autorange) {
ax.range = getAutoRange(gd, ax);

Expand Down
152 changes: 0 additions & 152 deletions src/plots/cartesian/constraint_defaults.js

This file was deleted.

Loading

0 comments on commit 25fa0c2

Please sign in to comment.