Skip to content
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
3 changes: 3 additions & 0 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ Plotly.redraw = function(gd) {
throw new Error('This element is not a Plotly plot: ' + gd);
}

helpers.cleanData(gd.data, gd.data);
helpers.cleanLayout(gd.layout);

gd.calcdata = undefined;
return Plotly.plot(gd).then(function() {
gd.emit('plotly_redraw');
Expand Down
38 changes: 38 additions & 0 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var Legend = require('@src/components/legend');
var pkg = require('../../../package.json');
var subroutines = require('@src/plot_api/subroutines');

var d3 = require('d3');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');

Expand Down Expand Up @@ -779,6 +780,43 @@ describe('Test plot api', function() {
});
});

describe('Plotly.redraw', function() {

afterEach(destroyGraphDiv);

it('', function(done) {
var gd = createGraphDiv(),
initialData = [],
layout = { title: 'Redraw' };

Plotly.newPlot(gd, initialData, layout);

var trace1 = {
x: [1, 2, 3, 4],
y: [4, 1, 5, 3],
name: 'First Trace'
};
var trace2 = {
x: [1, 2, 3, 4],
y: [14, 11, 15, 13],
name: 'Second Trace'
};
var trace3 = {
x: [1, 2, 3, 4],
y: [5, 3, 7, 1],
name: 'Third Trace'
};

var newData = [trace1, trace2, trace3];
gd.data = newData;

Plotly.redraw(gd).then(function() {
expect(d3.selectAll('g.trace.scatter').size()).toEqual(3);
})
.then(done);
});
});

describe('cleanData', function() {
var gd;

Expand Down