@@ -3098,6 +3098,9 @@ function sortAxisCategoriesByValue(axList, gd) {
3098
3098
var aggregator = match [ 1 ] ;
3099
3099
var order = match [ 2 ] ;
3100
3100
3101
+ var axLetter = ax . _id . charAt ( 0 ) ;
3102
+ var isX = axLetter === 'x' ;
3103
+
3101
3104
// Store values associated with each category
3102
3105
var categoriesValue = [ ] ;
3103
3106
for ( j = 0 ; j < ax . _categories . length ; j ++ ) {
@@ -3108,7 +3111,6 @@ function sortAxisCategoriesByValue(axList, gd) {
3108
3111
for ( j = 0 ; j < ax . _traceIndices . length ; j ++ ) {
3109
3112
var traceIndex = ax . _traceIndices [ j ] ;
3110
3113
var fullTrace = gd . _fullData [ traceIndex ] ;
3111
- var axLetter = ax . _id . charAt ( 0 ) ;
3112
3114
3113
3115
// Skip over invisible traces
3114
3116
if ( fullTrace . visible !== true ) continue ;
@@ -3118,27 +3120,28 @@ function sortAxisCategoriesByValue(axList, gd) {
3118
3120
delete fullTrace . _xautoBinFinished ;
3119
3121
delete fullTrace . _yautoBinFinished ;
3120
3122
}
3123
+ var isSplom = type === 'splom' ;
3124
+ var isScattergl = type === 'scattergl' ;
3121
3125
3122
3126
var cd = gd . calcdata [ traceIndex ] ;
3123
3127
for ( k = 0 ; k < cd . length ; k ++ ) {
3124
3128
var cdi = cd [ k ] ;
3125
- var cat , catIndex , value ;
3129
+ var catIndex , value ;
3126
3130
3127
- if ( type === 'splom' ) {
3131
+ if ( isSplom ) {
3128
3132
// If `splom`, collect values across dimensions
3129
3133
// Find which dimension the current axis is representing
3130
3134
var currentDimensionIndex = fullTrace . _axesDim [ ax . _id ] ;
3131
3135
3132
3136
// Apply logic to associated x axis if it's defined
3133
- if ( axLetter === 'y' ) {
3137
+ if ( ! isX ) {
3134
3138
var associatedXAxisID = fullTrace . _diag [ currentDimensionIndex ] [ 0 ] ;
3135
3139
if ( associatedXAxisID ) ax = gd . _fullLayout [ axisIDs . id2name ( associatedXAxisID ) ] ;
3136
3140
}
3137
3141
3138
3142
var categories = cdi . trace . dimensions [ currentDimensionIndex ] . values ;
3139
3143
for ( l = 0 ; l < categories . length ; l ++ ) {
3140
- cat = categories [ l ] ;
3141
- catIndex = ax . _categoriesMap [ cat ] ;
3144
+ catIndex = ax . _categoriesMap [ categories [ l ] ] ;
3142
3145
3143
3146
// Collect associated values at index `l` over all other dimensions
3144
3147
for ( o = 0 ; o < cdi . trace . dimensions . length ; o ++ ) {
@@ -3147,18 +3150,14 @@ function sortAxisCategoriesByValue(axList, gd) {
3147
3150
categoriesValue [ catIndex ] [ 1 ] . push ( dimension . values [ l ] ) ;
3148
3151
}
3149
3152
}
3150
- } else if ( type === 'scattergl' ) {
3153
+ } else if ( isScattergl ) {
3151
3154
// If `scattergl`, collect all values stashed under cdi.t
3152
3155
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 ] ;
3156
3158
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 ] ;
3162
3161
value = cdi . t . x [ l ] ;
3163
3162
}
3164
3163
categoriesValue [ catIndex ] [ 1 ] . push ( value ) ;
@@ -3181,16 +3180,19 @@ function sortAxisCategoriesByValue(axList, gd) {
3181
3180
}
3182
3181
} else {
3183
3182
// 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 ] ;
3190
3193
}
3191
- if ( ! Array . isArray ( value ) ) value = [ value ] ;
3192
3194
for ( l = 0 ; l < value . length ; l ++ ) {
3193
- categoriesValue [ cat ] [ 1 ] . push ( value [ l ] ) ;
3195
+ categoriesValue [ catIndex ] [ 1 ] . push ( value [ l ] ) ;
3194
3196
}
3195
3197
}
3196
3198
}
0 commit comments