Skip to content

Commit bb64307

Browse files
committed
fallbacks for jitter algo with no IQR and lots of duplicate points
1 parent ce8674f commit bb64307

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/traces/box/plot.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ module.exports = function plot(gd, plotinfo, cdbox) {
132132
.data(function(d) {
133133
var pts = (trace.boxpoints === 'all') ? d.val :
134134
d.val.filter(function(v) { return (v < d.lf || v > d.uf); }),
135-
spreadLimit = (d.q3 - d.q1) * JITTERSPREAD,
135+
// normally use IQR, but if this is 0 or too small, use max-min
136+
typicalSpread = Math.max((d.max - d.min) / 10, d.q3 - d.q1),
137+
spreadLimit = typicalSpread * JITTERSPREAD,
136138
jitterFactors = [],
137139
maxJitterFactor = 0,
138140
i,
@@ -155,7 +157,7 @@ module.exports = function plot(gd, plotinfo, cdbox) {
155157
else pmin = Math.max(pmin, d.uf);
156158
}
157159

158-
jitterFactor = Math.sqrt(spreadLimit * (i1 - i0) / (pmax - pmin)) || 0;
160+
jitterFactor = Math.sqrt(spreadLimit * (i1 - i0) / (pmax - pmin + 1e-9)) || 0;
159161
jitterFactor = Lib.constrain(Math.abs(jitterFactor), 0, 1);
160162

161163
jitterFactors.push(jitterFactor);

0 commit comments

Comments
 (0)