Skip to content

Commit 7e5e5ef

Browse files
committed
Fix and test cheater axis visibility test
1 parent e577ad1 commit 7e5e5ef

File tree

2 files changed

+117
-10
lines changed

2 files changed

+117
-10
lines changed

src/plots/cartesian/layout_defaults.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
3030
xaListGl2d = [],
3131
yaListGl2d = [],
3232
xaListCheater = [],
33+
xaListNonCheater = [],
3334
outerTicks = {},
3435
noGrids = {},
3536
i;
@@ -52,15 +53,18 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
5253
var xaName = axisIds.id2name(trace.xaxis),
5354
yaName = axisIds.id2name(trace.yaxis);
5455

55-
// Note that we track the *opposite* of whether it's a cheater plot
56-
// because that makes it straightforward to check that any trace on
57-
// this axis that's *not* a cheater will make it visible
58-
//
59-
// There are three conditions that cause an axis to get marked as non
60-
// cheater (which is to say, visible by default):
61-
// 1. It's not in the carpet category at all
62-
// 2. Or if it is, then it's not a non-cheater carpet axis
63-
if(Registry.traceIs(trace, 'carpet') && (!trace.type === 'carpet' || trace._cheater)) {
56+
// Two things trigger axis visibility:
57+
// 1. is not carpet
58+
// 2. carpet that's not cheater
59+
if(!Registry.traceIs(trace, 'carpet') || (trace.type === 'carpet' && !trace._cheater)) {
60+
if(xaName) Lib.pushUnique(xaListNonCheater, xaName);
61+
}
62+
63+
// The above check for definitely-not-cheater is not adequate. This
64+
// second list tracks which axes *could* be a cheater so that the
65+
// full condition triggering hiding is:
66+
// *could* be a cheater and *is not definitely visible*
67+
if(trace.type === 'carpet' && trace._cheater) {
6468
if(xaName) Lib.pushUnique(xaListCheater, xaName);
6569
}
6670

@@ -182,7 +186,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
182186
data: fullData,
183187
bgColor: bgColor,
184188
calendar: layoutOut.calendar,
185-
cheateronly: axLetter === 'x' && xaListCheater.indexOf(axName) !== -1
189+
cheateronly: axLetter === 'x' && (xaListCheater.indexOf(axName) !== -1 && xaListNonCheater.indexOf(axName) === -1)
186190
};
187191

188192
handleAxisDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions, layoutOut);

test/jasmine/tests/carpet_test.js

+103
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,109 @@ describe('carpet supplyDefaults', function() {
118118
});*/
119119
});
120120

121+
describe('supplyDefaults visibility check', function() {
122+
it('does not hide empty subplots', function() {
123+
var gd = {data: [], layout: {xaxis: {}}};
124+
Plots.supplyDefaults(gd);
125+
expect(gd._fullLayout.xaxis.visible).toBe(true);
126+
});
127+
128+
it('does not hide axes with non-carpet traces', function() {
129+
var gd = {data: [{x: []}]};
130+
Plots.supplyDefaults(gd);
131+
expect(gd._fullLayout.xaxis.visible).toBe(true);
132+
});
133+
134+
it('does not hide axes with non-cheater carpet', function() {
135+
var gd = {data: [{
136+
type: 'carpet',
137+
a: [1, 2, 3],
138+
b: [1, 2],
139+
x: [[1, 2, 3], [4, 5, 6]],
140+
y: [[1, 2, 3], [4, 5, 6]],
141+
}, {
142+
type: 'contourcarpet',
143+
z: [[1, 2, 3], [4, 5, 6]],
144+
}]};
145+
Plots.supplyDefaults(gd);
146+
expect(gd._fullLayout.xaxis.visible).toBe(true);
147+
});
148+
149+
it('hides axes with cheater', function() {
150+
var gd = {data: [{
151+
type: 'carpet',
152+
a: [1, 2, 3],
153+
b: [1, 2],
154+
y: [[1, 2, 3], [4, 5, 6]],
155+
}, {
156+
type: 'contourcarpet',
157+
z: [[1, 2, 3], [4, 5, 6]],
158+
}]};
159+
Plots.supplyDefaults(gd);
160+
expect(gd._fullLayout.xaxis.visible).toBe(false);
161+
});
162+
163+
it('does not hide an axis with cheater and non-cheater carpet', function() {
164+
var gd = {
165+
data: [{
166+
carpetid: 'c1',
167+
type: 'carpet',
168+
a: [1, 2, 3],
169+
b: [1, 2],
170+
x: [[1, 2, 3], [4, 5, 6]],
171+
y: [[1, 2, 3], [4, 5, 6]],
172+
}, {
173+
carpetid: 'c2',
174+
type: 'carpet',
175+
a: [1, 2, 3],
176+
b: [1, 2],
177+
y: [[1, 2, 3], [4, 5, 6]],
178+
}, {
179+
carpetid: 'c1',
180+
type: 'contourcarpet',
181+
z: [[1, 2, 3], [4, 5, 6]],
182+
}, {
183+
carpetid: 'c2',
184+
type: 'contourcarpet',
185+
z: [[1, 2, 3], [4, 5, 6]],
186+
}]
187+
};
188+
189+
Plots.supplyDefaults(gd);
190+
expect(gd._fullLayout.xaxis.visible).toBe(true);
191+
});
192+
193+
it('does not hide an axis with cheater and non-cheater carpet', function() {
194+
var gd = {
195+
data: [{
196+
carpetid: 'c1',
197+
type: 'carpet',
198+
a: [1, 2, 3],
199+
b: [1, 2],
200+
x: [[1, 2, 3], [4, 5, 6]],
201+
y: [[1, 2, 3], [4, 5, 6]],
202+
}, {
203+
carpetid: 'c2',
204+
type: 'carpet',
205+
a: [1, 2, 3],
206+
b: [1, 2],
207+
y: [[1, 2, 3], [4, 5, 6]],
208+
}, {
209+
carpetid: 'c1',
210+
type: 'contourcarpet',
211+
z: [[1, 2, 3], [4, 5, 6]],
212+
}, {
213+
carpetid: 'c2',
214+
type: 'contourcarpet',
215+
z: [[1, 2, 3], [4, 5, 6]],
216+
}]
217+
};
218+
219+
Plots.supplyDefaults(gd);
220+
expect(gd._fullLayout.xaxis.visible).toBe(true);
221+
});
222+
});
223+
121224
describe('carpet smooth_fill_2d_array', function() {
122225
if(!test.smoothFill2D) return;
123226
var _;

0 commit comments

Comments
 (0)