Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/traces/violin/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ function silvermanRule(len, ssd, iqr) {
function calcBandwidth(trace, cdi, vals) {
var span = cdi.max - cdi.min;

// plot single-value violin with bandwidth of 1
if(!span) return 1;

// Limit how small the bandwidth can be.
//
// Silverman's rule of thumb can be "very" small
Expand Down
19 changes: 19 additions & 0 deletions test/jasmine/tests/violin_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,25 @@ describe('Test violin calc:', function() {
expect(fullLayout._violinScaleGroupStats.one.maxWidth).toBeCloseTo(0.055);
expect(fullLayout._violinScaleGroupStats.one.maxCount).toBe(8);
});

it('handle multi-box / single-value case', function() {
_calc({
x: [1, 2, 3, 4, 5, 6],
y: [1, 2, 3, 4, 5, 6]
});

expect(cd.length).toBe(6, '# of violins');
expect(cd.every(function(d) { return d.bandwidth; })).toBe(true, 'bandwidth');
});

it('handle multi-value / single-but-unique-value case', function() {
_calc({
y: [1, 1, 1, 1, 1]
});

expect(cd.length).toBe(1, '# of violins');
expect(cd[0].bandwidth).toBe(1, 'bandwidth');
});
});

describe('Test violin hover:', function() {
Expand Down