From 33837f84d564df4c68d14eb21a890db7c55e4ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Tue, 23 May 2017 16:10:46 -0400 Subject: [PATCH 1/3] add test case for event data after zoom (i.e. a non-recalc update) --- test/jasmine/tests/transform_sort_test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/jasmine/tests/transform_sort_test.js b/test/jasmine/tests/transform_sort_test.js index 05ee9ccaf51..aa055af14a6 100644 --- a/test/jasmine/tests/transform_sort_test.js +++ b/test/jasmine/tests/transform_sort_test.js @@ -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); }); From 6fe5ec4f5adba728496115d7bff773879e7e9750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Tue, 23 May 2017 16:13:07 -0400 Subject: [PATCH 2/3] 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) --- src/plots/plots.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index 12c5faaba6a..811014830f9 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -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'); @@ -505,12 +506,38 @@ plots.supplyDefaults = function(gd) { // update object references in calcdata if((gd.calcdata || []).length === newFullData.length) { 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; + + 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]); + } +} + // 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: @@ -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); } From 0a4ce1f6c0c358d4f03eb68124e90fd743697e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Tue, 23 May 2017 17:46:40 -0400 Subject: [PATCH 3/3] replace ast -> astr --- src/plots/plots.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index 811014830f9..1b6f45321f8 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -523,18 +523,18 @@ function remapTransformedArrays(cd0, newTrace) { var oldTrace = cd0.trace; var arrayAttrs = PlotSchema.findArrayAttributes(oldTrace); var transformedArrayHash = {}; - var i, ast; + var i, astr; for(i = 0; i < arrayAttrs.length; i++) { - ast = arrayAttrs[i]; - transformedArrayHash[ast] = Lib.nestedProperty(oldTrace, ast).get().slice(); + astr = arrayAttrs[i]; + transformedArrayHash[astr] = Lib.nestedProperty(oldTrace, astr).get().slice(); } cd0.trace = newTrace; for(i = 0; i < arrayAttrs.length; i++) { - ast = arrayAttrs[i]; - Lib.nestedProperty(cd0.trace, ast).set(transformedArrayHash[ast]); + astr = arrayAttrs[i]; + Lib.nestedProperty(cd0.trace, astr).set(transformedArrayHash[astr]); } }