Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d5a8770

Browse filesBrowse files
committed
sort categories by value: add support for histogram2d
1 parent 16caa35 commit d5a8770
Copy full SHA for d5a8770

File tree

Expand file treeCollapse file tree

1 file changed

+32
-12
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+32
-12
lines changed

‎src/plots/plots.js

Copy file name to clipboardExpand all lines: src/plots/plots.js
+32-12Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,14 +2860,15 @@ var sortAxisCategoriesByValueRegex = /(value|sum|min|max) (ascending|descending)
28602860

28612861
function sortAxisCategoriesByValue(axList, gd) {
28622862
var sortByValue = [];
2863-
var i, j, k;
2863+
var i, j, k, l, o;
28642864
for(i = 0; i < axList.length; i++) {
28652865
var ax = axList[i];
28662866
if(ax.type !== 'category') continue;
28672867

28682868
// 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);
28712872
// Store values associated with each category
28722873
var categoriesValue = [];
28732874
for(j = 0; j < ax._categories.length; j++) {
@@ -2876,7 +2877,7 @@ function sortAxisCategoriesByValue(axList, gd) {
28762877

28772878
// Collect values across traces
28782879
for(j = 0; j < ax._traceIndices.length; j++) {
2879-
// Keep track of traces we sort!
2880+
// Keep track of traces affected by this function
28802881
var traceIndex = ax._traceIndices[j];
28812882
sortByValue.push(traceIndex);
28822883

@@ -2888,21 +2889,40 @@ function sortAxisCategoriesByValue(axList, gd) {
28882889

28892890
var cd = gd.calcdata[traceIndex];
28902891
for(k = 0; k < cd.length; k++) {
2891-
var cat, value;
2892+
var cdi = cd[k];
2893+
var cat, value, orientation;
2894+
28922895
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';
28952899
} 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);
28982919
}
2899-
categoriesValue[cat][1].push(value);
29002920
}
29012921
}
29022922

29032923
// Aggregate values
29042924
var aggFn;
2905-
switch(m[1]) {
2925+
switch(match[1]) {
29062926
case 'min':
29072927
aggFn = Math.min;
29082928
break;
@@ -2928,7 +2948,7 @@ function sortAxisCategoriesByValue(axList, gd) {
29282948
});
29292949

29302950
// Reverse if descending
2931-
if(m[2] === 'descending') {
2951+
if(match[2] === 'descending') {
29322952
ax._initialCategories.reverse();
29332953
}
29342954

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.