File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -473,6 +473,9 @@ Plotly.redraw = function(gd) {
473473 throw new Error ( 'This element is not a Plotly plot: ' + gd ) ;
474474 }
475475
476+ helpers . cleanData ( gd . data , gd . data ) ;
477+ helpers . cleanLayout ( gd . layout ) ;
478+
476479 gd . calcdata = undefined ;
477480 return Plotly . plot ( gd ) . then ( function ( ) {
478481 gd . emit ( 'plotly_redraw' ) ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ var Legend = require('@src/components/legend');
88var pkg = require ( '../../../package.json' ) ;
99var subroutines = require ( '@src/plot_api/subroutines' ) ;
1010
11+ var d3 = require ( 'd3' ) ;
1112var createGraphDiv = require ( '../assets/create_graph_div' ) ;
1213var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
1314
@@ -779,6 +780,43 @@ describe('Test plot api', function() {
779780 } ) ;
780781 } ) ;
781782
783+ describe ( 'Plotly.redraw' , function ( ) {
784+
785+ afterEach ( destroyGraphDiv ) ;
786+
787+ it ( '' , function ( done ) {
788+ var gd = createGraphDiv ( ) ,
789+ initialData = [ ] ,
790+ layout = { title : 'Redraw' } ;
791+
792+ Plotly . newPlot ( gd , initialData , layout ) ;
793+
794+ var trace1 = {
795+ x : [ 1 , 2 , 3 , 4 ] ,
796+ y : [ 4 , 1 , 5 , 3 ] ,
797+ name : 'First Trace'
798+ } ;
799+ var trace2 = {
800+ x : [ 1 , 2 , 3 , 4 ] ,
801+ y : [ 14 , 11 , 15 , 13 ] ,
802+ name : 'Second Trace'
803+ } ;
804+ var trace3 = {
805+ x : [ 1 , 2 , 3 , 4 ] ,
806+ y : [ 5 , 3 , 7 , 1 ] ,
807+ name : 'Third Trace'
808+ } ;
809+
810+ var newData = [ trace1 , trace2 , trace3 ] ;
811+ gd . data = newData ;
812+
813+ Plotly . redraw ( gd ) . then ( function ( ) {
814+ expect ( d3 . selectAll ( 'g.trace.scatter' ) . size ( ) ) . toEqual ( 3 ) ;
815+ } )
816+ . then ( done ) ;
817+ } ) ;
818+ } ) ;
819+
782820 describe ( 'cleanData' , function ( ) {
783821 var gd ;
784822
You can’t perform that action at this time.
0 commit comments