Skip to content

Commit 6fe5ec4

Browse files
committed
remap transformed arrays in supply defaults
- flag fullData traces that passed through calc transforms with `_hasCalcTransform: true` - update calcdata[i][0].trace ref BUT map back transformed arrays so that they match the calcdata[i][j] items on non-recalc updates (e.g. zoom events)
1 parent 33837f8 commit 6fe5ec4

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/plots/plots.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var d3 = require('d3');
1313
var isNumeric = require('fast-isnumeric');
1414

1515
var Plotly = require('../plotly');
16+
var PlotSchema = require('../plot_api/plot_schema');
1617
var Registry = require('../registry');
1718
var Lib = require('../lib');
1819
var Color = require('../components/color');
@@ -505,12 +506,38 @@ plots.supplyDefaults = function(gd) {
505506
// update object references in calcdata
506507
if((gd.calcdata || []).length === newFullData.length) {
507508
for(i = 0; i < newFullData.length; i++) {
508-
var trace = newFullData[i];
509-
(gd.calcdata[i][0] || {}).trace = trace;
509+
var newTrace = newFullData[i];
510+
var cd0 = gd.calcdata[i][0];
511+
if(cd0 && cd0.trace) {
512+
if(cd0.trace._hasCalcTransform) {
513+
remapTransformedArrays(cd0, newTrace);
514+
} else {
515+
cd0.trace = newTrace;
516+
}
517+
}
510518
}
511519
}
512520
};
513521

522+
function remapTransformedArrays(cd0, newTrace) {
523+
var oldTrace = cd0.trace;
524+
var arrayAttrs = PlotSchema.findArrayAttributes(oldTrace);
525+
var transformedArrayHash = {};
526+
var i, ast;
527+
528+
for(i = 0; i < arrayAttrs.length; i++) {
529+
ast = arrayAttrs[i];
530+
transformedArrayHash[ast] = Lib.nestedProperty(oldTrace, ast).get().slice();
531+
}
532+
533+
cd0.trace = newTrace;
534+
535+
for(i = 0; i < arrayAttrs.length; i++) {
536+
ast = arrayAttrs[i];
537+
Lib.nestedProperty(cd0.trace, ast).set(transformedArrayHash[ast]);
538+
}
539+
}
540+
514541
// Create storage for all of the data related to frames and transitions:
515542
plots.createTransitionData = function(gd) {
516543
// Set up the default keyframe if it doesn't exist:
@@ -2022,6 +2049,7 @@ plots.doCalcdata = function(gd, traces) {
20222049

20232050
_module = transformsRegistry[transform.type];
20242051
if(_module && _module.calcTransform) {
2052+
trace._hasCalcTransform = true;
20252053
hasCalcTransform = true;
20262054
_module.calcTransform(gd, trace, transform);
20272055
}

0 commit comments

Comments
 (0)