Skip to content

Allow fixedrange axes to scaleanchor with constrain:domain #3460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/plots/cartesian/constraint_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ module.exports = function handleConstraintDefaults(containerIn, containerOut, co
var thisID = containerOut._id;
var letter = thisID.charAt(0);

if(containerOut.fixedrange) return;

// coerce the constraint mechanics even if this axis has no scaleanchor
// because it may be the anchor of another axis.
coerce('constrain');
var constrain = coerce('constrain');
Lib.coerce(containerIn, containerOut, {
constraintoward: {
valType: 'enumerated',
Expand All @@ -31,9 +29,9 @@ module.exports = function handleConstraintDefaults(containerIn, containerOut, co
}
}, 'constraintoward');

if(!containerIn.scaleanchor) return;
if(!containerIn.scaleanchor || (constrain === 'range' && containerOut.fixedrange)) return;

var constraintOpts = getConstraintOpts(constraintGroups, thisID, allAxisIds, layoutOut);
var constraintOpts = getConstraintOpts(constraintGroups, thisID, allAxisIds, layoutOut, constrain);

var scaleanchor = Lib.coerce(containerIn, containerOut, {
scaleanchor: {
Expand Down Expand Up @@ -62,12 +60,13 @@ module.exports = function handleConstraintDefaults(containerIn, containerOut, co
}
};

function getConstraintOpts(constraintGroups, thisID, allAxisIds, layoutOut) {
function getConstraintOpts(constraintGroups, thisID, allAxisIds, layoutOut, constrain) {
// If this axis is already part of a constraint group, we can't
// scaleanchor any other axis in that group, or we'd make a loop.
// Filter allAxisIds to enforce this, also matching axis types.

var thisType = layoutOut[id2name(thisID)].type;
var doesConstrainRange = constrain === 'range';

var i, j, idj, axj;

Expand All @@ -77,7 +76,9 @@ function getConstraintOpts(constraintGroups, thisID, allAxisIds, layoutOut) {
if(idj === thisID) continue;

axj = layoutOut[id2name(idj)];
if(axj.type === thisType && !axj.fixedrange) linkableAxes.push(idj);
if(axj.type === thisType && !(doesConstrainRange && axj.fixedrange)) {
linkableAxes.push(idj);
}
}

for(i = 0; i < constraintGroups.length; i++) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions test/image/mocks/axes_scaleanchor-constrain-domain-fixedrange.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"data": [
{
"y": [2, 3, 4, 5, 6],
"x": [2, 3, 4, 5, 6],
"z": [
[0.5, 0.8, 0.6, 0.8, 0.2],
[0.4, 0.3, 0.7, 0.2, 0.1],
[0.7, 0.5, 0.9, 0.5, 0.3],
[0.5, 0.8, 0.6, 0.8, 0.2],
[0.4, 0.3, 0.7, 0.2, 0.1]
],
"type": "heatmap"
}
],
"layout": {
"xaxis": {
"constrain": "domain",
"fixedrange": true
},
"yaxis": {
"constrain": "domain",
"scaleanchor": "x",
"scaleratio": 1,
"fixedrange": true
}
}
}