@@ -70,6 +70,9 @@ var FigureModel = widgets.DOMWidgetModel.extend({
70
70
* @typedef {null|Object } Py2JsDeleteTracesMsg
71
71
* @property {Array.<Number> } delete_inds
72
72
* 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.
73
76
* @property {Number } layout_edit_id
74
77
* Edit ID to use when returning layout deltas using
75
78
* the _js2py_layoutDelta message.
@@ -738,16 +741,10 @@ var FigureView = widgets.DOMWidgetView.extend({
738
741
this . model . on ( "change:_py2js_svgRequest" ,
739
742
this . do_svgRequest , this ) ;
740
743
741
- // Increment message ids
744
+ // Get message ids
742
745
// ---------------------
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" ) ;
751
748
752
749
// Set view UID
753
750
// ------------
@@ -768,10 +765,9 @@ var FigureView = widgets.DOMWidgetView.extend({
768
765
Plotly . newPlot ( this . el , initialTraces , initialLayout ) . then (
769
766
function ( ) {
770
767
// ### 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
772
769
// traces.
773
- var traceIndexes = _ . range ( initialTraces . length ) ;
774
- that . _sendTraceDeltas ( traceIndexes , trace_edit_id ) ;
770
+ that . _sendTraceDeltas ( trace_edit_id ) ;
775
771
776
772
// ### Send layout delta ###
777
773
that . _sendLayoutDelta ( layout_edit_id ) ;
@@ -1135,14 +1131,7 @@ var FigureView = widgets.DOMWidgetView.extend({
1135
1131
Plotly . addTraces ( this . el , msgData . trace_data ) . then ( function ( ) {
1136
1132
1137
1133
// ### 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 ) ;
1146
1135
1147
1136
// ### Send layout delta ###
1148
1137
var layout_edit_id = msgData . layout_edit_id ;
@@ -1159,12 +1148,16 @@ var FigureView = widgets.DOMWidgetView.extend({
1159
1148
/** @type {Py2JsDeleteTracesMsg } */
1160
1149
var msgData = this . model . get ( "_py2js_deleteTraces" ) ;
1161
1150
1162
- console . log ( "do_deleteTraces" ) ;
1151
+ console . log ( [ "do_deleteTraces" , msgData ] ) ;
1163
1152
if ( msgData !== null ) {
1164
1153
var delete_inds = msgData . delete_inds ;
1165
1154
var that = this ;
1166
1155
Plotly . deleteTraces ( this . el , delete_inds ) . then ( function ( ) {
1167
1156
1157
+ // ### Send trace deltas ###
1158
+ var trace_edit_id = msgData . trace_edit_id ;
1159
+ that . _sendTraceDeltas ( trace_edit_id ) ;
1160
+
1168
1161
// ### Send layout delta ###
1169
1162
var layout_edit_id = msgData . layout_edit_id ;
1170
1163
that . _sendLayoutDelta ( layout_edit_id ) ;
@@ -1224,7 +1217,7 @@ var FigureView = widgets.DOMWidgetView.extend({
1224
1217
// ### Send trace deltas ###
1225
1218
// We create an array of deltas corresponding to the restyled
1226
1219
// traces.
1227
- this . _sendTraceDeltas ( traceIndexes , msgData . trace_edit_id ) ;
1220
+ this . _sendTraceDeltas ( msgData . trace_edit_id ) ;
1228
1221
1229
1222
// ### Send layout delta ###
1230
1223
var layout_edit_id = msgData . layout_edit_id ;
@@ -1287,7 +1280,7 @@ var FigureView = widgets.DOMWidgetView.extend({
1287
1280
// ### Send trace deltas ###
1288
1281
// We create an array of deltas corresponding to the updated
1289
1282
// traces.
1290
- this . _sendTraceDeltas ( traceIndexes , msgData . trace_edit_id ) ;
1283
+ this . _sendTraceDeltas ( msgData . trace_edit_id ) ;
1291
1284
1292
1285
// ### Send layout delta ###
1293
1286
var layout_edit_id = msgData . layout_edit_id ;
@@ -1328,7 +1321,7 @@ var FigureView = widgets.DOMWidgetView.extend({
1328
1321
// ### Send trace deltas ###
1329
1322
// We create an array of deltas corresponding to the
1330
1323
// animated traces.
1331
- this . _sendTraceDeltas ( traceIndexes , msgData . trace_edit_id ) ;
1324
+ this . _sendTraceDeltas ( msgData . trace_edit_id ) ;
1332
1325
1333
1326
// ### Send layout delta ###
1334
1327
var layout_edit_id = msgData . layout_edit_id ;
@@ -1346,7 +1339,7 @@ var FigureView = widgets.DOMWidgetView.extend({
1346
1339
// ### Send trace deltas ###
1347
1340
// We create an array of deltas corresponding to the
1348
1341
// animated traces.
1349
- that . _sendTraceDeltas ( traceIndexes , msgData . trace_edit_id ) ;
1342
+ that . _sendTraceDeltas ( msgData . trace_edit_id ) ;
1350
1343
1351
1344
// ### Send layout delta ###
1352
1345
var layout_edit_id = msgData . layout_edit_id ;
@@ -1406,16 +1399,17 @@ var FigureView = widgets.DOMWidgetView.extend({
1406
1399
/**
1407
1400
* Construct trace deltas array for the requested trace indexes and
1408
1401
* send traceDeltas message to the Python side
1409
- * @param {Array.<Number> } traceIndexes
1410
1402
* Array of indexes of traces for which to compute deltas
1411
1403
* @param trace_edit_id
1412
1404
* Edit ID of message that triggered the creation of trace deltas
1413
1405
* @private
1414
1406
*/
1415
- _sendTraceDeltas : function ( traceIndexes , trace_edit_id ) {
1407
+ _sendTraceDeltas : function ( trace_edit_id ) {
1416
1408
1417
- var trace_deltas = new Array ( traceIndexes . length ) ;
1418
1409
var trace_data = this . model . get ( "_data" ) ;
1410
+ var traceIndexes = _ . range ( trace_data . length ) ;
1411
+ var trace_deltas = new Array ( traceIndexes . length ) ;
1412
+
1419
1413
var fullData = this . getFullData ( ) ;
1420
1414
for ( var i = 0 ; i < traceIndexes . length ; i ++ ) {
1421
1415
var traceInd = traceIndexes [ i ] ;
0 commit comments