Skip to content

Commit 6cc5ffd

Browse files
authored
Merge pull request #1717 from plotly/transformed-array-on-zoom-fix
Transformed array on zoom fix
2 parents 740fd7e + 0a4ce1f commit 6cc5ffd

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-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, astr;
527+
528+
for(i = 0; i < arrayAttrs.length; i++) {
529+
astr = arrayAttrs[i];
530+
transformedArrayHash[astr] = Lib.nestedProperty(oldTrace, astr).get().slice();
531+
}
532+
533+
cd0.trace = newTrace;
534+
535+
for(i = 0; i < arrayAttrs.length; i++) {
536+
astr = arrayAttrs[i];
537+
Lib.nestedProperty(cd0.trace, astr).set(transformedArrayHash[astr]);
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
}

test/jasmine/tests/transform_sort_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,18 @@ describe('Test sort transform interactions:', function() {
352352
.then(function(eventData) {
353353
assertPt(eventData, 1, 1, 5, 'G');
354354
})
355+
.then(function() {
356+
return Plotly.relayout(gd, 'xaxis.range', [-5, 5]);
357+
})
358+
.then(function() { return hover(gd, 'D'); })
359+
.then(function(eventData) {
360+
assertPt(eventData, 0, 1, 1, 'D');
361+
})
362+
.then(wait)
363+
.then(function() { return click(gd, 'G'); })
364+
.then(function(eventData) {
365+
assertPt(eventData, 1, 1, 5, 'G');
366+
})
355367
.catch(fail)
356368
.then(done);
357369
});

0 commit comments

Comments
 (0)