@@ -2861,6 +2861,31 @@ var sortAxisCategoriesByValueRegex = /(value|sum|min|max) (ascending|descending)
2861
2861
function sortAxisCategoriesByValue ( axList , gd ) {
2862
2862
var affectedTraces = [ ] ;
2863
2863
var i , j , k , l , o ;
2864
+
2865
+ function zMapCategory ( type , ax , value ) {
2866
+ var axLetter = ax . _id . charAt ( 0 ) ;
2867
+ if ( type === 'histogram2dcontour' ) {
2868
+ var counterAxLetter = ax . _counterAxes [ 0 ] ;
2869
+ var counterAx = axisIDs . getFromId ( gd , counterAxLetter ) ;
2870
+
2871
+ var xCategorical = axLetter === 'x' || ( counterAxLetter === 'x' && counterAx . type === 'category' ) ;
2872
+ var yCategorical = axLetter === 'y' || ( counterAxLetter === 'y' && counterAx . type === 'category' ) ;
2873
+
2874
+ return function ( o , l ) {
2875
+ if ( o === 0 || l === 0 ) return - 1 ; // Skip first row and column
2876
+ if ( xCategorical && o === value [ l ] . length - 1 ) return - 1 ;
2877
+ if ( yCategorical && l === value . length - 1 ) return - 1 ;
2878
+
2879
+ var catIndex = axLetter === 'y' ? l : o ;
2880
+ return catIndex - 1 ;
2881
+ } ;
2882
+ } else {
2883
+ return function ( o , l ) {
2884
+ return axLetter === 'y' ? l : o ;
2885
+ } ;
2886
+ }
2887
+ }
2888
+
2864
2889
for ( i = 0 ; i < axList . length ; i ++ ) {
2865
2890
var ax = axList [ i ] ;
2866
2891
if ( ax . type !== 'category' ) continue ;
@@ -2950,11 +2975,12 @@ function sortAxisCategoriesByValue(axList, gd) {
2950
2975
// If 2dMap, collect values in `z`
2951
2976
if ( cdi . hasOwnProperty ( 'z' ) ) {
2952
2977
value = cdi . z ;
2978
+ var mapping = zMapCategory ( fullTrace . type , ax , value ) ;
2953
2979
2954
2980
for ( l = 0 ; l < value . length ; l ++ ) {
2955
2981
for ( o = 0 ; o < value [ l ] . length ; o ++ ) {
2956
- catIndex = ax . _id . charAt ( 0 ) === 'y' ? l : o ;
2957
- categoriesValue [ catIndex ] [ 1 ] . push ( value [ l ] [ o ] ) ;
2982
+ catIndex = mapping ( o , l ) ;
2983
+ if ( catIndex + 1 ) categoriesValue [ catIndex ] [ 1 ] . push ( value [ l ] [ o ] ) ;
2958
2984
}
2959
2985
}
2960
2986
} else {
0 commit comments