MCPcopy
hub / github.com/microsoft/SandDance / pie

Function pie

docs/tests/v2/es6/js/sanddance.js:94857–94897  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

94855 padAngle = (0, _constant.default)(0);
94856
94857 function pie(data) {
94858 var i,
94859 n = data.length,
94860 j,
94861 k,
94862 sum = 0,
94863 index = new Array(n),
94864 arcs = new Array(n),
94865 a0 = +startAngle.apply(this, arguments),
94866 da = Math.min(_math.tau, Math.max(-_math.tau, endAngle.apply(this, arguments) - a0)),
94867 a1,
94868 p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
94869 pa = p * (da < 0 ? -1 : 1),
94870 v;
94871
94872 for (i = 0; i < n; ++i) {
94873 if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
94874 sum += v;
94875 }
94876 } // Optionally sort the arcs by previously-computed values or by data.
94877
94878
94879 if (sortValues != null) index.sort(function (i, j) {
94880 return sortValues(arcs[i], arcs[j]);
94881 });else if (sort != null) index.sort(function (i, j) {
94882 return sort(data[i], data[j]);
94883 }); // Compute the arcs! They are stored in the original data's order.
94884
94885 for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
94886 j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
94887 data: data[j],
94888 index: i,
94889 value: v,
94890 startAngle: a0,
94891 endAngle: a1,
94892 padAngle: p
94893 };
94894 }
94895
94896 return arcs;
94897 }
94898
94899 pie.value = function (_) {
94900 return arguments.length ? (value = typeof _ === "function" ? _ : (0, _constant.default)(+_), pie) : value;

Callers

nothing calls this directly

Calls 4

valueFunction · 0.70
sortFunction · 0.70
minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected