From 35e4d322c6e92a222e48bd50f6a0c6ec81be54ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Thu, 15 Sep 2016 18:22:40 -0400 Subject: [PATCH 1/2] plot_api: make Plotly.redraw go through a round of clean data/layout - to bring it on-par with Plotly.plot - fixes #942 by properly supplying uid to new traces which are now required by the Scatter.plot method. --- src/plot_api/plot_api.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 1b627b49bc1..c50189988e9 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -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'); From 1e6616c8bfaca8ee5d29f38f39cdbcd2299c05dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Thu, 15 Sep 2016 18:22:58 -0400 Subject: [PATCH 2/2] test: add (first) Plotly.redraw test (!!!) --- test/jasmine/tests/plot_api_test.js | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/jasmine/tests/plot_api_test.js b/test/jasmine/tests/plot_api_test.js index b5cde2401f7..748ec779278 100644 --- a/test/jasmine/tests/plot_api_test.js +++ b/test/jasmine/tests/plot_api_test.js @@ -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'); @@ -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;