Skip to content

Commit b5bfee1

Browse files
committed
shapes: add 'visible' attribute
1 parent 7f40318 commit b5bfee1

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

src/components/shapes/attributes.js

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ var scatterLineAttrs = scatterAttrs.line;
1717
module.exports = {
1818
_isLinkedToArray: true,
1919

20+
visible: {
21+
valType: 'boolean',
22+
role: 'info',
23+
dflt: true,
24+
description: [
25+
'Determines whether or not this shape is visible.'
26+
].join(' ')
27+
},
28+
2029
type: {
2130
valType: 'enumerated',
2231
values: ['circle', 'rect', 'path', 'line'],

src/components/shapes/calc_autorange.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
'use strict';
1111

12+
var Lib = require('../../lib');
1213
var Axes = require('../../plots/cartesian/axes');
1314

1415
var constants = require('./constants');
@@ -17,7 +18,7 @@ var helpers = require('./helpers');
1718

1819
module.exports = function calcAutorange(gd) {
1920
var fullLayout = gd._fullLayout,
20-
shapeList = fullLayout.shapes;
21+
shapeList = Lib.filterVisible(fullLayout.shapes);
2122

2223
if(!shapeList.length || !gd._fullData.length) return;
2324

src/components/shapes/draw.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ function draw(gd) {
4949
fullLayout._shapeSubplotLayer.selectAll('path').remove();
5050

5151
for(var i = 0; i < fullLayout.shapes.length; i++) {
52-
drawOne(gd, i);
52+
if(fullLayout.shapes[i].visible) {
53+
drawOne(gd, i);
54+
}
5355
}
5456

5557
// may need to resurrect this if we put text (LaTeX) in shapes
@@ -169,8 +171,6 @@ function updateShape(gd, index, opt, value) {
169171
// TODO: clean this up and remove it.
170172
if(!optionsIn) return;
171173

172-
var oldRef = {xref: optionsIn.xref, yref: optionsIn.yref};
173-
174174
// alter the input shape as requested
175175
var optionsEdit = {};
176176
if(typeof opt === 'string' && opt) optionsEdit[opt] = value;
@@ -182,7 +182,12 @@ function updateShape(gd, index, opt, value) {
182182
Lib.nestedProperty(optionsIn, k).set(optionsEdit[k]);
183183
}
184184

185-
var posAttrs = ['x0', 'x1', 'y0', 'y1'];
185+
// return early in visible: false updates
186+
if(optionsIn.visible === false) return;
187+
188+
var oldRef = {xref: optionsIn.xref, yref: optionsIn.yref},
189+
posAttrs = ['x0', 'x1', 'y0', 'y1'];
190+
186191
for(i = 0; i < 4; i++) {
187192
var posAttr = posAttrs[i];
188193
// if we don't have an explicit position already,

src/components/shapes/shape_defaults.js

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ module.exports = function handleShapeDefaults(shapeIn, fullLayout) {
2222
return Lib.coerce(shapeIn, shapeOut, attributes, attr, dflt);
2323
}
2424

25+
var visible = coerce('visible');
26+
27+
if(!visible) return shapeOut;
28+
2529
coerce('layer');
2630
coerce('opacity');
2731
coerce('fillcolor');

test/image/mocks/shapes_below_traces.json

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"y1": 1,
9292
"yref": "paper"
9393
},
94+
{ "visible": false },
9495
{
9596
"fillcolor": "#f6e8c3",
9697
"layer": "below",

test/jasmine/tests/shapes_test.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,23 @@ describe('Test shapes:', function() {
183183
expect(countShapePathsInUpperLayer()).toEqual(pathCount + 1);
184184
expect(getLastShape(gd)).toEqual(shape);
185185
expect(countShapes(gd)).toEqual(index + 1);
186-
})
187-
.then(function() {
186+
188187
return Plotly.relayout(gd, 'shapes[' + index + ']', 'remove');
189188
})
190189
.then(function() {
191190
expect(countShapePathsInUpperLayer()).toEqual(pathCount);
192191
expect(countShapes(gd)).toEqual(index);
193192

194-
return Plotly.relayout(gd, 'shapes[' + 1 + ']', null);
193+
return Plotly.relayout(gd, 'shapes[' + 2 + '].visible', false);
195194
})
196195
.then(function() {
197196
expect(countShapePathsInUpperLayer()).toEqual(pathCount - 1);
197+
expect(countShapes(gd)).toEqual(index);
198+
199+
return Plotly.relayout(gd, 'shapes[' + 1 + ']', null);
200+
})
201+
.then(function() {
202+
expect(countShapePathsInUpperLayer()).toEqual(pathCount - 2);
198203
expect(countShapes(gd)).toEqual(index - 1);
199204
})
200205
.then(done);

0 commit comments

Comments
 (0)