| 119188 | // Based on Leland Wilkinson, Dot Plots, The American Statistician, 1999. |
| 119189 | // https://www.cs.uic.edu/~wilkinson/Publications/dotplots.pdf |
| 119190 | function dotbin(array, step, smooth, f) { |
| 119191 | f = f || ((_)=>_); |
| 119192 | const n = array.length, v = new Float64Array(n); |
| 119193 | let i = 0, j = 1, a = f(array[0]), b = a, w = a + step, x; |
| 119194 | for(; j < n; ++j){ |
| 119195 | x = f(array[j]); |
| 119196 | if (x >= w) { |
| 119197 | b = (a + b) / 2; |
| 119198 | for(; i < j; ++i)v[i] = b; |
| 119199 | w = x + step; |
| 119200 | a = x; |
| 119201 | } |
| 119202 | b = x; |
| 119203 | } |
| 119204 | b = (a + b) / 2; |
| 119205 | for(; i < j; ++i)v[i] = b; |
| 119206 | return smooth ? smoothing(v, step + step / 4) : v; |
| 119207 | } // perform smoothing to reduce variance |
| 119208 | // swap points between "adjacent" stacks |
| 119209 | // Wilkinson defines adjacent as within step/4 units |
| 119210 | function smoothing(v, thresh) { |