Skip to content

Extend input relayout & restyle objects before looping over key-vals #1376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion test/jasmine/tests/annotations_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '"]',
Expand All @@ -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() {
Expand All @@ -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);
});
});

Expand Down