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 c5334df

Browse filesBrowse files
committed
sort categories by value: test data aggregation
1 parent 6b0a307 commit c5334df
Copy full SHA for c5334df

File tree

1 file changed

+90
-47
lines changed
Filter options

1 file changed

+90
-47
lines changed

‎test/jasmine/tests/calcdata_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/calcdata_test.js
+90-47Lines changed: 90 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var BADNUM = require('@src/constants/numerical').BADNUM;
44
var createGraphDiv = require('../assets/create_graph_div');
55
var destroyGraphDiv = require('../assets/destroy_graph_div');
66
var failTest = require('../assets/fail_test');
7+
var Lib = require('@src/lib');
78

89
describe('calculated data and points', function() {
910
var gd;
@@ -871,7 +872,7 @@ describe('calculated data and points', function() {
871872
});
872873
});
873874

874-
describe('should order categories per value per axis', function() {
875+
describe('ordering tests for categories', function() {
875876
var schema = Plotly.PlotSchema.get();
876877
var traces = Object.keys(schema.traces);
877878
var tracesSchema = [];
@@ -883,58 +884,100 @@ describe('calculated data and points', function() {
883884
return t.categories.length && t.categories.indexOf('cartesian') !== -1;
884885
});
885886

887+
var excludedTraces = [
888+
'carpet', 'contourcarpet', 'splom', 'funnel',
889+
// TODO: add support for the following
890+
'scattergl', 'histogram2dcontour'
891+
];
886892
var supportedCartesianTraces = cartesianTraces.filter(function(t) {
887-
if(t.type === 'scattergl' || t.type === 'carpet' ||
888-
t.type === 'contourcarpet' || t.type === 'funnel' ||
889-
t.type === 'splom' || t.type === 'histogram2dcontour') return false;
890-
return true;
891-
});
893+
if(excludedTraces.indexOf(t.type) === -1) return true;
894+
});
895+
896+
var cat = ['a', 'b', 'c'];
897+
var data = [7, 2, 3];
898+
var z = [ data, [0, 0, 0], [0, 0, 0]];
899+
900+
var baseMock = {
901+
data: [{
902+
x: cat,
903+
a: cat,
904+
905+
b: data,
906+
y: data,
907+
z: z,
908+
909+
// For OHLC
910+
open: data,
911+
close: data,
912+
high: data,
913+
low: data,
914+
915+
// For waterfall
916+
measure: ['absolute', 'absolute', 'absolute'],
917+
918+
// For splom
919+
dimensions: [
920+
{
921+
label: 'DimensionA',
922+
values: cat
923+
},
924+
{
925+
label: 'DimensionB',
926+
values: data
927+
}
928+
]
929+
}],
930+
layout: {
931+
xaxis: {
932+
type: 'category'
933+
}
934+
}
935+
};
892936

893937
supportedCartesianTraces
894938
.forEach(function(trace) {
895-
it('for trace type ' + trace.type, function(done) {
896-
var type = trace.type;
897-
var data = [7, 2, 3, 7];
898-
var cat = ['a', 'b', 'c', 'a'];
899-
var z = [ data, data, data];
900-
var finalOrder = ['b', 'c', 'a'];
901-
902-
Plotly.newPlot(gd, {
903-
data: [{
904-
type: type,
905-
x: cat,
906-
a: cat,
907-
b: data,
908-
y: data,
909-
z: z,
910-
911-
// For OHLC
912-
open: data,
913-
close: data,
914-
high: data,
915-
low: data,
916-
917-
// For splom
918-
dimensions: [
919-
{
920-
label: 'DimensionA',
921-
values: cat
922-
},
923-
{
924-
label: 'DimensionB',
925-
values: data
926-
}
927-
]
928-
}],
929-
layout: {
930-
xaxis: {
931-
type: 'category',
932-
categoryorder: 'value ascending'
933-
}
939+
['value ascending', 'value descending'].forEach(function(categoryorder) {
940+
it('sort by ' + categoryorder + ' for trace type ' + trace.type, function(done) {
941+
var type = trace.type;
942+
var mock = Lib.extendDeep({}, baseMock);
943+
mock.data[0].type = type;
944+
mock.layout.xaxis.categoryorder = categoryorder;
945+
946+
// Set ordering
947+
var finalOrder = ['b', 'c', 'a'];
948+
if(categoryorder === 'value descending') finalOrder.reverse();
949+
950+
if(type.match(/histogram/)) {
951+
mock.data[0].x.push('a');
952+
mock.data[0].y.push(7);
934953
}
935-
})
954+
955+
Plotly.newPlot(gd, mock)
956+
.then(function(gd) {
957+
expect(gd._fullLayout.xaxis._categories).toEqual(finalOrder, 'for trace ' + type);
958+
})
959+
.catch(failTest)
960+
.then(done);
961+
});
962+
});
963+
964+
it('aggregates values per category for trace type ' + trace.type, function(done) {
965+
var type = trace.type;
966+
var mock = Lib.extendDeep({}, baseMock);
967+
mock.data[0].type = type;
968+
mock.layout.xaxis.categoryorder = 'value ascending';
969+
970+
if(type.match(/histogram/)) {
971+
mock.data[0].x.push('a');
972+
mock.data[0].y.push(7);
973+
}
974+
975+
Plotly.newPlot(gd, mock)
936976
.then(function(gd) {
937-
expect(gd._fullLayout.xaxis._categories).toEqual(finalOrder, 'for trace ' + type);
977+
var agg = [['b', 2], ['c', 3], ['a', 7]];
978+
if(type === 'ohlc' || type === 'candlestick') agg = [['b', 4], ['c', 6], ['a', 14]];
979+
if(type.match(/histogram/)) agg = [['b', 1], ['c', 1], ['a', 2]];
980+
expect(gd._fullLayout.xaxis._categoriesAggregatedValue).toEqual(agg);
938981
})
939982
.catch(failTest)
940983
.then(done);

0 commit comments

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