Skip to content

Commit 157a6e2

Browse files
committed
don't mutate dimensions[i].displayindex in calc
... so that Plotly.react works on parcats mocks that have "bad" displayindex values
1 parent 3bb0a77 commit 157a6e2

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

src/traces/parcats/calc.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ module.exports = function calc(gd, trace) {
160160

161161
// Array of DimensionModel objects
162162
var dimensionModels = trace.dimensions.filter(visible).map(function(di, i) {
163-
return createDimensionModel(i, di._index, di.displayindex, di.label, totalCount);
163+
return createDimensionModel(i, di._index, di._displayindex, di.label, totalCount);
164164
});
165165

166166

@@ -456,16 +456,23 @@ function getUniqueInfo(values, uniqueValues) {
456456

457457
/**
458458
* Validate the requested display order for the dimensions.
459-
* If the display order is a permutation of 0 through dimensions.length - 1 then leave it alone. Otherwise, repalce
460-
* the display order with the dimension order
459+
* If the display order is a permutation of 0 through dimensions.length - 1, link to _displayindex
460+
* Otherwise, replace the display order with the dimension order
461461
* @param {Object} trace
462462
*/
463463
function validateDimensionDisplayInds(trace) {
464-
var displayInds = trace.dimensions.filter(visible).map(function(dim) {return dim.displayindex;});
465-
if(!isRangePermutation(displayInds)) {
466-
trace.dimensions.filter(visible).forEach(function(dim, i) {
467-
dim.displayindex = i;
468-
});
464+
var visibleDims = Lib.filterVisible(trace.dimensions);
465+
var displayInds = visibleDims.map(function(d) { return d.displayindex; });
466+
var i;
467+
468+
if(isRangePermutation(displayInds)) {
469+
for(i = 0; i < visibleDims.length; i++) {
470+
visibleDims[i]._displayindex = visibleDims[i].displayindex;
471+
}
472+
} else {
473+
for(i = 0; i < visibleDims.length; i++) {
474+
visibleDims[i]._displayindex = i;
475+
}
469476
}
470477
}
471478

Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"data": [
3+
{"type": "parcats",
4+
"dimensions": [
5+
{"label": "One", "values": [1, 1, 2, 1, 2, 1, 1, 2, 1],
6+
"displayindex": 1, "categoryarray": [1, 2], "ticktext": ["One", "Two"]},
7+
{"label": "Two", "values": ["A", "B", "A", "B", "C", "C", "A", "B", "C"],
8+
"displayindex": 2, "categoryarray": ["B", "A", "C"]},
9+
{"label": "Three", "values": [11, 11, 11, 11, 11, 11, 11, 11, 11], "displayindex": 1}]}
10+
],
11+
"layout": {
12+
"height": 602,
13+
"width": 592,
14+
"margin": {
15+
"l": 40, "r": 40, "t": 50, "b": 40
16+
}}
17+
}

test/jasmine/assets/mock_lists.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var svgMockList = [
2727
['range_selector_style', require('@mocks/range_selector_style.json')],
2828
['range_slider_multiple', require('@mocks/range_slider_multiple.json')],
2929
['sankey_energy', require('@mocks/sankey_energy.json')],
30-
['parcats_basic', require('@mocks/parcats_basic.json')],
30+
['parcats_bad-displayindex', require('@mocks/parcats_bad-displayindex.json')],
3131
['scattercarpet', require('@mocks/scattercarpet.json')],
3232
['shapes', require('@mocks/shapes.json')],
3333
['splom_iris', require('@mocks/splom_iris.json')],

0 commit comments

Comments
 (0)