Skip to content

Commit 463d7ce

Browse files
committed
make ordered category algo skip over visible false traces
1 parent 6e0b63a commit 463d7ce

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/plots/cartesian/ordered_categories.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,25 @@ var d3 = require('d3');
1313

1414
// flattenUniqueSort :: String -> Function -> [[String]] -> [String]
1515
function flattenUniqueSort(axisLetter, sortFunction, data) {
16-
1716
// Bisection based insertion sort of distinct values for logarithmic time complexity.
1817
// Can't use a hashmap, which is O(1), because ES5 maps coerce keys to strings. If it ever becomes a bottleneck,
1918
// code can be separated: a hashmap (JS object) based version if all values encountered are strings; and
2019
// downgrading to this O(log(n)) array on the first encounter of a non-string value.
2120

2221
var categoryArray = [];
23-
2422
var traceLines = data.map(function(d) {return d[axisLetter];});
25-
26-
var i, j, tracePoints, category, insertionIndex;
27-
2823
var bisector = d3.bisector(sortFunction).left;
2924

30-
for(i = 0; i < traceLines.length; i++) {
31-
32-
tracePoints = traceLines[i];
33-
34-
for(j = 0; j < tracePoints.length; j++) {
25+
for(var i = 0; i < traceLines.length; i++) {
26+
var tracePoints = traceLines[i] || [];
3527

36-
category = tracePoints[j];
28+
for(var j = 0; j < tracePoints.length; j++) {
29+
var category = tracePoints[j];
3730

3831
// skip loop: ignore null and undefined categories
3932
if(category === null || category === undefined) continue;
4033

41-
insertionIndex = bisector(categoryArray, category);
34+
var insertionIndex = bisector(categoryArray, category);
4235

4336
// skip loop on already encountered values
4437
if(insertionIndex < categoryArray.length && categoryArray[insertionIndex] === category) continue;

test/jasmine/tests/calcdata_test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,27 @@ describe('calculated data and points', function() {
150150

151151
expect(gd._fullLayout.xaxis._categories).toEqual(['1']);
152152
});
153+
154+
it('should skip over visible-false traces', function() {
155+
Plotly.plot(gd, [{
156+
x: [1, 2, 3],
157+
y: [7, 6, 5],
158+
visible: false
159+
}, {
160+
x: [10, 9, 8],
161+
y: ['A', 'B', 'C'],
162+
yaxis: 'y2'
163+
}], {
164+
yaxis2: {
165+
categoryorder: 'category descending'
166+
}
167+
});
168+
169+
expect(gd.calcdata[1][0]).toEqual(jasmine.objectContaining({x: 10, y: 2}));
170+
expect(gd.calcdata[1][1]).toEqual(jasmine.objectContaining({x: 9, y: 1}));
171+
expect(gd.calcdata[1][2]).toEqual(jasmine.objectContaining({x: 8, y: 0}));
172+
expect(gd._fullLayout.yaxis2._categories).toEqual(['C', 'B', 'A']);
173+
});
153174
});
154175

155176
describe('explicit category ordering', function() {

0 commit comments

Comments
 (0)