Skip to content

Commit 71700de

Browse files
committed
2nd cut violin jasmine tests
1 parent 17f65d0 commit 71700de

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

test/jasmine/tests/violin_test.js

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Plots = require('@src/plots/plots');
44

55
var Violin = require('@src/traces/violin');
66

7+
var d3 = require('d3');
78
var createGraphDiv = require('../assets/create_graph_div');
89
var destroyGraphDiv = require('../assets/destroy_graph_div');
910
var fail = require('../assets/fail_test');
@@ -187,6 +188,46 @@ describe('Test violin calc:', function() {
187188
expect(cd[0].span).toBeCloseToArray([0, 4.28], 'defaults to soft bound');
188189
});
189190

191+
it('should honor set bandwidth in span calculations', function() {
192+
var y = [1, 1, 2, 2, 3];
193+
var bw = 0.1;
194+
195+
_calc({
196+
y: y,
197+
bandwidth: bw
198+
});
199+
expect(cd[0].bandwidth).toBeCloseTo(0.1);
200+
expect(cd[0].span).toBeCloseToArray([0.8, 3.2]);
201+
202+
_calc({
203+
y: y,
204+
bandwidth: bw,
205+
spanmode: 'hard'
206+
});
207+
expect(cd[0].span).toBeCloseToArray([1, 3]);
208+
209+
_calc({
210+
y: y,
211+
bandwidth: bw,
212+
span: [0, 0]
213+
});
214+
expect(cd[0].span).toBeCloseToArray([-1, 1], 'cleans up invalid range');
215+
216+
_calc({
217+
y: y,
218+
bandwidth: bw,
219+
span: [null, 5]
220+
});
221+
expect(cd[0].span).toBeCloseToArray([0.8, 5], 'defaults to soft bound');
222+
223+
_calc({
224+
y: y,
225+
bandwidth: bw,
226+
span: [0, null]
227+
});
228+
expect(cd[0].span).toBeCloseToArray([0, 3.2], 'defaults to soft bound');
229+
});
230+
190231
it('should fill in scale-group stats', function() {
191232
_calc({
192233
name: 'one',
@@ -345,10 +386,89 @@ describe('Test violin hover:', function() {
345386
pos: [180, 240],
346387
nums: 'look:0.7',
347388
name: ''
389+
}, {
390+
desc: 'one-sided violin under hovermode closest',
391+
// hoveron: 'kde+points'
392+
// hovermode: 'closest'
393+
// width: 400
394+
// height: 700
395+
mock: require('@mocks/violin_side-by-side.json'),
396+
pos: [250, 300],
397+
nums: '(x: 42.43046, kde: 0.083, Saturday)',
398+
name: ''
399+
}, {
400+
desc: 'one-sided violin under hovermode y',
401+
// hoveron: 'kde+points'
402+
// width: 400
403+
// height: 700
404+
mock: require('@mocks/violin_side-by-side.json'),
405+
patch: function(fig) {
406+
fig.layout.hovermode = 'y';
407+
return fig;
408+
},
409+
pos: [250, 300],
410+
nums: 'x: 42.43046, kde: 0.083',
411+
name: '',
412+
axis: 'Saturday'
348413
}]
349414
.forEach(function(specs) {
350415
it('should generate correct hover labels ' + specs.desc, function(done) {
351416
run(specs).catch(fail).then(done);
352417
});
353418
});
419+
420+
describe('KDE lines inside violin under *kde* hoveron flag', function() {
421+
var fig;
422+
423+
beforeEach(function() {
424+
gd = createGraphDiv();
425+
426+
fig = Lib.extendDeep({}, require('@mocks/violin_old-faithful.json'), {
427+
layout: {width: 500, height: 500}
428+
});
429+
fig.data[0].points = false;
430+
});
431+
432+
function assertViolinHoverLine(pos) {
433+
var line = d3.select('.hoverlayer').selectAll('line');
434+
435+
expect(line.size()).toBe(1, 'only one violin line at a time');
436+
expect(line.attr('class').indexOf('violinline')).toBe(0, 'correct class name');
437+
expect([
438+
line.attr('x1'), line.attr('y1'),
439+
line.attr('x2'), line.attr('y2')
440+
]).toBeCloseToArray(pos, 'line position');
441+
}
442+
443+
it('should show in two-sided base case', function(done) {
444+
Plotly.plot(gd, fig).then(function() {
445+
mouseEvent('mousemove', 250, 250);
446+
assertViolinHoverLine([299.35, 250, 200.65, 250]);
447+
})
448+
.catch(fail)
449+
.then(done);
450+
});
451+
452+
it('should show in one-sided positive case', function(done) {
453+
fig.data[0].side = 'positive';
454+
455+
Plotly.plot(gd, fig).then(function() {
456+
mouseEvent('mousemove', 300, 250);
457+
assertViolinHoverLine([299.35, 250, 250, 250]);
458+
})
459+
.catch(fail)
460+
.then(done);
461+
});
462+
463+
it('should show in one-sided negative case', function(done) {
464+
fig.data[0].side = 'negative';
465+
466+
Plotly.plot(gd, fig).then(function() {
467+
mouseEvent('mousemove', 200, 250);
468+
assertViolinHoverLine([200.65, 250, 250, 250]);
469+
})
470+
.catch(fail)
471+
.then(done);
472+
});
473+
});
354474
});

0 commit comments

Comments
 (0)