@@ -254,27 +254,37 @@ var extraFormatKeys = [
254
254
'year' , 'month' , 'dayMonth' , 'dayMonthYear'
255
255
] ;
256
256
257
- // Fill in default values:
258
- //
259
- // gd.data, gd.layout:
260
- // are precisely what the user specified,
261
- // these fields shouldn't be modified nor used directly
262
- // after the supply defaults step.
263
- //
264
- // gd._fullData, gd._fullLayout:
265
- // are complete descriptions of how to draw the plot,
266
- // use these fields in all required computations.
267
- //
268
- // gd._fullLayout._modules
269
- // is a list of all the trace modules required to draw the plot.
270
- //
271
- // gd._fullLayout._basePlotModules
272
- // is a list of all the plot modules required to draw the plot.
273
- //
274
- // gd._fullLayout._transformModules
275
- // is a list of all the transform modules invoked.
276
- //
277
- plots . supplyDefaults = function ( gd , skipCalcUpdate ) {
257
+ /*
258
+ * Fill in default values
259
+ * @param {DOM element } gd
260
+ * @param {object } opts
261
+ * @param {boolean } opts.skipUpdateCalc: normally if the existing gd.calcdata looks
262
+ * compatible with the new gd._fullData we finish by linking the new _fullData traces
263
+ * to the old gd.calcdata, so it's correctly set if we're not going to recalc. But also,
264
+ * if there are calcTransforms on the trace, we first remap data arrays from the old full
265
+ * trace into the new one. Use skipUpdateCalc to defer this (needed by Plotly.react)
266
+ *
267
+ * gd.data, gd.layout:
268
+ * are precisely what the user specified,
269
+ * these fields shouldn't be modified nor used directly
270
+ * after the supply defaults step.
271
+ *
272
+ * gd._fullData, gd._fullLayout:
273
+ * are complete descriptions of how to draw the plot,
274
+ * use these fields in all required computations.
275
+ *
276
+ * gd._fullLayout._modules
277
+ * is a list of all the trace modules required to draw the plot.
278
+ *
279
+ * gd._fullLayout._basePlotModules
280
+ * is a list of all the plot modules required to draw the plot.
281
+ *
282
+ * gd._fullLayout._transformModules
283
+ * is a list of all the transform modules invoked.
284
+ *
285
+ */
286
+ plots . supplyDefaults = function ( gd , opts ) {
287
+ var skipUpdateCalc = opts && opts . skipUpdateCalc ;
278
288
var oldFullLayout = gd . _fullLayout || { } ;
279
289
280
290
if ( oldFullLayout . _skipDefaults ) {
@@ -458,7 +468,7 @@ plots.supplyDefaults = function(gd, skipCalcUpdate) {
458
468
}
459
469
460
470
// update object references in calcdata
461
- if ( ! skipCalcUpdate && oldCalcdata . length === newFullData . length ) {
471
+ if ( ! skipUpdateCalc && oldCalcdata . length === newFullData . length ) {
462
472
plots . supplyDefaultsUpdateCalc ( oldCalcdata , newFullData ) ;
463
473
}
464
474
@@ -471,11 +481,18 @@ plots.supplyDefaultsUpdateCalc = function(oldCalcdata, newFullData) {
471
481
var newTrace = newFullData [ i ] ;
472
482
var cd0 = oldCalcdata [ i ] [ 0 ] ;
473
483
if ( cd0 && cd0 . trace ) {
474
- if ( cd0 . trace . _hasCalcTransform ) {
475
- remapTransformedArrays ( cd0 , newTrace ) ;
476
- } else {
477
- cd0 . trace = newTrace ;
484
+ var oldTrace = cd0 . trace ;
485
+ if ( oldTrace . _hasCalcTransform ) {
486
+ var arrayAttrs = oldTrace . _arrayAttrs ;
487
+ var j , astr , oldArrayVal ;
488
+
489
+ for ( j = 0 ; j < arrayAttrs . length ; j ++ ) {
490
+ astr = arrayAttrs [ j ] ;
491
+ oldArrayVal = Lib . nestedProperty ( oldTrace , astr ) . get ( ) . slice ( ) ;
492
+ Lib . nestedProperty ( newTrace , astr ) . set ( oldArrayVal ) ;
493
+ }
478
494
}
495
+ cd0 . trace = newTrace ;
479
496
}
480
497
}
481
498
} ;
@@ -522,25 +539,6 @@ function emptySubplotLists() {
522
539
return out ;
523
540
}
524
541
525
- function remapTransformedArrays ( cd0 , newTrace ) {
526
- var oldTrace = cd0 . trace ;
527
- var arrayAttrs = oldTrace . _arrayAttrs ;
528
- var transformedArrayHash = { } ;
529
- var i , astr ;
530
-
531
- for ( i = 0 ; i < arrayAttrs . length ; i ++ ) {
532
- astr = arrayAttrs [ i ] ;
533
- transformedArrayHash [ astr ] = Lib . nestedProperty ( oldTrace , astr ) . get ( ) . slice ( ) ;
534
- }
535
-
536
- cd0 . trace = newTrace ;
537
-
538
- for ( i = 0 ; i < arrayAttrs . length ; i ++ ) {
539
- astr = arrayAttrs [ i ] ;
540
- Lib . nestedProperty ( cd0 . trace , astr ) . set ( transformedArrayHash [ astr ] ) ;
541
- }
542
- }
543
-
544
542
/**
545
543
* getFormatObj: use _context to get the format object from locale.
546
544
* Used to get d3.locale argument object and extraFormat argument object
0 commit comments