@@ -70,6 +70,9 @@ var FigureModel = widgets.DOMWidgetModel.extend({
7070 * @typedef {null|Object } Py2JsDeleteTracesMsg
7171 * @property {Array.<Number> } delete_inds
7272 * Array of indexes of traces to be deleted, in ascending order
73+ * @property {Number } trace_edit_id
74+ * Edit ID to use when returning trace deltas using
75+ * the _js2py_traceDeltas message.
7376 * @property {Number } layout_edit_id
7477 * Edit ID to use when returning layout deltas using
7578 * the _js2py_layoutDelta message.
@@ -738,16 +741,10 @@ var FigureView = widgets.DOMWidgetView.extend({
738741 this . model . on ( "change:_py2js_svgRequest" ,
739742 this . do_svgRequest , this ) ;
740743
741- // Increment message ids
744+ // Get message ids
742745 // ---------------------
743- // Creating a view is, itself, a layout and trace edit operation
744- // because the creation of the view will result in trace and layout
745- // delta messages being sent back to the Python side.
746- var layout_edit_id = this . model . get ( "_last_layout_edit_id" ) + 1 ;
747- this . model . set ( "_last_layout_edit_id" , layout_edit_id ) ;
748- var trace_edit_id = this . model . get ( "_last_trace_edit_id" ) + 1 ;
749- this . model . set ( "_last_trace_edit_id" , trace_edit_id ) ;
750- this . touch ( ) ;
746+ var layout_edit_id = this . model . get ( "_last_layout_edit_id" ) ;
747+ var trace_edit_id = this . model . get ( "_last_trace_edit_id" ) ;
751748
752749 // Set view UID
753750 // ------------
@@ -768,10 +765,9 @@ var FigureView = widgets.DOMWidgetView.extend({
768765 Plotly . newPlot ( this . el , initialTraces , initialLayout ) . then (
769766 function ( ) {
770767 // ### Send trace deltas ###
771- // We create an array of deltas corresponding to the animated
768+ // We create an array of deltas corresponding to the new
772769 // traces.
773- var traceIndexes = _ . range ( initialTraces . length ) ;
774- that . _sendTraceDeltas ( traceIndexes , trace_edit_id ) ;
770+ that . _sendTraceDeltas ( trace_edit_id ) ;
775771
776772 // ### Send layout delta ###
777773 that . _sendLayoutDelta ( layout_edit_id ) ;
@@ -1135,14 +1131,7 @@ var FigureView = widgets.DOMWidgetView.extend({
11351131 Plotly . addTraces ( this . el , msgData . trace_data ) . then ( function ( ) {
11361132
11371133 // ### Send trace deltas ###
1138- // We create an array of deltas corresponding to the new
1139- // traces.
1140- var newTraceIndexes = msgData . trace_data . map ( function ( v , i ) {
1141- return i + prevNumTraces
1142- } ) ;
1143-
1144- that . _sendTraceDeltas ( newTraceIndexes , msgData . trace_edit_id ) ;
1145-
1134+ that . _sendTraceDeltas ( msgData . trace_edit_id ) ;
11461135
11471136 // ### Send layout delta ###
11481137 var layout_edit_id = msgData . layout_edit_id ;
@@ -1159,12 +1148,16 @@ var FigureView = widgets.DOMWidgetView.extend({
11591148 /** @type {Py2JsDeleteTracesMsg } */
11601149 var msgData = this . model . get ( "_py2js_deleteTraces" ) ;
11611150
1162- console . log ( "do_deleteTraces" ) ;
1151+ console . log ( [ "do_deleteTraces" , msgData ] ) ;
11631152 if ( msgData !== null ) {
11641153 var delete_inds = msgData . delete_inds ;
11651154 var that = this ;
11661155 Plotly . deleteTraces ( this . el , delete_inds ) . then ( function ( ) {
11671156
1157+ // ### Send trace deltas ###
1158+ var trace_edit_id = msgData . trace_edit_id ;
1159+ that . _sendTraceDeltas ( trace_edit_id ) ;
1160+
11681161 // ### Send layout delta ###
11691162 var layout_edit_id = msgData . layout_edit_id ;
11701163 that . _sendLayoutDelta ( layout_edit_id ) ;
@@ -1224,7 +1217,7 @@ var FigureView = widgets.DOMWidgetView.extend({
12241217 // ### Send trace deltas ###
12251218 // We create an array of deltas corresponding to the restyled
12261219 // traces.
1227- this . _sendTraceDeltas ( traceIndexes , msgData . trace_edit_id ) ;
1220+ this . _sendTraceDeltas ( msgData . trace_edit_id ) ;
12281221
12291222 // ### Send layout delta ###
12301223 var layout_edit_id = msgData . layout_edit_id ;
@@ -1287,7 +1280,7 @@ var FigureView = widgets.DOMWidgetView.extend({
12871280 // ### Send trace deltas ###
12881281 // We create an array of deltas corresponding to the updated
12891282 // traces.
1290- this . _sendTraceDeltas ( traceIndexes , msgData . trace_edit_id ) ;
1283+ this . _sendTraceDeltas ( msgData . trace_edit_id ) ;
12911284
12921285 // ### Send layout delta ###
12931286 var layout_edit_id = msgData . layout_edit_id ;
@@ -1328,7 +1321,7 @@ var FigureView = widgets.DOMWidgetView.extend({
13281321 // ### Send trace deltas ###
13291322 // We create an array of deltas corresponding to the
13301323 // animated traces.
1331- this . _sendTraceDeltas ( traceIndexes , msgData . trace_edit_id ) ;
1324+ this . _sendTraceDeltas ( msgData . trace_edit_id ) ;
13321325
13331326 // ### Send layout delta ###
13341327 var layout_edit_id = msgData . layout_edit_id ;
@@ -1346,7 +1339,7 @@ var FigureView = widgets.DOMWidgetView.extend({
13461339 // ### Send trace deltas ###
13471340 // We create an array of deltas corresponding to the
13481341 // animated traces.
1349- that . _sendTraceDeltas ( traceIndexes , msgData . trace_edit_id ) ;
1342+ that . _sendTraceDeltas ( msgData . trace_edit_id ) ;
13501343
13511344 // ### Send layout delta ###
13521345 var layout_edit_id = msgData . layout_edit_id ;
@@ -1406,16 +1399,17 @@ var FigureView = widgets.DOMWidgetView.extend({
14061399 /**
14071400 * Construct trace deltas array for the requested trace indexes and
14081401 * send traceDeltas message to the Python side
1409- * @param {Array.<Number> } traceIndexes
14101402 * Array of indexes of traces for which to compute deltas
14111403 * @param trace_edit_id
14121404 * Edit ID of message that triggered the creation of trace deltas
14131405 * @private
14141406 */
1415- _sendTraceDeltas : function ( traceIndexes , trace_edit_id ) {
1407+ _sendTraceDeltas : function ( trace_edit_id ) {
14161408
1417- var trace_deltas = new Array ( traceIndexes . length ) ;
14181409 var trace_data = this . model . get ( "_data" ) ;
1410+ var traceIndexes = _ . range ( trace_data . length ) ;
1411+ var trace_deltas = new Array ( traceIndexes . length ) ;
1412+
14191413 var fullData = this . getFullData ( ) ;
14201414 for ( var i = 0 ; i < traceIndexes . length ; i ++ ) {
14211415 var traceInd = traceIndexes [ i ] ;
0 commit comments