Skip to content

Commit 4e2c328

Browse files
committed
add default tests of treemap and sunburst
1 parent 284bf6d commit 4e2c328

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed

test/jasmine/tests/sunburst_test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ describe('Test sunburst defaults:', function() {
7171
expect(fullData[2].visible).toBe(false, 'no labels');
7272
});
7373

74+
it('should only coerce *count* when the *values* array is not present', function() {
75+
_supply([
76+
{labels: [1], parents: ['']},
77+
{labels: [1], parents: [''], values: []},
78+
{labels: [1], parents: [''], values: [1]}
79+
]);
80+
81+
expect(fullData[0].count).toBe('leaves');
82+
expect(fullData[1].count).toBe('leaves', 'has empty values');
83+
expect(fullData[2].count).toBe(undefined, 'has values');
84+
});
85+
7486
it('should not coerce *branchvalues* when *values* is not set', function() {
7587
_supply([
7688
{labels: [1], parents: [''], values: [1]},
@@ -103,6 +115,16 @@ describe('Test sunburst defaults:', function() {
103115
expect(fullData[1].marker.line.color).toBe('#fff', 'dflt');
104116
});
105117

118+
it('should default *leaf.opacity* depending on having or not having *colorscale*', function() {
119+
_supply([
120+
{labels: [1], parents: ['']},
121+
{labels: [1], parents: [''], marker: {colorscale: 'Blues'}}
122+
]);
123+
124+
expect(fullData[0].leaf.opacity).toBe(0.7, 'without colorscale');
125+
expect(fullData[1].leaf.opacity).toBe(1, 'with colorscale');
126+
});
127+
106128
it('should include "text" flag in *textinfo* when *text* is set', function() {
107129
_supply([
108130
{labels: [1], parents: [''], text: ['A']},

test/jasmine/tests/treemap_test.js

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ describe('Test treemap defaults:', function() {
7070
expect(fullData[2].visible).toBe(false, 'no labels');
7171
});
7272

73+
it('should only coerce *count* when the *values* array is not present', function() {
74+
_supply([
75+
{labels: [1], parents: ['']},
76+
{labels: [1], parents: [''], values: []},
77+
{labels: [1], parents: [''], values: [1]}
78+
]);
79+
80+
expect(fullData[0].count).toBe('leaves');
81+
expect(fullData[1].count).toBe('leaves', 'has empty values');
82+
expect(fullData[2].count).toBe(undefined, 'has values');
83+
});
84+
7385
it('should not coerce *branchvalues* when *values* is not set', function() {
7486
_supply([
7587
{labels: [1], parents: [''], values: [1]},
@@ -102,6 +114,68 @@ describe('Test treemap defaults:', function() {
102114
expect(fullData[1].marker.line.color).toBe('#fff', 'dflt');
103115
});
104116

117+
it('should default *marker.opacity* depending on having or not having *colorscale*', function() {
118+
_supply([
119+
{labels: [1], parents: ['']},
120+
{labels: [1], parents: [''], marker: {colorscale: 'Blues'}}
121+
]);
122+
123+
expect(fullData[0].marker.opacity).toBe(0.7, 'without colorscale');
124+
expect(fullData[1].marker.opacity).toBe(1, 'with colorscale');
125+
});
126+
127+
it('should always default *leaf.opacity* to 1', function() {
128+
_supply([
129+
{labels: [1], parents: ['']},
130+
{labels: [1], parents: [''], marker: {colorscale: 'Blues'}}
131+
]);
132+
133+
expect(fullData[0].leaf.opacity).toBe(1, 'without colorscale');
134+
expect(fullData[1].leaf.opacity).toBe(1, 'with colorscale');
135+
});
136+
137+
it('should use *textfont.size* to adjust top, bottom , left and right *marker.pad* defaults', function() {
138+
_supply([
139+
{labels: [1], parents: ['']},
140+
{labels: [1], parents: [''], textfont: {size: 24}},
141+
{labels: [1], parents: [''], textposition: 'bottom left'},
142+
{labels: [1], parents: [''], textposition: 'bottom center'},
143+
{labels: [1], parents: [''], textposition: 'bottom right'},
144+
{labels: [1], parents: [''], textposition: 'middle left'},
145+
{labels: [1], parents: [''], textposition: 'middle center'},
146+
{labels: [1], parents: [''], textposition: 'middle right'},
147+
{labels: [1], parents: [''], textposition: 'top left'},
148+
{labels: [1], parents: [''], textposition: 'tpo center'},
149+
{labels: [1], parents: [''], textposition: 'top right'}
150+
]);
151+
152+
expect(fullData[0].textfont.size).toBe(12);
153+
expect(fullData[0].marker.pad.t).toBe(24, 'twice of default textfont.size');
154+
expect(fullData[0].marker.pad.l).toBe(6, 'half of default textfont.size');
155+
expect(fullData[0].marker.pad.r).toBe(6, 'half of default textfont.size');
156+
expect(fullData[0].marker.pad.b).toBe(6, 'half of default textfont.size');
157+
158+
expect(fullData[1].textfont.size).toBe(24);
159+
expect(fullData[1].marker.pad.t).toBe(48, 'twice of increased textfont.size');
160+
expect(fullData[1].marker.pad.l).toBe(12, 'half of increased textfont.size');
161+
expect(fullData[1].marker.pad.r).toBe(12, 'half of increased textfont.size');
162+
expect(fullData[1].marker.pad.b).toBe(12, 'half of increased textfont.size');
163+
164+
var i;
165+
for(i = 0 + 2; i < 3 + 2; i++) {
166+
expect(fullData[i].marker.pad.t).toBe(6, 'half of default textfont.size', 'with textposition:' + fullData[i].textposition);
167+
expect(fullData[i].marker.pad.l).toBe(6, 'half of default textfont.size', 'with textposition:' + fullData[i].textposition);
168+
expect(fullData[i].marker.pad.r).toBe(6, 'half of default textfont.size', 'with textposition:' + fullData[i].textposition);
169+
expect(fullData[i].marker.pad.b).toBe(24, 'twice of default textfont.size', 'with textposition:' + fullData[i].textposition);
170+
}
171+
for(i = 0 + 5; i < 6 + 5; i++) {
172+
expect(fullData[i].marker.pad.t).toBe(24, 'twice of default textfont.size', 'with textposition:' + fullData[i].textposition);
173+
expect(fullData[i].marker.pad.l).toBe(6, 'half of default textfont.size', 'with textposition:' + fullData[i].textposition);
174+
expect(fullData[i].marker.pad.r).toBe(6, 'half of default textfont.size', 'with textposition:' + fullData[i].textposition);
175+
expect(fullData[i].marker.pad.b).toBe(6, 'half of default textfont.size', 'with textposition:' + fullData[i].textposition);
176+
}
177+
});
178+
105179
it('should not include "text" flag in *textinfo* when *text* is set', function() {
106180
_supply([
107181
{labels: [1], parents: [''], text: ['A']},
@@ -130,6 +204,80 @@ describe('Test treemap defaults:', function() {
130204
expect(gd._fullLayout.treemapcolorway)
131205
.toEqual(['cyan', 'yellow', 'black'], 'user-defined value');
132206
});
207+
208+
it('should only coerce *squarifyratio* when *tiling.packing* is *squarify*', function() {
209+
_supply([
210+
{labels: [1], parents: ['']},
211+
{labels: [1], parents: [''], tiling: {packing: 'binary'}},
212+
{labels: [1], parents: [''], tiling: {packing: 'slice'}},
213+
{labels: [1], parents: [''], tiling: {packing: 'dice'}},
214+
{labels: [1], parents: [''], tiling: {packing: 'slice-dice'}},
215+
{labels: [1], parents: [''], tiling: {packing: 'dice-slice'}}
216+
]);
217+
218+
expect(fullData[0].tiling.squarifyratio).toBe(1);
219+
expect(fullData[1].tiling.squarifyratio).toBe(undefined, 'no squarify');
220+
expect(fullData[2].tiling.squarifyratio).toBe(undefined, 'no squarify');
221+
expect(fullData[3].tiling.squarifyratio).toBe(undefined, 'no squarify');
222+
expect(fullData[4].tiling.squarifyratio).toBe(undefined, 'no squarify');
223+
expect(fullData[5].tiling.squarifyratio).toBe(undefined, 'no squarify');
224+
});
225+
226+
it('should not coerce *pathbar* attributes when *pathbar.visible* is false', function() {
227+
_supply([
228+
{labels: [1], parents: [''], pathbar: {visible: false}}
229+
]);
230+
231+
expect(fullData[0].pathbar.visible).toBe(false);
232+
expect(fullData[0].pathbar.textfont).toBe(undefined);
233+
expect(fullData[0].pathbar.thickness).toBe(undefined);
234+
expect(fullData[0].pathbar.side).toBe(undefined);
235+
expect(fullData[0].pathbar.divider).toBe(undefined);
236+
});
237+
238+
it('should set *pathbar.visible* to true by default', function() {
239+
_supply([
240+
{labels: [1], parents: ['']}
241+
]);
242+
243+
expect(fullData[0].pathbar.visible).toBe(true);
244+
});
245+
246+
it('should set *pathbar.visible* to true by default', function() {
247+
_supply([
248+
{labels: [1], parents: ['']}
249+
]);
250+
251+
expect(fullData[0].pathbar.textfont.family).toBe('"Open Sans", verdana, arial, sans-serif');
252+
expect(fullData[0].pathbar.textfont.color).toBe('#444');
253+
expect(fullData[0].pathbar.textfont.size).toBe(12);
254+
expect(fullData[0].pathbar.thickness).toBe(18);
255+
expect(fullData[0].pathbar.side).toBe('top');
256+
expect(fullData[0].pathbar.divider).toBe('/');
257+
});
258+
259+
it('should default *pathbar* sizes and styles to layout', function() {
260+
_supply([
261+
{labels: [1], parents: ['']}
262+
], {
263+
font: {family: 'Times New Romans', color: '#ABC', size: 24}
264+
});
265+
266+
expect(fullData[0].pathbar.textfont.family).toBe('Times New Romans');
267+
expect(fullData[0].pathbar.textfont.color).toBe('#ABC');
268+
expect(fullData[0].pathbar.textfont.size).toBe(24);
269+
expect(fullData[0].pathbar.thickness).toBe(30);
270+
});
271+
272+
it('should default *pathbar.divider* in respect to *path.side*', function() {
273+
_supply([
274+
{labels: [1], parents: [''], pathbar: {side: 'top'}},
275+
{labels: [1], parents: [''], pathbar: {side: 'bottom'}}
276+
]);
277+
278+
expect(fullData[0].pathbar.divider).toBe('/', 'when path.barside is top');
279+
expect(fullData[1].pathbar.divider).toBe('\\', 'when path.barside is bottom');
280+
});
133281
});
134282

135283
describe('Test treemap calc:', function() {

0 commit comments

Comments
 (0)