@sjcrh/proteinpaint-shared 2.109.1-0 → 2.109.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/violin.bins.js
CHANGED
|
@@ -32,7 +32,7 @@ output:
|
|
|
32
32
|
import { bin } from 'd3-array'
|
|
33
33
|
import * as d3 from 'd3'
|
|
34
34
|
|
|
35
|
-
export function getBinsDensity(
|
|
35
|
+
export function getBinsDensity(plot, isKDE = false, ticks = 20) {
|
|
36
36
|
const [valuesMin, valuesMax] = d3.extent(plot.values) //Min and max on plot
|
|
37
37
|
//Commented out as it seems to be handled by kde with automatic bandwidth
|
|
38
38
|
//if (valuesMin == valuesMax) return { bins: [{ x0: valuesMin, density: 1 }], densityMax: valuesMax, densityMin: 0}
|
|
@@ -48,12 +48,12 @@ export function getBinsDensity(scale, plot, isKDE = false, ticks = 20) {
|
|
|
48
48
|
//Divided thresholds(or bins) into 3 parts, below p2nd, between p2nd and p98, above p98. This allows to handle outliers better.
|
|
49
49
|
//When there are no outliers, p2nd and p98 will be the same or very close to valuesMin and valuesMax respectively
|
|
50
50
|
if (p2nd > valuesMin) thresholds = [...getThresholds(valuesMin, p2nd, ticks)]
|
|
51
|
-
if (p98
|
|
51
|
+
if (p98 >= p2nd) thresholds.push(...getThresholds(p2nd, p98, ticks))
|
|
52
52
|
if (p98 < valuesMax) thresholds.push(...getThresholds(p98, valuesMax, ticks))
|
|
53
53
|
|
|
54
54
|
const result = isKDE
|
|
55
55
|
? kde(gaussianKernel, thresholds, plot.values, valuesMin, valuesMax)
|
|
56
|
-
: getBinsHist(
|
|
56
|
+
: getBinsHist(plot.values, thresholds, valuesMin, valuesMax)
|
|
57
57
|
|
|
58
58
|
result.bins.unshift({ x0: valuesMin, density: result.densityMin }) //This allows to start the plot from min prob, avoids rendering issues
|
|
59
59
|
|
|
@@ -157,9 +157,9 @@ function silvermanBandwidth(data) {
|
|
|
157
157
|
return h
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
function getBinsHist(
|
|
160
|
+
function getBinsHist(values, thresholds, valuesMin, valuesMax) {
|
|
161
161
|
const binBuilder = bin()
|
|
162
|
-
.domain(
|
|
162
|
+
.domain([valuesMin, valuesMax]) /* extent of the data that is lowest to highest*/
|
|
163
163
|
.thresholds(thresholds) /* buckets are created which are separated by the threshold*/
|
|
164
164
|
.value(d => d) /* bin the data points into this bucket*/
|
|
165
165
|
const bins0 = binBuilder(values)
|