Skip to content

Commit 8ef17c3

Browse files
committed
image: apply layout defaults if an image is present at all
1 parent 6ad80ab commit 8ef17c3

File tree

5 files changed

+21
-31
lines changed

5 files changed

+21
-31
lines changed

Diff for: src/plots/cartesian/layout_defaults.js

+10-20
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
4141
var yaMustDisplay = {};
4242
var yaMustNotReverse = {};
4343
var yaMayReverse = {};
44-
var yaMustNotScaleanchor = {};
45-
var yaMayScaleanchor = {};
46-
var yaMustNotConstrainDomain = {};
47-
var yaMayConstrainDomain = {};
44+
var axHasImage = {};
4845
var outerTicks = {};
4946
var noGrids = {};
5047
var i, j;
@@ -82,20 +79,13 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
8279
} else {
8380
if(yaName) yaMayHide[yaName] = true;
8481
}
85-
yaMustNotScaleanchor[yaName] = true;
86-
yaMustNotConstrainDomain[yaName] = true;
8782
} else if(trace.type === 'image') {
88-
if(yaName) {
89-
yaMayReverse[yaName] = true;
90-
yaMayScaleanchor[yaName] = true;
91-
yaMayConstrainDomain[yaName] = true;
92-
}
83+
if(yaName) axHasImage[yaName] = true;
84+
if(xaName) axHasImage[xaName] = true;
9385
} else {
9486
if(yaName) {
9587
yaMustDisplay[yaName] = true;
9688
yaMustNotReverse[yaName] = true;
97-
yaMustNotScaleanchor[yaName] = true;
98-
yaMustNotConstrainDomain[yaName] = true;
9989
}
10090

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

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

211205
var defaultOptions = {
212206
letter: axLetter,
@@ -309,16 +303,12 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
309303
axLayoutOut = layoutOut[axName];
310304

311305
var scaleanchorDflt = null;
312-
if(axLetter === 'y' && !axLayoutIn.hasOwnProperty('scaleanchor') &&
313-
!yaMustNotScaleanchor[axName] && yaMayScaleanchor[axName]
314-
) {
306+
if(axLetter === 'y' && !axLayoutIn.hasOwnProperty('scaleanchor') && axHasImage[axName]) {
315307
scaleanchorDflt = axLayoutOut.anchor;
316308
}
317309

318310
var constrainDflt = null;
319-
if(axLetter === 'y' && !axLayoutIn.hasOwnProperty('constrain') &&
320-
!yaMustNotConstrainDomain[axName] && yaMayConstrainDomain[axName]
321-
) {
311+
if(!axLayoutIn.hasOwnProperty('constrain') && axHasImage[axName]) {
322312
constrainDflt = 'domain';
323313
}
324314
handleConstraintDefaults(axLayoutIn, axLayoutOut, coerce, {

Diff for: src/traces/image/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ 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\,`)',
31-
'in order for pixels to be rendered as squares and',
32-
'the y axis is constrained to the domain (ie. `constrain: \'domain\'`).'
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\,`)',
32+
'in order for pixels to be rendered as squares.'
3333
].join(' ')
3434
}
3535
};

Diff for: test/image/baselines/image_axis_type.png

-1.93 KB
Loading

Diff for: test/image/baselines/image_with_heatmap.png

-117 Bytes
Loading

Diff for: test/jasmine/tests/image_test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ describe('image smart layout defaults', function() {
116116
expect(gd._fullLayout.yaxis.autorange).toBe('reversed');
117117
});
118118

119-
it('should NOT reverse yaxis if another trace is present', function() {
119+
it('should reverse yaxis even if another trace is present', function() {
120120
gd = {};
121121
gd.data = [{type: 'image', z: [[[255, 0, 0]]]}, {type: 'scatter', y: [5, 3, 2]}];
122122
supplyAllDefaults(gd);
123-
expect(gd._fullLayout.yaxis.autorange).not.toBe('reversed');
123+
expect(gd._fullLayout.yaxis.autorange).toBe('reversed');
124124
});
125125

126126
it('should NOT reverse yaxis if it\'s already defined', function() {
@@ -138,11 +138,11 @@ describe('image smart layout defaults', function() {
138138
expect(gd._fullLayout.yaxis.scaleanchor).toBe('x');
139139
});
140140

141-
it('should NOT set scaleanchor if another trace is present', function() {
141+
it('should set scaleanchor even if another trace is present', function() {
142142
gd = {};
143143
gd.data = [{type: 'image', z: [[[255, 0, 0]]]}, {type: 'scatter', y: [5, 3, 2]}];
144144
supplyAllDefaults(gd);
145-
expect(gd._fullLayout.yaxis.scaleanchor).toBe(undefined);
145+
expect(gd._fullLayout.yaxis.scaleanchor).toBe('x');
146146
});
147147

148148
it('should NOT set scaleanchor if it\'s already defined', function() {
@@ -159,11 +159,11 @@ describe('image smart layout defaults', function() {
159159
expect(gd._fullLayout.yaxis.constrain).toBe('domain');
160160
});
161161

162-
it('should NOT constrain axes to domain if another trace is present', function() {
162+
it('should constrain axes to domain even if another trace is present', function() {
163163
gd = {};
164164
gd.data = [{type: 'image', z: [[[255, 0, 0]]]}, {type: 'scatter', y: [5, 3, 2]}];
165165
supplyAllDefaults(gd);
166-
expect(gd._fullLayout.yaxis.constrain).toBe(undefined);
166+
expect(gd._fullLayout.yaxis.constrain).toBe('domain');
167167
});
168168

169169
it('should NOT constrain axes to domain if it\'s already defined', function() {

0 commit comments

Comments
 (0)