8000 sort categories by value: test that ordering works for x and y axes · maun/plotly.js@4e4dcc0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e4dcc0

Browse files
committed
sort categories by value: test that ordering works for x and y axes
1 parent ad1b658 commit 4e4dcc0

File tree

2 files changed

+172
-140
lines changed

2 files changed

+172
-140
lines changed

src/plots/plots.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,23 +2876,25 @@ function sortAxisCategoriesByValue(axList, gd) {
28762876

28772877
// Collect values across traces
28782878
for(j = 0; j < ax._traceIndices.length; j++) {
2879-
// Keep track of traces affected by this function
28802879
var traceIndex = ax._traceIndices[j];
2881-
sortByValue.push(traceIndex);
2882-
28832880
var fullData = gd._fullData[traceIndex];
2881+
2882+
// Skip over invisible traces
28842883
if(fullData.visible !== true) continue;
28852884

2885+
// Keep track of traces affected by this function
2886+
sortByValue.push(traceIndex);
2887+
28862888
var type = fullData.type;
28872889
if(type === 'histogram') delete fullData._autoBinFinished;
28882890

28892891
var cd = gd.calcdata[traceIndex];
28902892
for(k = 0; k < cd.length; k++) {
28912893
var cdi = cd[k];
2892-
var cat, catIndex, value, orientation;
2894+
var cat, catIndex, value;
28932895

28942896
// Collect values across dimensions
2895-
if(fullData.type === 'splom') {
2897+
if(type === 'splom') {
28962898
// Find which dimension the current axis is representing
28972899
var currentDimensionIndex = cdi.trace[ax._id.charAt(0) + 'axes'].indexOf(ax._id);
28982900

@@ -2908,7 +2910,7 @@ function sortAxisCategoriesByValue(axList, gd) {
29082910
categoriesValue[catIndex][1].push(dimension.values[l]);
29092911
}
29102912
}
2911-
} else if(fullData.type === 'scattergl') {
2913+
} else if(type === 'scattergl') {
29122914
// TODO: FIXME sorting scattergl breaks
29132915
for(l = 0; l < cdi.t.x.length; l++) {
29142916
if(ax._id.charAt(0) === 'x') {
@@ -2928,30 +2930,35 @@ function sortAxisCategoriesByValue(axList, gd) {
29282930
if(ax._id.charAt(0) === 'x') {
29292931
cat = cdi.p + 1 ? cdi.p : cdi.x;
29302932
value = cdi.s || cdi.v || cdi.y;
2931-
// orientation = 'h';
29322933
} else if(ax._id.charAt(0) === 'y') {
29332934
cat = cdi.p + 1 ? cdi.p : cdi.y;
29342935
value = cdi.s || cdi.v || cdi.x;
2935-
// orientation = 'v';
29362936
}
2937-
orientation = fullData.orientation || 'v';
29382937

29392938
var twoDim = false;
29402939
if(cdi.hasOwnProperty('z')) {
29412940
value = cdi.z;
29422941
twoDim = true;
29432942
}
29442943

2944+
if(fullData.orientation === 'h') {
2945+
cat = cdi.p + 1 ? cdi.p : cdi.x;
2946+
value = cdi.s || cdi.v || cdi.y;
2947+
}
2948+
29452949
if(twoDim) {
29462950
for(l = 0; l < value.length; l++) {
29472951
for(o = 0; o < value[l].length; o++) {
2948-
catIndex = orientation === 'v' ? o : l;
2952+
catIndex = ax._id.charAt(0) === 'y' ? l : o;
29492953
if(catIndex > categoriesValue.length - 1) continue;
29502954
categoriesValue[catIndex][1].push(value[l][o]);
29512955
}
29522956
}
29532957
} else {
2954-
categoriesValue[cat][1].push(value);
2958+
if(!Array.isArray(value)) value = [value];
2959+
for(l = 0; l < value.length; l++) {
2960+
categoriesValue[cat][1].push(value[l]);
2961+
}
29552962
}
29562963
}
29572964
}

0 commit comments

Comments
 (0)
0