Skip to content

Commit 5a0b788

Browse files
committed
Add axis cartesian axis visibility option
1 parent eee837f commit 5a0b788

File tree

6 files changed

+36
-1
lines changed

6 files changed

+36
-1
lines changed

src/plots/cartesian/axes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,8 @@ axes.doTicks = function(gd, axid, skipTitle) {
16651665
ticksign = ticksign.map(function(v) { return -v; });
16661666
}
16671667

1668+
if(!ax.visible) return;
1669+
16681670
// remove zero lines, grid lines, and inside ticks if they're within
16691671
// 1 pixel of the end
16701672
// The key case here is removing zero lines when the axis bound is zero.

src/plots/cartesian/axis_defaults.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
4747
return Lib.coerce2(containerIn, containerOut, layoutAttributes, attr, dflt);
4848
}
4949

50+
coerce('visible', !options.cheateronly);
51+
5052
var axType = containerOut.type;
5153

5254
if(axType === 'date') {

src/plots/cartesian/layout_attributes.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ var constants = require('./constants');
1616

1717

1818
module.exports = {
19+
visible: {
20+
valType: 'boolean',
21+
role: 'info',
22+
description: [
23+
'A single toggle to hide the axis while preserving interaction like dragging.',
24+
'Default is true when a cheater plot is present on the axis, otherwise',
25+
'false'
26+
].join(' ')
27+
},
1928
color: {
2029
valType: 'color',
2130
dflt: colorAttrs.defaultLine,

src/plots/cartesian/layout_defaults.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
2929
yaListCartesian = [],
3030
xaListGl2d = [],
3131
yaListGl2d = [],
32+
xaListCheater = [],
33+
xaListNonCheater = [],
3234
outerTicks = {},
3335
noGrids = {},
3436
i;
@@ -51,6 +53,21 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
5153
var xaName = axisIds.id2name(trace.xaxis),
5254
yaName = axisIds.id2name(trace.yaxis);
5355

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) {
68+
if(xaName) Lib.pushUnique(xaListCheater, xaName);
69+
}
70+
5471
// add axes implied by traces
5572
if(xaName && listX.indexOf(xaName) === -1) listX.push(xaName);
5673
if(yaName && listY.indexOf(yaName) === -1) listY.push(yaName);
@@ -168,7 +185,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
168185
showGrid: !noGrids[axName],
169186
data: fullData,
170187
bgColor: bgColor,
171-
calendar: layoutOut.calendar
188+
calendar: layoutOut.calendar,
189+
cheateronly: axLetter === 'x' && (xaListCheater.indexOf(axName) !== -1 && xaListNonCheater.indexOf(axName) === -1)
172190
};
173191

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

src/plots/gl3d/layout/axis_attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var extendFlat = require('../../../lib/extend').extendFlat;
1414

1515

1616
module.exports = {
17+
visible: axesAttrs.visible,
1718
showspikes: {
1819
valType: 'boolean',
1920
role: 'info',

src/plots/ternary/ternary.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
200200
// fictitious angles and domain, but then rotate and translate
201201
// it into place at the end
202202
var aaxis = _this.aaxis = extendFlat({}, ternaryLayout.aaxis, {
203+
visible: true,
203204
range: [amin, sum - bmin - cmin],
204205
side: 'left',
205206
_counterangle: 30,
@@ -220,6 +221,7 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
220221
// baxis goes across the bottom (backward). We can set it up as an x axis
221222
// without any enclosing transformation.
222223
var baxis = _this.baxis = extendFlat({}, ternaryLayout.baxis, {
224+
visible: true,
223225
range: [sum - amin - cmin, bmin],
224226
side: 'bottom',
225227
_counterangle: 30,
@@ -239,6 +241,7 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
239241
// caxis goes down the right side. Set it up as a y axis, with
240242
// post-transformation similar to aaxis
241243
var caxis = _this.caxis = extendFlat({}, ternaryLayout.caxis, {
244+
visible: true,
242245
range: [sum - amin - bmin, cmin],
243246
side: 'right',
244247
_counterangle: 30,

0 commit comments

Comments
 (0)