Skip to content

Commit a0e6a5c

Browse files
committed
Fix bug that prevented update of shape properties
* Added test that updates the layer property of a shape.
1 parent 7d85bfe commit a0e6a5c

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/components/shapes/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ function updateShape(gd, index, opt, value) {
238238
else if(Lib.isPlainObject(opt)) optionsEdit = opt;
239239

240240
var optionKeys = Object.keys(optionsEdit);
241-
for(i = 0; i < optionsEdit.length; i++) {
241+
for(i = 0; i < optionKeys.length; i++) {
242242
var k = optionKeys[i];
243243
Lib.nestedProperty(optionsIn, k).set(optionsEdit[k]);
244244
}

test/jasmine/tests/shapes_test.js

+40
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,45 @@ describe('Test shapes:', function() {
186186
expect(countShapes(gd)).toEqual(index);
187187
}).then(done);
188188
});
189+
190+
it('should be able to update a shape layer', function(done) {
191+
var index = countShapes(gd),
192+
astr = 'shapes[' + index + ']',
193+
shape = getRandomShape(),
194+
shapesInLowerLayer = countShapePathsInLowerLayer(),
195+
shapesInUpperLayer = countShapePathsInUpperLayer();
196+
197+
shape.xref = 'paper';
198+
shape.yref = 'paper';
199+
200+
Plotly.relayout(gd, astr, shape).then(function() {
201+
expect(countShapePathsInLowerLayer())
202+
.toEqual(shapesInLowerLayer);
203+
expect(countShapePathsInUpperLayer())
204+
.toEqual(shapesInUpperLayer + 1);
205+
expect(getLastShape(gd)).toEqual(shape);
206+
expect(countShapes(gd)).toEqual(index + 1);
207+
}).then(function() {
208+
shape.layer = 'below';
209+
Plotly.relayout(gd, astr + '.layer', shape.layer);
210+
}).then(function() {
211+
expect(countShapePathsInLowerLayer())
212+
.toEqual(shapesInLowerLayer + 1);
213+
expect(countShapePathsInUpperLayer())
214+
.toEqual(shapesInUpperLayer);
215+
expect(getLastShape(gd)).toEqual(shape);
216+
expect(countShapes(gd)).toEqual(index + 1);
217+
}).then(function() {
218+
shape.layer = 'above';
219+
Plotly.relayout(gd, astr + '.layer', shape.layer);
220+
}).then(function() {
221+
expect(countShapePathsInLowerLayer())
222+
.toEqual(shapesInLowerLayer);
223+
expect(countShapePathsInUpperLayer())
224+
.toEqual(shapesInUpperLayer + 1);
225+
expect(getLastShape(gd)).toEqual(shape);
226+
expect(countShapes(gd)).toEqual(index + 1);
227+
}).then(done);
228+
});
189229
});
190230
});

0 commit comments

Comments
 (0)