Skip to content

Commit 4233619

Browse files
authored
Merge pull request #4313 from plotly/image-constrain
image: constrain axes to domain, apply defaults whenever an image is present
2 parents 2b0d3c3 + 29cf98f commit 4233619

File tree

13 files changed

+65
-26
lines changed

13 files changed

+65
-26
lines changed

src/plots/cartesian/constraints.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ exports.handleConstraintDefaults = function(containerIn, containerOut, coerce, o
2121
var allAxisIds = opts.allAxisIds;
2222
var layoutOut = opts.layoutOut;
2323
var scaleanchorDflt = opts.scaleanchorDflt;
24+
var constrainDflt = opts.constrainDflt;
2425
var constraintGroups = layoutOut._axisConstraintGroups;
2526
var matchGroups = layoutOut._axisMatchGroups;
2627
var axId = containerOut._id;
@@ -31,7 +32,7 @@ exports.handleConstraintDefaults = function(containerIn, containerOut, coerce, o
3132

3233
// coerce the constraint mechanics even if this axis has no scaleanchor
3334
// because it may be the anchor of another axis.
34-
var constrain = coerce('constrain');
35+
var constrain = coerce('constrain', constrainDflt);
3536
Lib.coerce(containerIn, containerOut, {
3637
constraintoward: {
3738
valType: 'enumerated',

src/plots/cartesian/layout_defaults.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
4141
var yaMustDisplay = {};
4242
var yaMustNotReverse = {};
4343
var yaMayReverse = {};
44-
var yaMustNotScaleanchor = {};
45-
var yaMayScaleanchor = {};
44+
var axHasImage = {};
4645
var outerTicks = {};
4746
var noGrids = {};
4847
var i, j;
@@ -80,17 +79,13 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
8079
} else {
8180
if(yaName) yaMayHide[yaName] = true;
8281
}
83-
yaMustNotScaleanchor[yaName] = true;
8482
} else if(trace.type === 'image') {
85-
if(yaName) {
86-
yaMayReverse[yaName] = true;
87-
yaMayScaleanchor[yaName] = true;
88-
}
83+
if(yaName) axHasImage[yaName] = true;
84+
if(xaName) axHasImage[xaName] = true;
8985
} else {
9086
if(yaName) {
9187
yaMustDisplay[yaName] = true;
9288
yaMustNotReverse[yaName] = true;
93-
yaMustNotScaleanchor[yaName] = true;
9489
}
9590

9691
if(!traceIs(trace, 'carpet') || (trace.type === 'carpet' && !trace._cheater)) {
@@ -201,7 +196,11 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
201196
(axLetter === 'y' && !yaMustDisplay[axName] && yaMayHide[axName]);
202197

203198
var reverseDflt =
204-
(axLetter === 'y' && !yaMustNotReverse[axName] && yaMayReverse[axName]);
199+
(axLetter === 'y' &&
200+
(
201+
(!yaMustNotReverse[axName] && yaMayReverse[axName]) ||
202+
axHasImage[axName]
203+
));
205204

206205
var defaultOptions = {
207206
letter: axLetter,
@@ -303,16 +302,21 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
303302
axLayoutIn = layoutIn[axName];
304303
axLayoutOut = layoutOut[axName];
305304

306-
var scaleanchorDflt = null;
307-
if(axLetter === 'y' && !axLayoutIn.hasOwnProperty('scaleanchor') &&
308-
!yaMustNotScaleanchor[axName] && yaMayScaleanchor[axName]
309-
) {
305+
var scaleanchorDflt;
306+
if(axLetter === 'y' && !axLayoutIn.hasOwnProperty('scaleanchor') && axHasImage[axName]) {
310307
scaleanchorDflt = axLayoutOut.anchor;
311-
}
308+
} else {scaleanchorDflt = undefined;}
309+
310+
var constrainDflt;
311+
if(!axLayoutIn.hasOwnProperty('constrain') && axHasImage[axName]) {
312+
constrainDflt = 'domain';
313+
} else {constrainDflt = undefined;}
314+
312315
handleConstraintDefaults(axLayoutIn, axLayoutOut, coerce, {
313316
allAxisIds: allAxisIds,
314317
layoutOut: layoutOut,
315-
scaleanchorDflt: scaleanchorDflt
318+
scaleanchorDflt: scaleanchorDflt,
319+
constrainDflt: constrainDflt
316320
});
317321
}
318322

src/traces/image/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ module.exports = {
2525
meta: {
2626
description: [
2727
'Display an image, i.e. data on a 2D regular raster.',
28-
'If only images are displayed in a subplot,',
29-
'the y axis will be reversed (ie. `autorange: \'reversed\'`)',
30-
'and it will have the same scale as the x axis (ie. `scaleanchor: \'x\,`)',
28+
'By default, when an image is displayed in a subplot,',
29+
'its y axis will be reversed (ie. `autorange: \'reversed\'`),',
30+
'constrained to the domain (ie. `constrain: \'domain\'`)',
31+
'and it will have the same scale as its x axis (ie. `scaleanchor: \'x\,`)',
3132
'in order for pixels to be rendered as squares.'
3233
].join(' ')
3334
}
-2.97 KB
Loading
-2.24 KB
Loading

test/image/baselines/image_cat.png

2 Bytes
Loading
-700 Bytes
Loading
-1.33 KB
Loading
-156 Bytes
Loading
-117 Bytes
Loading

0 commit comments

Comments
 (0)