Skip to content

Commit 7543dc6

Browse files
committed
move ptNumber2cdIndex computation to main binning loop
1 parent c8d715b commit 7543dc6

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

src/traces/histogram/calc.js

+8-18
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,13 @@ module.exports = function calc(gd, trace) {
112112
};
113113
}
114114

115+
// bin the data
116+
// and make histogram-specific pt-number-to-cd-index map object
115117
var nMax = size.length;
116118
var uniqueValsPerBin = true;
117119
var leftGap = Infinity;
118120
var rightGap = Infinity;
119-
// bin the data
121+
var ptNumber2cdIndex = {};
120122
for(i = 0; i < pos0.length; i++) {
121123
var posi = pos0[i];
122124
n = Lib.findBin(posi, bins);
@@ -126,6 +128,7 @@ module.exports = function calc(gd, trace) {
126128
uniqueValsPerBin = false;
127129
}
128130
inputPoints[n].push(i);
131+
ptNumber2cdIndex[i] = n;
129132

130133
leftGap = Math.min(leftGap, posi - binEdges[n]);
131134
rightGap = Math.min(rightGap, binEdges[n + 1] - posi);
@@ -195,7 +198,10 @@ module.exports = function calc(gd, trace) {
195198
}
196199

197200
arraysToCalcdata(cd, trace);
198-
calcSelection(cd, trace);
201+
202+
if(Array.isArray(trace.selectedpoints)) {
203+
Lib.tagSelected(cd, trace, ptNumber2cdIndex);
204+
}
199205

200206
return cd;
201207
};
@@ -510,19 +516,3 @@ function cdf(size, direction, currentBin) {
510516
}
511517
}
512518
}
513-
514-
function calcSelection(cd, trace) {
515-
if(Array.isArray(trace.selectedpoints)) {
516-
var ptNumber2cdIndex = {};
517-
518-
// make histogram-specific pt-number-to-cd-index map object
519-
for(var i = 0; i < cd.length; i++) {
520-
var pts = cd[i].pts || [];
521-
for(var j = 0; j < pts.length; j++) {
522-
ptNumber2cdIndex[pts[j]] = i;
523-
}
524-
}
525-
526-
Lib.tagSelected(cd, trace, ptNumber2cdIndex);
527-
}
528-
}

test/jasmine/tests/select_test.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ describe('Test select box and lasso per trace:', function() {
554554

555555
if(typeof e[j] === 'number') {
556556
expect(p[k]).toBeCloseTo(e[j], 1, msgFull);
557+
} else if(Array.isArray(e[j])) {
558+
expect(p[k]).toBeCloseToArray(e[j], 1, msgFull);
557559
} else {
558560
expect(p[k]).toBe(e[j], msgFull);
559561
}
@@ -990,7 +992,7 @@ describe('Test select box and lasso per trace:', function() {
990992
});
991993

992994
it('should work for histogram traces', function(done) {
993-
var assertPoints = makeAssertPoints(['curveNumber', 'x', 'y']);
995+
var assertPoints = makeAssertPoints(['curveNumber', 'x', 'y', 'pointIndices']);
994996
var assertRanges = makeAssertRanges();
995997
var assertLassoPoints = makeAssertLassoPoints();
996998

@@ -1006,7 +1008,7 @@ describe('Test select box and lasso per trace:', function() {
10061008
[[200, 200], [400, 200], [400, 350], [200, 350], [200, 200]],
10071009
function() {
10081010
assertPoints([
1009-
[0, 1.8, 2], [1, 2.2, 1], [1, 3.2, 1]
1011+
[0, 1.8, 2, [3, 4]], [1, 2.2, 1, [1]], [1, 3.2, 1, [2]]
10101012
]);
10111013
assertLassoPoints([
10121014
[1.66, 3.59, 3.59, 1.66, 1.66],
@@ -1024,7 +1026,7 @@ describe('Test select box and lasso per trace:', function() {
10241026
[[200, 200], [400, 350]],
10251027
function() {
10261028
assertPoints([
1027-
[0, 1.8, 2], [1, 2.2, 1], [1, 3.2, 1]
1029+
[0, 1.8, 2, [3, 4]], [1, 2.2, 1, [1]], [1, 3.2, 1, [2]]
10281030
]);
10291031
assertRanges([[1.66, 3.59], [0.69, 2.17]]);
10301032
},

0 commit comments

Comments
 (0)