8000 Transform inverse mapping by monfera · Pull Request #2126 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Transform inverse mapping #2126

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 8 commits into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
< 8000 /span> Prev Previous commit
extracting out common function
  • Loading branch information
monfera committed Oct 27, 2017
commit ce3a118b70ca4e6aead0710a95cdd43602cf648d
8 changes: 3 additions & 5 deletions src/transforms/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
var Axes = require('../plots/cartesian/axes');
var Lib = require('../lib');
var PlotSchema = require('../plot_api/plot_schema');
var pointsAccessorFunction = require('./helpers').pointsAccessorFunction;
var BADNUM = require('../constants/numerical').BADNUM;

exports.moduleType = 'transform';
Expand Down Expand Up @@ -221,10 +222,7 @@ exports.calcTransform = function(gd, trace, opts) {
var indexToPoints = {};
var groupings = [];

var prevTransforms = trace.transforms.filter(function(tr) {return tr._indexToPoints;});
var originalPointsAccessor = prevTransforms.length ?
function(i) {return prevTransforms[prevTransforms.length - 1]._indexToPoints[i];} :
function(i) {return [i];};
var originalPointsAccessor = pointsAccessorFunction(trace.transforms, opts);

for(i = 0; i < groupArray.length; i++) {
vi = groupArray[i];
Expand All @@ -237,7 +235,7 @@ exports.calcTransform = function(gd, trace, opts) {
}
else {
groupings[groupIndex].push(i);
indexToPoints[groupIndices[vi]] = indexToPoints[groupIndices[vi]].concat(originalPointsAccessor(i));
indexToPoints[groupIndices[vi]] = (indexToPoints[groupIndices[vi]] || []).concat(originalPointsAccessor(i));
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/transforms/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
var Lib = require('../lib');
var Registry = require('../registry');
var Axes = require('../plots/cartesian/axes');
var pointsAccessorFunction = require('./helpers').pointsAccessorFunction;

var COMPARISON_OPS = ['=', '!=', '<', '>=', '>', '<='];
var INTERVAL_OPS = ['[]', '()', '[)', '(]', '][', ')(', '](', ')['];
Expand Down Expand Up @@ -205,10 +206,7 @@ exports.calcTransform = function(gd, trace, opts) {
// copy all original array attribute values, and clear arrays in trace
forAllAttrs(initFn);

var prevTransforms = trace.transforms.filter(function(tr) {return tr._indexToPoints;});
var originalPointsAccessor = prevTransforms.length ?
function(i) {return prevTransforms[prevTransforms.length - 1]._indexToPoints[i];} :
function(i) {return [i];};
var originalPointsAccessor = pointsAccessorFunction(trace.transforms, opts);

// loop through filter array, fill trace arrays if passed
for(var i = 0; i < len; i++) {
Expand Down
24 changes: 24 additions & 0 deletions src/transforms/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

exports.pointsAccessorFunction = function(transforms, opts) {
var tr;
var prevIndexToPoints;
for(var i = 0; i < transforms.length; i++) {
tr = transforms[i];
if(tr === opts) break;< 4A25 /td>
if(!tr._indexToPoints || tr.enabled === false) continue;
prevIndexToPoints = tr._indexToPoints;
}
var originalPointsAccessor = prevIndexToPoints ?
function(i) {return prevIndexToPoints[i];} :
function(i) {return [i];};
return originalPointsAccessor;
};
0