Skip to content

Commit 9cac919

Browse files
committed
first cut splom defaults test
1 parent 89fb6bb commit 9cac919

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

test/jasmine/tests/splom_test.js

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
var Lib = require('@src/lib');
2+
var supplyAllDefaults = require('../assets/supply_defaults');
3+
4+
describe('Test splom trace defaults:', function() {
5+
var gd;
6+
7+
function _supply(opts, layout) {
8+
gd = {};
9+
opts = Array.isArray(opts) ? opts : [opts];
10+
11+
gd.data = opts.map(function(o) {
12+
return Lib.extendFlat({type: 'splom'}, o || {});
13+
});
14+
gd.layout = layout || {};
15+
16+
supplyAllDefaults(gd);
17+
}
18+
19+
it('should set to `visible: false` dimensions-less traces', function() {
20+
_supply([{}, {dimensions: []}]);
21+
22+
expect(gd._fullData[0].visible).toBe(false);
23+
expect(gd._fullData[1].visible).toBe(false);
24+
});
25+
26+
it('should set to `visible: false` to values-less dimensions', function() {
27+
_supply({
28+
dimensions: [
29+
'not-an-object',
30+
{other: 'stuff'}
31+
]
32+
});
33+
34+
expect(gd._fullData[0].dimensions[0].visible).toBe(false);
35+
expect(gd._fullData[0].dimensions[1].visible).toBe(false);
36+
});
37+
38+
it('should work with only one dimensions', function() {
39+
_supply({
40+
dimensions: [
41+
{values: [2, 1, 2]}
42+
]
43+
});
44+
45+
var fullLayout = gd._fullLayout;
46+
expect(fullLayout.xaxis.domain).toBeCloseToArray([0, 1]);
47+
expect(fullLayout.yaxis.domain).toBeCloseToArray([0, 1]);
48+
});
49+
50+
it('should set `grid.xaxes` and `grid.yaxes` default using the new of dimensions', function() {
51+
_supply({
52+
dimensions: [
53+
{values: [1, 2, 3]},
54+
{values: [2, 1, 2]}
55+
]
56+
});
57+
58+
var fullTrace = gd._fullData[0];
59+
expect(fullTrace._commonLength).toBe(3, 'common length');
60+
expect(fullTrace.dimensions[0]._length).toBe(3, 'dim 0 length');
61+
expect(fullTrace.dimensions[1]._length).toBe(3, 'dim 1 length');
62+
expect(fullTrace.xaxes).toEqual(['x', 'x2']);
63+
expect(fullTrace.yaxes).toEqual(['y', 'y2']);
64+
65+
var fullLayout = gd._fullLayout;
66+
expect(fullLayout.xaxis.domain).toBeCloseToArray([0, 0.47]);
67+
expect(fullLayout.yaxis.domain).toBeCloseToArray([0.53, 1]);
68+
expect(fullLayout.xaxis2.domain).toBeCloseToArray([0.53, 1]);
69+
expect(fullLayout.yaxis2.domain).toBeCloseToArray([0, 0.47]);
70+
71+
var subplots = fullLayout._subplots;
72+
expect(subplots.xaxis).toEqual(['x', 'x2']);
73+
expect(subplots.yaxis).toEqual(['y', 'y2']);
74+
expect(subplots.cartesian).toEqual(['xy', 'xy2', 'x2y', 'x2y2']);
75+
});
76+
77+
it('should honor `grid.xaxes` and `grid.yaxes` settings', function() {
78+
_supply({
79+
dimensions: [
80+
{values: [1, 2, 3]},
81+
{values: [2, 1, 2]}
82+
]
83+
}, {
84+
grid: {domain: {x: [0, 0.5], y: [0, 0.5]}}
85+
});
86+
87+
var fullLayout = gd._fullLayout;
88+
expect(fullLayout.xaxis.domain).toBeCloseToArray([0, 0.24]);
89+
expect(fullLayout.yaxis.domain).toBeCloseToArray([0.26, 0.5]);
90+
expect(fullLayout.xaxis2.domain).toBeCloseToArray([0.26, 0.5]);
91+
expect(fullLayout.yaxis2.domain).toBeCloseToArray([0, 0.24]);
92+
});
93+
94+
it('should honor xaxis and yaxis settings', function() {
95+
_supply({
96+
dimensions: [
97+
{values: [1, 2, 3]},
98+
{values: [2, 1, 2]}
99+
]
100+
}, {
101+
xaxis: {domain: [0, 0.4]},
102+
yaxis2: {domain: [0, 0.3]}
103+
});
104+
105+
var fullLayout = gd._fullLayout;
106+
expect(fullLayout.xaxis.domain).toBeCloseToArray([0, 0.4]);
107+
expect(fullLayout.yaxis.domain).toBeCloseToArray([0.53, 1]);
108+
expect(fullLayout.xaxis2.domain).toBeCloseToArray([0.53, 1]);
109+
expect(fullLayout.yaxis2.domain).toBeCloseToArray([0, 0.3]);
110+
});
111+
112+
it('should set axis title default using dimensions *label*', function() {
113+
_supply({
114+
dimensions: [{
115+
label: 'A',
116+
values: [2, 3, 1]
117+
}, {
118+
label: 'B',
119+
values: [1, 2, 1]
120+
}]
121+
});
122+
123+
var fullLayout = gd._fullLayout;
124+
expect(fullLayout.xaxis.title).toBe('A');
125+
expect(fullLayout.yaxis.title).toBe('A');
126+
expect(fullLayout.xaxis2.title).toBe('B');
127+
expect(fullLayout.yaxis2.title).toBe('B');
128+
});
129+
130+
it('should lead to correct axis auto type value', function() {
131+
_supply({
132+
dimensions: [
133+
{values: ['a', 'b', 'c']},
134+
{values: ['A', 't', 'd']}
135+
]
136+
});
137+
138+
var fullLayout = gd._fullLayout;
139+
expect(fullLayout.xaxis.type).toBe('category');
140+
expect(fullLayout.yaxis.type).toBe('category');
141+
});
142+
});

0 commit comments

Comments
 (0)