Skip to content

Commit 0f5e491

Browse files
committed
fix issue 5267 - pick correct categories and values pluse a bit of optimization
1 parent 98dfdb8 commit 0f5e491

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/plots/plots.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,6 +3098,9 @@ function sortAxisCategoriesByValue(axList, gd) {
30983098
var aggregator = match[1];
30993099
var order = match[2];
31003100

3101+
var axLetter = ax._id.charAt(0);
3102+
var isX = axLetter === 'x';
3103+
31013104
// Store values associated with each category
31023105
var categoriesValue = [];
31033106
for(j = 0; j < ax._categories.length; j++) {
@@ -3108,7 +3111,6 @@ function sortAxisCategoriesByValue(axList, gd) {
31083111
for(j = 0; j < ax._traceIndices.length; j++) {
31093112
var traceIndex = ax._traceIndices[j];
31103113
var fullTrace = gd._fullData[traceIndex];
3111-
var axLetter = ax._id.charAt(0);
31123114

31133115
// Skip over invisible traces
31143116
if(fullTrace.visible !== true) continue;
@@ -3118,27 +3120,28 @@ function sortAxisCategoriesByValue(axList, gd) {
31183120
delete fullTrace._xautoBinFinished;
31193121
delete fullTrace._yautoBinFinished;
31203122
}
3123+
var isSplom = type === 'splom';
3124+
var isScattergl = type === 'scattergl';
31213125

31223126
var cd = gd.calcdata[traceIndex];
31233127
for(k = 0; k < cd.length; k++) {
31243128
var cdi = cd[k];
3125-
var cat, catIndex, value;
3129+
var catIndex, value;
31263130

3127-
if(type === 'splom') {
3131+
if(isSplom) {
31283132
// If `splom`, collect values across dimensions
31293133
// Find which dimension the current axis is representing
31303134
var currentDimensionIndex = fullTrace._axesDim[ax._id];
31313135

31323136
// Apply logic to associated x axis if it's defined
3133-
if(axLetter === 'y') {
3137+
if(!isX) {
31343138
var associatedXAxisID = fullTrace._diag[currentDimensionIndex][0];
31353139
if(associatedXAxisID) ax = gd._fullLayout[axisIDs.id2name(associatedXAxisID)];
31363140
}
31373141

31383142
var categories = cdi.trace.dimensions[currentDimensionIndex].values;
31393143
for(l = 0; l < categories.length; l++) {
3140-
cat = categories[l];
3141-
catIndex = ax._categoriesMap[cat];
3144+
catIndex = ax._categoriesMap[categories[l]];
31423145

31433146
// Collect associated values at index `l` over all other dimensions
31443147
for(o = 0; o < cdi.trace.dimensions.length; o++) {
@@ -3147,18 +3150,14 @@ function sortAxisCategoriesByValue(axList, gd) {
31473150
categoriesValue[catIndex][1].push(dimension.values[l]);
31483151
}
31493152
}
3150-
} else if(type === 'scattergl') {
3153+
} else if(isScattergl) {
31513154
// If `scattergl`, collect all values stashed under cdi.t
31523155
for(l = 0; l < cdi.t.x.length; l++) {
3153-
if(axLetter === 'x') {
3154-
cat = cdi.t.x[l];
3155-
catIndex = cat;
3156+
if(isX) {
3157+
catIndex = cdi.t.x[l];
31563158
value = cdi.t.y[l];
3157-
}
3158-
3159-
if(axLetter === 'y') {
3160-
cat = cdi.t.y[l];
3161-
catIndex = cat;
3159+
} else {
3160+
catIndex = cdi.t.y[l];
31623161
value = cdi.t.x[l];
31633162
}
31643163
categoriesValue[catIndex][1].push(value);
@@ -3181,16 +3180,19 @@ function sortAxisCategoriesByValue(axList, gd) {
31813180
}
31823181
} else {
31833182
// For all other 2d cartesian traces
3184-
if(axLetter === 'x') {
3185-
cat = cdi.p + 1 ? cdi.p : cdi.x;
3186-
value = cdi.s || cdi.v || cdi.y;
3187-
} else if(axLetter === 'y') {
3188-
cat = cdi.p + 1 ? cdi.p : cdi.y;
3189-
value = cdi.s || cdi.v || cdi.x;
3183+
catIndex = cdi.p;
3184+
if(catIndex === undefined) catIndex = cdi[axLetter];
3185+
3186+
value = cdi.s;
3187+
if(value === undefined) value = cdi.v;
3188+
if(value === undefined) value = isX ? cdi.y : cdi.x;
3189+
3190+
if(!Array.isArray(value)) {
3191+
if(value === undefined) value = [];
3192+
else value = [value];
31903193
}
3191-
if(!Array.isArray(value)) value = [value];
31923194
for(l = 0; l < value.length; l++) {
3193-
categoriesValue[cat][1].push(value[l]);
3195+
categoriesValue[catIndex][1].push(value[l]);
31943196
}
31953197
}
31963198
}

0 commit comments

Comments
 (0)