-
Notifications
You must be signed in to change notification settings - Fork 181
Expand file tree
/
Copy path0313c03ef89d0446a4edd70242d04ac0.json
More file actions
1 lines (1 loc) · 1.56 KB
/
0313c03ef89d0446a4edd70242d04ac0.json
File metadata and controls
1 lines (1 loc) · 1.56 KB
1
{"ast":null,"code":"import { ascending, bisect, quantile as threshold } from \"d3-array\";\nimport { slice } from \"./array\";\nimport { initRange } from \"./init\";\nexport default function quantile() {\n var domain = [],\n range = [],\n thresholds = [],\n unknown;\n\n function rescale() {\n var i = 0,\n n = Math.max(1, range.length);\n thresholds = new Array(n - 1);\n\n while (++i < n) thresholds[i - 1] = threshold(domain, i / n);\n\n return scale;\n }\n\n function scale(x) {\n return isNaN(x = +x) ? unknown : range[bisect(thresholds, x)];\n }\n\n scale.invertExtent = function (y) {\n var i = range.indexOf(y);\n return i < 0 ? [NaN, NaN] : [i > 0 ? thresholds[i - 1] : domain[0], i < thresholds.length ? thresholds[i] : domain[domain.length - 1]];\n };\n\n scale.domain = function (_) {\n if (!arguments.length) return domain.slice();\n domain = [];\n\n for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);\n\n domain.sort(ascending);\n return rescale();\n };\n\n scale.range = function (_) {\n return arguments.length ? (range = slice.call(_), rescale()) : range.slice();\n };\n\n scale.unknown = function (_) {\n return arguments.length ? (unknown = _, scale) : unknown;\n };\n\n scale.quantiles = function () {\n return thresholds.slice();\n };\n\n scale.copy = function () {\n return quantile().domain(domain).range(range).unknown(unknown);\n };\n\n return initRange.apply(scale, arguments);\n}","map":null,"metadata":{},"sourceType":"module"}