Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var d3 = require('d3');
var isNumeric = require('fast-isnumeric');

var Plotly = require('../plotly');
var PlotSchema = require('../plot_api/plot_schema');
var Registry = require('../registry');
var Lib = require('../lib');
var Color = require('../components/color');
Expand Down Expand Up @@ -505,12 +506,38 @@ plots.supplyDefaults = function(gd) {
// update object references in calcdata
if((gd.calcdata || []).length === newFullData.length) {
Copy link
Contributor Author

@etpinard etpinard May 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block updates the gd.calcdata[i][0].trace reference so that the plot step can use the correct fullData attribute values even in cases where Plots.doCalcdata isn't called (e.g. on zoom).

for(i = 0; i < newFullData.length; i++) {
var trace = newFullData[i];
(gd.calcdata[i][0] || {}).trace = trace;
var newTrace = newFullData[i];
var cd0 = gd.calcdata[i][0];
if(cd0 && cd0.trace) {
if(cd0.trace._hasCalcTransform) {
remapTransformedArrays(cd0, newTrace);
} else {
cd0.trace = newTrace;
}
}
}
}
};

function remapTransformedArrays(cd0, newTrace) {
var oldTrace = cd0.trace;
var arrayAttrs = PlotSchema.findArrayAttributes(oldTrace);
var transformedArrayHash = {};
var i, astr;

for(i = 0; i < arrayAttrs.length; i++) {
astr = arrayAttrs[i];
transformedArrayHash[astr] = Lib.nestedProperty(oldTrace, astr).get().slice();
}

cd0.trace = newTrace;

for(i = 0; i < arrayAttrs.length; i++) {
astr = arrayAttrs[i];
Lib.nestedProperty(cd0.trace, astr).set(transformedArrayHash[astr]);
}
}

// Create storage for all of the data related to frames and transitions:
plots.createTransitionData = function(gd) {
// Set up the default keyframe if it doesn't exist:
Expand Down Expand Up @@ -2022,6 +2049,7 @@ plots.doCalcdata = function(gd, traces) {

_module = transformsRegistry[transform.type];
if(_module && _module.calcTransform) {
trace._hasCalcTransform = true;
hasCalcTransform = true;
_module.calcTransform(gd, trace, transform);
}
Expand Down
12 changes: 12 additions & 0 deletions test/jasmine/tests/transform_sort_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,18 @@ describe('Test sort transform interactions:', function() {
.then(function(eventData) {
assertPt(eventData, 1, 1, 5, 'G');
})
.then(function() {
return Plotly.relayout(gd, 'xaxis.range', [-5, 5]);
})
.then(function() { return hover(gd, 'D'); })
.then(function(eventData) {
assertPt(eventData, 0, 1, 1, 'D');
})
.then(wait)
.then(function() { return click(gd, 'G'); })
.then(function(eventData) {
assertPt(eventData, 1, 1, 5, 'G');
})
.catch(fail)
.then(done);
});
Expand Down