Skip to content

Commit 121db9c

Browse files
committed
violin: handle data with zero standard deviation
1 parent 7e68a2e commit 121db9c

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/traces/violin/calc.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,15 @@ function silvermanRule(len, ssd, iqr) {
100100
function calcBandwidth(trace, cdi, vals) {
101101
var span = cdi.max - cdi.min;
102102

103-
// plot single-value violin with bandwidth of 1
104-
if(!span) return 1;
103+
// If span is zero
104+
if(!span) {
105+
if(trace.bandwidth) {
106+
return trace.bandwidth;
107+
} else {
108+
// plot single-value violin with bandwidth of 1
109+
return 1;
110+
}
111+
}
105112

106113
// Limit how small the bandwidth can be.
107114
//
22.8 KB
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"data": [{
3+
"type": "violin",
4+
"y": [0, 0, 0, 0],
5+
"points": "all",
6+
"pointpos": 0,
7+
"bandwidth": 0.025,
8+
"meanline": {
9+
"visible": true
10+
}
11+
}, {
12+
"type": "violin",
13+
"y": [2, 2, 2, 2],
14+
"points": "all",
15+
"bandwidth": 0.1,
16+
"pointpos": 0
17+
}, {
18+
"type": "violin",
19+
"y": [0, 1, 1.5, 2],
20+
"points": "all",
21+
"pointpos": 0
22+
}]
23+
}

0 commit comments

Comments
 (0)