MCPcopy Create free account
hub / github.com/breck7/scroll / density

Function density

external/.d3.js:6610–6741  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6608}
6609
6610function density() {
6611 var x = defaultX$1,
6612 y = defaultY$1,
6613 weight = defaultWeight,
6614 dx = 960,
6615 dy = 500,
6616 r = 20, // blur radius
6617 k = 2, // log2(grid cell size)
6618 o = r * 3, // grid offset, to pad for blur
6619 n = (dx + o * 2) >> k, // grid width
6620 m = (dy + o * 2) >> k, // grid height
6621 threshold = constant$5(20);
6622
6623 function grid(data) {
6624 var values = new Float32Array(n * m),
6625 pow2k = Math.pow(2, -k),
6626 i = -1;
6627
6628 for (const d of data) {
6629 var xi = (x(d, ++i, data) + o) * pow2k,
6630 yi = (y(d, i, data) + o) * pow2k,
6631 wi = +weight(d, i, data);
6632 if (wi && xi >= 0 && xi < n && yi >= 0 && yi < m) {
6633 var x0 = Math.floor(xi),
6634 y0 = Math.floor(yi),
6635 xt = xi - x0 - 0.5,
6636 yt = yi - y0 - 0.5;
6637 values[x0 + y0 * n] += (1 - xt) * (1 - yt) * wi;
6638 values[x0 + 1 + y0 * n] += xt * (1 - yt) * wi;
6639 values[x0 + 1 + (y0 + 1) * n] += xt * yt * wi;
6640 values[x0 + (y0 + 1) * n] += (1 - xt) * yt * wi;
6641 }
6642 }
6643
6644 blur2({data: values, width: n, height: m}, r * pow2k);
6645 return values;
6646 }
6647
6648 function density(data) {
6649 var values = grid(data),
6650 tz = threshold(values),
6651 pow4k = Math.pow(2, 2 * k);
6652
6653 // Convert number of thresholds into uniform thresholds.
6654 if (!Array.isArray(tz)) {
6655 tz = ticks(Number.MIN_VALUE, max$3(values) / pow4k, tz);
6656 }
6657
6658 return Contours()
6659 .size([n, m])
6660 .thresholds(tz.map(d => d * pow4k))
6661 (values)
6662 .map((c, i) => (c.value = +tz[i], transform(c)));
6663 }
6664
6665 density.contours = function(data) {
6666 var values = grid(data),
6667 contours = Contours().size([n, m]),

Callers

nothing calls this directly

Calls 10

constant$5Function · 0.85
gridFunction · 0.85
thresholdFunction · 0.85
ticksFunction · 0.85
max$3Function · 0.85
ContoursFunction · 0.85
resizeFunction · 0.85
mapMethod · 0.80
logMethod · 0.80
transformFunction · 0.70

Tested by

no test coverage detected