Skip to content

Fix Plotly.update for full data + layout replot #971

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
Sep 22, 2016
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
10 changes: 8 additions & 2 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2062,9 +2062,15 @@ Plotly.update = function update(gd, traceUpdate, layoutUpdate, traces) {
var seq = [];

if(restyleFlags.fullReplot && relayoutFlags.layoutReplot) {
var layout = gd.layout;
var data = gd.data,
layout = gd.layout;

// clear existing data/layout on gd
// so that Plotly.plot doesn't try to extend them
gd.data = undefined;
gd.layout = undefined;
seq.push(function() { return Plotly.plot(gd, gd.data, layout); });

seq.push(function() { return Plotly.plot(gd, data, layout); });
}
else if(restyleFlags.fullReplot) {
seq.push(Plotly.plot);
Expand Down
26 changes: 25 additions & 1 deletion test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ describe('Test plot api', function() {
});

describe('Plotly.update should', function() {
var gd, calcdata;
var gd, data, layout, calcdata;

beforeAll(function() {
Object.keys(subroutines).forEach(function(k) {
Expand All @@ -945,6 +945,8 @@ describe('Test plot api', function() {
beforeEach(function(done) {
gd = createGraphDiv();
Plotly.plot(gd, [{ y: [2, 1, 2] }]).then(function() {
data = gd.data;
layout = gd.layout;
calcdata = gd.calcdata;
done();
});
Expand All @@ -964,11 +966,33 @@ describe('Test plot api', function() {

it('clear calcdata on data updates', function(done) {
Plotly.update(gd, { x: [[3, 1, 3]] }).then(function() {
expect(data).toBe(gd.data);
expect(layout).toBe(gd.layout);
expect(calcdata).not.toBe(gd.calcdata);
done();
});
});

it('clear calcdata on data + axis updates w/o extending current gd.data', function(done) {
var traceUpdate = {
x: [[3, 1, 3]]
};

var layoutUpdate = {
xaxis: {title: 'A', type: '-'}
};

Plotly.update(gd, traceUpdate, layoutUpdate).then(function() {
expect(data).toBe(gd.data);
expect(layout).toBe(gd.layout);
expect(calcdata).not.toBe(gd.calcdata);

expect(gd.data.length).toEqual(1);

done();
});
});

it('call doLegend on legend updates', function(done) {
expect(subroutines.doLegend).not.toHaveBeenCalled();

Expand Down