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 04e68c3

Browse filesBrowse files
committed
sort categories by value: add jasmine tests
1 parent d5a8770 commit 04e68c3
Copy full SHA for 04e68c3

File tree

3 files changed

+51
-2
lines changed
Filter options

3 files changed

+51
-2
lines changed

‎src/plot_api/plot_schema.js

Copy file name to clipboardExpand all lines: src/plot_api/plot_schema.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ function getTraceAttributes(type) {
503503

504504
var out = {
505505
meta: _module.meta || {},
506+
categories: _module.categories || {},
507+
type: type,
506508
attributes: formatAttributes(attributes),
507509
};
508510

‎src/plots/plots.js

Copy file name to clipboardExpand all lines: src/plots/plots.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,7 +2868,6 @@ function sortAxisCategoriesByValue(axList, gd) {
28682868
// Order by value
28692869
var match = ax.categoryorder.match(sortAxisCategoriesByValueRegex);
28702870
if(match) {
2871-
console.log(ax._categories);
28722871
// Store values associated with each category
28732872
var categoriesValue = [];
28742873
for(j = 0; j < ax._categories.length; j++) {
@@ -2911,7 +2910,9 @@ function sortAxisCategoriesByValue(axList, gd) {
29112910
if(twoDim) {
29122911
for(l = 0; l < value.length; l++) {
29132912
for(o = 0; o < value[l].length; o++) {
2914-
categoriesValue[orientation === 'h' ? o : l][1].push(value[l][o]);
2913+
var catIndex = orientation === 'h' ? o : l;
2914+
if(catIndex > categoriesValue.length - 1) continue;
2915+
categoriesValue[catIndex][1].push(value[l][o]);
29152916
}
29162917
}
29172918
} else {

‎test/jasmine/tests/calcdata_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/calcdata_test.js
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,52 @@ describe('calculated data and points', function() {
869869
'b': 1
870870
});
871871
});
872+
873+
it('should order categories per value per axis', function() {
874+
var schema = Plotly.PlotSchema.get();
875+
var traces = Object.keys(schema.traces);
876+
var tracesSchema = [];
877+
var i;
878+
for(i = 0; i < traces.length; i++) {
879+
tracesSchema.push(schema.traces[traces[i]]);
880+
}
881+
var cartesianTraces = tracesSchema.filter(function(t) {
882+
return t.categories.length && t.categories.indexOf('cartesian') !== -1;
883+
});
884+
885+
var cartesianTraceNames = cartesianTraces.map(function(t) {
886+
return t.type;
887+
});
888+
889+
for(i = 0; i < cartesianTraceNames.length; i++) {
890+
var type = cartesianTraceNames[i];
891+
if(type === 'scattergl') continue;
892+
if(type === 'carpet') continue;
893+
if(type === 'contourcarpet') continue;
894+
895+
Plotly.newPlot(gd, {
896+
data: [{
897+
type: type,
898+
x: ['a', 'b', 'c', 'a'],
899+
a: ['a', 'b', 'c', 'a'],
900+
b: [7, 3, 2, 7],
901+
y: [7, 3, 2, 7],
902+
z: [7, 3, 2, 7],
903+
// For OHLC
904+
open: [7, 3, 2, 7],
905+
close: [7, 3, 2, 7],
906+
high: [7, 3, 2, 7],
907+
low: [7, 3, 2, 7]
908+
}],
909+
layout: {
910+
xaxis: {
911+
type: 'category',
912+
categoryorder: 'value ascending'
913+
}
914+
}
915+
});
916+
}
917+
});
872918
});
873919

874920
describe('customdata', function() {

0 commit comments

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