diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 55c98d78910..8f6e6803d3b 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -1183,7 +1183,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) { if(typeof astr === 'string') aobj[astr] = val; else if(Lib.isPlainObject(astr)) { // the 3-arg form - aobj = astr; + aobj = Lib.extendFlat({}, astr); if(traces === undefined) traces = val; } else { @@ -1702,7 +1702,7 @@ Plotly.relayout = function relayout(gd, astr, val) { if(typeof astr === 'string') { aobj[astr] = val; } else if(Lib.isPlainObject(astr)) { - aobj = astr; + aobj = Lib.extendFlat({}, astr); } else { Lib.warn('Relayout fail.', astr, val); return Promise.reject(); @@ -2092,10 +2092,10 @@ Plotly.update = function update(gd, traceUpdate, layoutUpdate, traces) { if(Object.keys(traceUpdate).length) gd.changed = true; if(Object.keys(layoutUpdate).length) gd.changed = true; - var restyleSpecs = _restyle(gd, traceUpdate, traces), + var restyleSpecs = _restyle(gd, Lib.extendFlat({}, traceUpdate), traces), restyleFlags = restyleSpecs.flags; - var relayoutSpecs = _relayout(gd, layoutUpdate), + var relayoutSpecs = _relayout(gd, Lib.extendFlat({}, layoutUpdate)), relayoutFlags = relayoutSpecs.flags; // clear calcdata if required diff --git a/test/jasmine/tests/annotations_test.js b/test/jasmine/tests/annotations_test.js index 880f273ed70..ee155f9cf0d 100644 --- a/test/jasmine/tests/annotations_test.js +++ b/test/jasmine/tests/annotations_test.js @@ -185,6 +185,7 @@ describe('annotations relayout', function() { }); it('should be able update annotations', function(done) { + var updateObj = { 'annotations[0].text': 'hello' }; function assertText(index, expected) { var query = '.annotation[data-index="' + index + '"]', @@ -193,6 +194,12 @@ describe('annotations relayout', function() { expect(actual).toEqual(expected); } + function assertUpdateObj() { + // w/o mutating relayout update object + expect(Object.keys(updateObj)).toEqual(['annotations[0].text']); + expect(updateObj['annotations[0].text']).toEqual('hello'); + } + assertText(0, 'left top'); Plotly.relayout(gd, 'annotations[0].text', 'hello').then(function() { @@ -202,9 +209,25 @@ describe('annotations relayout', function() { }) .then(function() { assertText(0, 'new text'); + + return Plotly.relayout(gd, updateObj); }) - .then(done); + .then(function() { + assertText(0, 'hello'); + assertUpdateObj(); + + return Plotly.relayout(gd, 'annotations[0].text', null); + }) + .then(function() { + assertText(0, 'new text'); + return Plotly.update(gd, {}, updateObj); + }) + .then(function() { + assertText(0, 'hello'); + assertUpdateObj(); + }) + .then(done); }); });