Skip to content

Transformed array on zoom fix #1717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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, ast;
Copy link
Collaborator

Choose a reason for hiding this comment

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

🐄 just so I don't get confused, ast makes me think "abstract syntax tree", elsewhere we call this astr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right, astr is what I had in mind. Something wrong happened between brain and keyboard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 0a4ce1f


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

cd0.trace = newTrace;

for(i = 0; i < arrayAttrs.length; i++) {
ast = arrayAttrs[i];
Lib.nestedProperty(cd0.trace, ast).set(transformedArrayHash[ast]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we make sure that the array attributes in gd.calcdata[i][0].trace match the transformed array post calc transform. Other non-data-array attributes are left untouched.

}
}

// 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