Skip to content

Commit 044ea96

Browse files
committed
add indexToPoints to sort transforms
1 parent 51fcb2e commit 044ea96

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/transforms/sort.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
var Lib = require('../lib');
1212
var Axes = require('../plots/cartesian/axes');
13+
var pointsAccessorFunction = require('./helpers').pointsAccessorFunction;
1314

1415
exports.moduleType = 'transform';
1516

@@ -87,18 +88,27 @@ exports.calcTransform = function(gd, trace, opts) {
8788
var arrayAttrs = trace._arrayAttrs;
8889
var d2c = Axes.getDataToCoordFunc(gd, trace, target, targetArray);
8990
var indices = getIndices(opts, targetArray, d2c);
91+
var originalPointsAccessor = pointsAccessorFunction(trace.transforms, opts);
92+
var indexToPoints = {};
93+
var i, j;
9094

91-
for(var i = 0; i < arrayAttrs.length; i++) {
95+
for(i = 0; i < arrayAttrs.length; i++) {
9296
var np = Lib.nestedProperty(trace, arrayAttrs[i]);
9397
var arrayOld = np.get();
9498
var arrayNew = new Array(len);
9599

96-
for(var j = 0; j < len; j++) {
100+
for(j = 0; j < len; j++) {
97101
arrayNew[j] = arrayOld[indices[j]];
98102
}
99103

100104
np.set(arrayNew);
101105
}
106+
107+
for(j = 0; j < len; j++) {
108+
indexToPoints[j] = originalPointsAccessor(indices[j]);
109+
}
110+
111+
opts._indexToPoints = indexToPoints;
102112
};
103113

104114
function getIndices(opts, targetArray, d2c) {

test/jasmine/tests/transform_sort_test.js

+27
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ describe('Test sort transform calc:', function() {
9090
expect(out[0].ids).toEqual(['n0', 'n2', 'n1', 'z', 'p1', 'p3', 'p2']);
9191
expect(out[0].marker.color).toEqual([0.1, 0.3, 0.2, 0.1, 0.2, 0.4, 0.3]);
9292
expect(out[0].marker.size).toEqual([10, 5, 20, 1, 6, 10, 0]);
93+
expect(out[0].transforms[0]._indexToPoints).toEqual({
94+
0: [0],
95+
1: [2],
96+
2: [1],
97+
3: [3],
98+
4: [4],
99+
5: [6],
100+
6: [5]
101+
});
93102
});
94103

95104
it('should sort all array attributes (descending case)', function() {
@@ -104,6 +113,15 @@ describe('Test sort transform calc:', function() {
104113
expect(out[0].ids).toEqual(['p2', 'p1', 'p3', 'z', 'n1', 'n0', 'n2']);
105114
expect(out[0].marker.color).toEqual([0.3, 0.2, 0.4, 0.1, 0.2, 0.1, 0.3]);
106115
expect(out[0].marker.size).toEqual([0, 6, 10, 1, 20, 10, 5]);
116+
expect(out[0].transforms[0]._indexToPoints).toEqual({
117+
0: [5],
118+
1: [4],
119+
2: [6],
120+
3: [3],
121+
4: [1],
122+
5: [0],
123+
6: [2]
124+
});
107125
});
108126

109127
it('should sort via nested targets', function() {
@@ -119,6 +137,15 @@ describe('Test sort transform calc:', function() {
119137
expect(out[0].ids).toEqual(['n1', 'n0', 'p3', 'p1', 'n2', 'z', 'p2']);
120138
expect(out[0].marker.color).toEqual([0.2, 0.1, 0.4, 0.2, 0.3, 0.1, 0.3]);
121139
expect(out[0].marker.size).toEqual([20, 10, 10, 6, 5, 1, 0]);
140+
expect(out[0].transforms[0]._indexToPoints).toEqual({
141+
0: [1],
142+
1: [0],
143+
2: [6],
144+
3: [4],
145+
4: [2],
146+
5: [3],
147+
6: [5]
148+
});
122149
});
123150

124151
it('should sort via dates targets', function() {

0 commit comments

Comments
 (0)