Skip to content

Commit 1a8e0f5

Browse files
committed
Modify relayout to ignore undefined values
1 parent abf8ec5 commit 1a8e0f5

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/plot_api/plot_api.js

+2
Original file line numberDiff line numberDiff line change
@@ -2187,6 +2187,8 @@ Plotly.relayout = function relayout(gd, astr, val) {
21872187
parentFull = Lib.nestedProperty(fullLayout, ptrunk).get(),
21882188
diff;
21892189

2190+
if(vi === undefined) continue;
2191+
21902192
redoit[ai] = vi;
21912193

21922194
// axis reverse is special - it is its own inverse

test/jasmine/tests/plot_api_test.js

+34
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,40 @@ describe('Test plot api', function() {
4848
})
4949
.then(done);
5050
});
51+
52+
it('sets null values to their default', function(done) {
53+
var defaultWidth;
54+
Plotly.plot(gd, [{ x: [1, 2, 3], y: [1, 2, 3] }])
55+
.then(function() {
56+
defaultWidth = gd._fullLayout.width;
57+
return Plotly.relayout(gd, { width: defaultWidth - 25});
58+
})
59+
.then(function() {
60+
expect(gd._fullLayout.width).toBe(defaultWidth - 25);
61+
return Plotly.relayout(gd, { width: null });
62+
})
63+
.then(function() {
64+
expect(gd._fullLayout.width).toBe(defaultWidth);
65+
})
66+
.then(done);
67+
});
68+
69+
it('ignores undefined values', function(done) {
70+
var defaultWidth;
71+
Plotly.plot(gd, [{ x: [1, 2, 3], y: [1, 2, 3] }])
72+
.then(function() {
73+
defaultWidth = gd._fullLayout.width;
74+
return Plotly.relayout(gd, { width: defaultWidth - 25});
75+
})
76+
.then(function() {
77+
expect(gd._fullLayout.width).toBe(defaultWidth - 25);
78+
return Plotly.relayout(gd, { width: undefined });
79+
})
80+
.then(function() {
81+
expect(gd._fullLayout.width).toBe(defaultWidth - 25);
82+
})
83+
.then(done);
84+
});
5185
});
5286

5387
describe('Plotly.restyle', function() {

0 commit comments

Comments
 (0)