Skip to content

Commit 42aabe1

Browse files
committed
rework matching & scaleanchor so they work together
match-scale partial matches + scaleanchor partial 2 scale-match even more match-scale moremore
1 parent a382098 commit 42aabe1

18 files changed

+504
-332
lines changed

src/plot_api/plot_api.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,21 +2283,18 @@ function _relayout(gd, aobj) {
22832283
}
22842284

22852285
// figure out if we need to recalculate axis constraints
2286-
var constraints = fullLayout._axisConstraintGroups || [];
22872286
for(axId in rangesAltered) {
2288-
for(i = 0; i < constraints.length; i++) {
2289-
var group = constraints[i];
2290-
if(group[axId]) {
2291-
// Always recalc if we're changing constrained ranges.
2292-
// Otherwise it's possible to violate the constraints by
2293-
// specifying arbitrary ranges for all axes in the group.
2294-
// this way some ranges may expand beyond what's specified,
2295-
// as they do at first draw, to satisfy the constraints.
2296-
flags.calc = true;
2297-
for(var groupAxId in group) {
2298-
if(!rangesAltered[groupAxId]) {
2299-
Axes.getFromId(gd, groupAxId)._constraintShrinkable = true;
2300-
}
2287+
var group = Axes.getFromId(gd, axId)._constraintGroup;
2288+
if(group) {
2289+
// Always recalc if we're changing constrained ranges.
2290+
// Otherwise it's possible to violate the constraints by
2291+
// specifying arbitrary ranges for all axes in the group.
2292+
// this way some ranges may expand beyond what's specified,
2293+
// as they do at first draw, to satisfy the constraints.
2294+
flags.calc = true;
2295+
for(var groupAxId in group) {
2296+
if(!rangesAltered[groupAxId]) {
2297+
Axes.getFromId(gd, groupAxId)._constraintShrinkable = true;
23012298
}
23022299
}
23032300
}

src/plot_api/subroutines.js

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -667,57 +667,16 @@ exports.redrawReglTraces = function(gd) {
667667
};
668668

669669
exports.doAutoRangeAndConstraints = function(gd) {
670-
var fullLayout = gd._fullLayout;
671670
var axList = Axes.list(gd, '', true);
672-
var matchGroups = fullLayout._axisMatchGroups || [];
673-
var axLookup = {};
674671
var ax;
675-
var axRng;
676672

677673
for(var i = 0; i < axList.length; i++) {
678674
ax = axList[i];
679675
cleanAxisConstraints(gd, ax);
680676
doAutoRange(gd, ax);
681-
axLookup[ax._id] = 1;
682677
}
683678

684679
enforceAxisConstraints(gd);
685-
686-
groupLoop:
687-
for(var j = 0; j < matchGroups.length; j++) {
688-
var group = matchGroups[j];
689-
var rng = null;
690-
var id;
691-
692-
for(id in group) {
693-
ax = Axes.getFromId(gd, id);
694-
695-
// skip over 'missing' axes which do not pass through doAutoRange
696-
if(!axLookup[ax._id]) continue;
697-
// if one axis has autorange false, we're done
698-
if(ax.autorange === false) continue groupLoop;
699-
700-
axRng = Lib.simpleMap(ax.range, ax.r2l);
701-
if(rng) {
702-
if(rng[0] < rng[1]) {
703-
rng[0] = Math.min(rng[0], axRng[0]);
704-
rng[1] = Math.max(rng[1], axRng[1]);
705-
} else {
706-
rng[0] = Math.max(rng[0], axRng[0]);
707-
rng[1] = Math.min(rng[1], axRng[1]);
708-
}
709-
} else {
710-
rng = axRng;
711-
}
712-
}
713-
714-
for(id in group) {
715-
ax = Axes.getFromId(gd, id);
716-
ax.range = Lib.simpleMap(rng, ax.l2r);
717-
ax._input.range = ax.range.slice();
718-
ax.setScale();
719-
}
720-
}
721680
};
722681

723682
// An initial paint must be completed before these components can be

src/plots/cartesian/autorange.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ var Lib = require('../../lib');
1414
var FP_SAFE = require('../../constants/numerical').FP_SAFE;
1515
var Registry = require('../../registry');
1616

17+
var getFromId = require('./axis_ids').getFromId;
18+
1719
module.exports = {
1820
getAutoRange: getAutoRange,
1921
makePadFn: makePadFn,
@@ -213,7 +215,7 @@ function makePadFn(ax) {
213215
return function getPad(pt) { return pt.pad + (pt.extrapad ? extrappad : 0); };
214216
}
215217

216-
function concatExtremes(gd, ax) {
218+
function concatExtremes(gd, ax, noMatch) {
217219
var axId = ax._id;
218220
var fullData = gd._fullData;
219221
var fullLayout = gd._fullLayout;
@@ -242,6 +244,28 @@ function concatExtremes(gd, ax) {
242244
_concat(fullLayout.annotations || [], ax._annIndices || []);
243245
_concat(fullLayout.shapes || [], ax._shapeIndices || []);
244246

247+
// Include the extremes from other matched axes with this one
248+
// TODO: find a way to only do this calculation once, rather than
249+
// repeating it for every axis in the matched group
250+
if(ax._matchGroup && !noMatch) {
251+
for(var axId2 in ax._matchGroup) {
252+
if(axId2 !== ax._id) {
253+
var ax2 = getFromId(gd, axId2);
254+
var extremes2 = concatExtremes(gd, ax2, true);
255+
// convert padding on the second axis to the first with lenRatio
256+
var lenRatio = ax._length / ax2._length;
257+
for(j = 0; j < extremes2.min.length; j++) {
258+
d = extremes2.min[j];
259+
collapseMinArray(minArray, d.val, d.pad * lenRatio, {extrapad: d.extrapad});
260+
}
261+
for(j = 0; j < extremes2.max.length; j++) {
262+
d = extremes2.max[j];
263+
collapseMaxArray(maxArray, d.val, d.pad * lenRatio, {extrapad: d.extrapad});
264+
}
265+
}
266+
}
267+
}
268+
245269
return {min: minArray, max: maxArray};
246270
}
247271

src/plots/cartesian/axis_ids.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,6 @@ exports.idSort = function(id1, id2) {
123123
return +(id1.substr(1) || 1) - +(id2.substr(1) || 1);
124124
};
125125

126-
exports.getAxisGroup = function getAxisGroup(fullLayout, axId) {
127-
var matchGroups = fullLayout._axisMatchGroups;
128-
129-
for(var i = 0; i < matchGroups.length; i++) {
130-
var group = matchGroups[i];
131-
if(group[axId]) return 'g' + i;
132-
}
133-
return axId;
134-
};
135-
136126
/*
137127
* An axis reference (e.g., the contents at the 'xref' key of an object) might
138128
* have extra information appended. Extract the axis ID only.

0 commit comments

Comments
 (0)