10000 sort categories by values: support yaxes for splom · maun/plotly.js@544618d · GitHub
[go: up one dir, main page]

Skip to content

Commit 544618d

Browse files
committed
sort categories by values: support yaxes for splom
1 parent fc1bbce commit 544618d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/plots/plots.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2895,6 +2895,14 @@ function sortAxisCategoriesByValue(axList, gd) {
28952895
// Find which dimension the current axis is representing
28962896
var currentDimensionIndex = cdi.trace[ax._id.charAt(0) + 'axes'].indexOf(ax._id);
28972897

2898+
// Apply logic to associated x axis
2899+
if(ax._id.charAt(0) === 'y') {
2900+
var associatedXAxis = ax._id.split('');
2901+
associatedXAxis[0] = 'x';
2902+
associatedXAxis = associatedXAxis.join('');
2903+
ax = gd._fullLayout[axisIDs.id2name(associatedXAxis)];
2904+
}
2905+
28982906
var categories = cdi.trace.dimensions[currentDimensionIndex].values;
28992907
for(l = 0; l < categories.length; l++) {
29002908
cat = categories[l];

test/jasmine/tests/calcdata_test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,6 @@ describe('calculated data and points', function() {
897897

898898
// oneOrientationTraces are traces for which swapping x/y is not supported
899899
var oneOrientationTraces = ['ohlc', 'candlestick'];
900-
oneOrientationTraces.push('splom'); // TODO: support splom and remove this
901900

902901
function makeData(type, a, b, axId) {
903902
var input = [a, b];
@@ -949,11 +948,11 @@ describe('calculated data and points', function() {
949948
dimensions: [
950949
{
951950
label: 'DimensionA',
952-
values: cat
951+
values: a
953952
},
954953
{
955954
label: 'DimensionB',
956-
values: data
955+
values: b
957956
}
958957
]
959958
});
@@ -963,7 +962,7 @@ describe('calculated data and points', function() {
963962
['xaxis', 'yaxis'].forEach(function(axId) {
964963
if(axId === 'yaxis' && oneOrientationTraces.indexOf(trace.type) !== -1) return;
965964
['value ascending', 'value descending'].forEach(function(categoryorder) {
966-
it('sorts ' + trace.type + ' by ' + categoryorder, function(done) {
965+
it('sorts ' + axId + ' by ' + categoryorder + 'for trace type ' + trace.type, function(done) {
967966
var data = [7, 2, 3];
968967
var baseMock = { data: [makeData(trace.type, cat, data, axId)], layout: {}};
969968
var mock = Lib.extendDeep({}, baseMock);
@@ -980,7 +979,7 @@ describe('calculated data and points', function() {
980979

981980
Plotly.newPlot(gd, mock)
982981
.then(function(gd) {
983-
expect(gd._fullLayout[axId]._categories).toEqual(finalOrder, 'for trace ' + trace.type);
982+
expect(gd._fullLayout[trace.type === 'splom' ? 'xaxis' : axId]._categories).toEqual(finalOrder, 'for trace ' + trace.type);
984983
})
985984
.catch(failTest)
986985
.then(done);
@@ -999,7 +998,7 @@ describe('calculated data and points', function() {
999998

1000999
Plotly.newPlot(gd, mock)
10011000
.then(function(gd) {
1002-
var agg = gd._fullLayout[axId]._categoriesAggregatedValue.sort(function(a, b) {
1001+
var agg = gd._fullLayout[mock.data[0].type === 'splom' ? 'xaxis' : axId]._categoriesAggregatedValue.sort(function(a, b) {
10031002
return a[0] > b[0];
10041003
});
10051004
expect(agg).toEqual(expectedAgg, 'wrong aggregation for ' + axId);

0 commit comments

Comments
 (0)
0