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 9899a63

Browse filesBrowse files
committed
sort categories by value: add support for splom
1 parent 4afbefc commit 9899a63
Copy full SHA for 9899a63

File tree

2 files changed

+51
-32
lines changed
Filter options

2 files changed

+51
-32
lines changed

‎src/plots/plots.js

Copy file name to clipboardExpand all lines: src/plots/plots.js
+44-25Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,35 +2889,54 @@ function sortAxisCategoriesByValue(axList, gd) {
28892889
var cd = gd.calcdata[traceIndex];
28902890
for(k = 0; k < cd.length; k++) {
28912891
var cdi = cd[k];
2892-
var cat, value, orientation;
2893-
2894-
if(ax._id.charAt(0) === 'x') {
2895-
cat = cdi.p + 1 ? cdi.p : cdi.x;
2896-
value = cdi.s || cdi.v || cdi.y;
2897-
// orientation = 'h';
2898-
} else if(ax._id.charAt(0) === 'y') {
2899-
cat = cdi.p + 1 ? cdi.p : cdi.y;
2900-
value = cdi.s || cdi.v || cdi.x;
2901-
// orientation = 'v';
2902-
}
2903-
orientation = fullData.orientation || 'v';
2892+
var cat, catIndex, value, orientation;
2893+
2894+
// Collect values across dimensions
2895+
if(fullData.type === 'splom') {
2896+
// Find which dimension the current axis is mapped
2897+
var currentDimensionIndex = cdi.trace[ax._id.charAt(0) + 'axes'].indexOf(ax._id);
2898+
2899+
var categories = cdi.trace.dimensions[currentDimensionIndex].values;
2900+
for(l = 0; l < categories.length; l++) {
2901+
cat = categories[l];
2902+
catIndex = ax._categoriesMap[cat];
2903+
2904+
// Collect values over all dimensions
2905+
for(o = 0; o < cdi.trace.dimensions.length; o++) {
2906+
if(o === currentDimensionIndex) continue;
2907+
var dimension = cdi.trace.dimensions[o];
2908+
categoriesValue[catIndex][1].push(dimension.values[l]);
2909+
}
2910+
}
2911+
} else {
2912+
if(ax._id.charAt(0) === 'x') {
2913+
cat = cdi.p + 1 ? cdi.p : cdi.x;
2914+
value = cdi.s || cdi.v || cdi.y;
2915+
// orientation = 'h';
2916+
} else if(ax._id.charAt(0) === 'y') {
2917+
cat = cdi.p + 1 ? cdi.p : cdi.y;
2918+
value = cdi.s || cdi.v || cdi.x;
2919+
// orientation = 'v';
2920+
}
2921+
orientation = fullData.orientation || 'v';
29042922

2905-
var twoDim = false;
2906-
if(cdi.hasOwnProperty('z')) {
2907-
value = cdi.z;
2908-
twoDim = true;
2909-
}
2923+
var twoDim = false;
2924+
if(cdi.hasOwnProperty('z')) {
2925+
value = cdi.z;
2926+
twoDim = true;
2927+
}
29102928

2911-
if(twoDim) {
2912-
for(l = 0; l < value.length; l++) {
2913-
for(o = 0; o < value[l].length; o++) {
2914-
var catIndex = orientation === 'v' ? o : l;
2915-
if(catIndex > categoriesValue.length - 1) continue;
2916-
categoriesValue[catIndex][1].push(value[l][o]);
2929+
if(twoDim) {
2930+
for(l = 0; l < value.length; l++) {
2931+
for(o = 0; o < value[l].length; o++) {
2932+
catIndex = orientation === 'v' ? o : l;
2933+
if(catIndex > categoriesValue.length - 1) continue;
2934+
categoriesValue[catIndex][1].push(value[l][o]);
2935+
}
29172936
}
2937+
} else {
2938+
categoriesValue[cat][1].push(value);
29182939
}
2919-
} else {
2920-
categoriesValue[cat][1].push(value);
29212940
}
29222941
}
29232942
}

‎test/jasmine/tests/calcdata_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/calcdata_test.js
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ describe('calculated data and points', function() {
872872
});
873873
});
874874

875-
describe('ordering tests for categories', function() {
875+
describe('by value', function() {
876876
var schema = Plotly.PlotSchema.get();
877877
var traces = Object.keys(schema.traces);
878878
var tracesSchema = [];
@@ -885,7 +885,7 @@ describe('calculated data and points', function() {
885885
});
886886

887887
var excludedTraces = [
888-
'carpet', 'contourcarpet', 'splom',
888+
'carpet', 'contourcarpet',
889889
// TODO: add support for the following
890890
'scattergl', 'histogram2dcontour'
891891
];
@@ -941,7 +941,7 @@ describe('calculated data and points', function() {
941941
supportedCartesianTraces
942942
.forEach(function(trace) {
943943
['value ascending', 'value descending'].forEach(function(categoryorder) {
944-
it('sort by ' + categoryorder + ' for trace type ' + trace.type, function(done) {
944+
it('sorts ' + trace.type + ' by ' + categoryorder, function(done) {
945945
var baseMock = {
946946
data: [makeData(trace.type, cat, data)],
947947
layout: {
@@ -971,7 +971,7 @@ describe('calculated data and points', function() {
971971
});
972972
});
973973

974-
it('aggregates values per category for trace type ' + trace.type, function(done) {
974+
it('aggregates all values in trace type ' + trace.type, function(done) {
975975
var type = trace.type;
976976
var baseMock = {
977977
data: [makeData(trace.type, cat, data)],
@@ -1003,7 +1003,7 @@ describe('calculated data and points', function() {
10031003
.then(done);
10041004
});
10051005

1006-
it('aggregates values per category across multiple trace type ' + trace.type, function(done) {
1006+
it('aggregates all values across multiple traces of type ' + trace.type, function(done) {
10071007
var type = trace.type;
10081008
var baseMock = {
10091009
data: [makeData(type, cat, data)],
@@ -1041,7 +1041,7 @@ describe('calculated data and points', function() {
10411041
.then(done);
10421042
});
10431043

1044-
it('aggregates minimum values per category across multiple trace type ' + trace.type, function(done) {
1044+
it('finds the minimum value per category across multiple traces of type ' + trace.type, function(done) {
10451045
var type = trace.type;
10461046
var baseMock = {
10471047
data: [makeData(trace.type, cat, data)],
@@ -1081,7 +1081,7 @@ describe('calculated data and points', function() {
10811081
.then(done);
10821082
});
10831083

1084-
it('aggregates maximum values per category across multiple trace type ' + trace.type, function(done) {
1084+
it('finds the maximum value per category across multiple traces of type ' + trace.type, function(done) {
10851085
var type = trace.type;
10861086
var baseMock = {
10871087
data: [makeData(trace.type, cat, data)],

0 commit comments

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