@@ -2860,14 +2860,15 @@ var sortAxisCategoriesByValueRegex = /(value|sum|min|max) (ascending|descending)
2860
2860
2861
2861
function sortAxisCategoriesByValue ( axList , gd ) {
2862
2862
var sortByValue = [ ] ;
2863
- var i , j , k ;
2863
+ var i , j , k , l , o ;
2864
2864
for ( i = 0 ; i < axList . length ; i ++ ) {
2865
2865
var ax = axList [ i ] ;
2866
2866
if ( ax . type !== 'category' ) continue ;
2867
2867
2868
2868
// Order by value
2869
- var m = ax . categoryorder . match ( sortAxisCategoriesByValueRegex ) ;
2870
- if ( m ) {
2869
+ var match = ax . categoryorder . match ( sortAxisCategoriesByValueRegex ) ;
2870
+ if ( match ) {
2871
+ console . log ( ax . _categories ) ;
2871
2872
// Store values associated with each category
2872
2873
var categoriesValue = [ ] ;
2873
2874
for ( j = 0 ; j < ax . _categories . length ; j ++ ) {
@@ -2876,7 +2877,7 @@ function sortAxisCategoriesByValue(axList, gd) {
2876
2877
2877
2878
// Collect values across traces
2878
2879
for ( j = 0 ; j < ax . _traceIndices . length ; j ++ ) {
2879
- // Keep track of traces we sort!
2880
+ // Keep track of traces affected by this function
2880
2881
var traceIndex = ax . _traceIndices [ j ] ;
2881
2882
sortByValue . push ( traceIndex ) ;
2882
2883
@@ -2888,21 +2889,40 @@ function sortAxisCategoriesByValue(axList, gd) {
2888
2889
2889
2890
var cd = gd . calcdata [ traceIndex ] ;
2890
2891
for ( k = 0 ; k < cd . length ; k ++ ) {
2891
- var cat , value ;
2892
+ var cdi = cd [ k ] ;
2893
+ var cat , value , orientation ;
2894
+
2892
2895
if ( ax . _id [ 0 ] === 'x' ) {
2893
- cat = cd [ k ] . x ;
2894
- value = cd [ k ] . y ;
2896
+ cat = cdi . x ;
2897
+ value = cdi . y ;
2898
+ orientation = 'h' ;
2895
2899
} else if ( ax . _id [ 0 ] === 'y' ) {
2896
- cat = cd [ k ] . y ;
2897
- value = cd [ k ] . x ;
2900
+ cat = cdi . y ;
2901
+ value = cdi . x ;
2902
+ orientation = 'v' ;
2903
+ }
2904
+
2905
+ var twoDim = false ;
2906
+ if ( cdi . hasOwnProperty ( 'z' ) ) {
2907
+ value = cdi . z ;
2908
+ twoDim = true ;
2909
+ }
2910
+
2911
+ if ( twoDim ) {
2912
+ for ( l = 0 ; l < value . length ; l ++ ) {
2913
+ for ( o = 0 ; o < value [ l ] . length ; o ++ ) {
2914
+ categoriesValue [ orientation === 'h' ? o : l ] [ 1 ] . push ( value [ l ] [ o ] ) ;
2915
+ }
2916
+ }
2917
+ } else {
2918
+ categoriesValue [ cat ] [ 1 ] . push ( value ) ;
2898
2919
}
2899
- categoriesValue [ cat ] [ 1 ] . push ( value ) ;
2900
2920
}
2901
2921
}
2902
2922
2903
2923
// Aggregate values
2904
2924
var aggFn ;
2905
- switch ( m [ 1 ] ) {
2925
+ switch ( match [ 1 ] ) {
2906
2926
case 'min' :
2907
2927
aggFn = Math . min ;
2908
2928
break ;
@@ -2928,7 +2948,7 @@ function sortAxisCategoriesByValue(axList, gd) {
2928
2948
} ) ;
2929
2949
2930
2950
// Reverse if descending
2931
- if ( m [ 2 ] === 'descending' ) {
2951
+ if ( match [ 2 ] === 'descending' ) {
2932
2952
ax . _initialCategories . reverse ( ) ;
2933
2953
}
2934
2954
0 commit comments