| 17990 | } |
| 17991 | |
| 17992 | function pie() { |
| 17993 | var value = identity$1, |
| 17994 | sortValues = descending$1, |
| 17995 | sort = null, |
| 17996 | startAngle = constant$1(0), |
| 17997 | endAngle = constant$1(tau), |
| 17998 | padAngle = constant$1(0); |
| 17999 | |
| 18000 | function pie(data) { |
| 18001 | var i, |
| 18002 | n = (data = array(data)).length, |
| 18003 | j, |
| 18004 | k, |
| 18005 | sum = 0, |
| 18006 | index = new Array(n), |
| 18007 | arcs = new Array(n), |
| 18008 | a0 = +startAngle.apply(this, arguments), |
| 18009 | da = Math.min(tau, Math.max(-tau, endAngle.apply(this, arguments) - a0)), |
| 18010 | a1, |
| 18011 | p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)), |
| 18012 | pa = p * (da < 0 ? -1 : 1), |
| 18013 | v; |
| 18014 | |
| 18015 | for (i = 0; i < n; ++i) { |
| 18016 | if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) { |
| 18017 | sum += v; |
| 18018 | } |
| 18019 | } |
| 18020 | |
| 18021 | // Optionally sort the arcs by previously-computed values or by data. |
| 18022 | if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); }); |
| 18023 | else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); }); |
| 18024 | |
| 18025 | // Compute the arcs! They are stored in the original data's order. |
| 18026 | for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) { |
| 18027 | j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = { |
| 18028 | data: data[j], |
| 18029 | index: i, |
| 18030 | value: v, |
| 18031 | startAngle: a0, |
| 18032 | endAngle: a1, |
| 18033 | padAngle: p |
| 18034 | }; |
| 18035 | } |
| 18036 | |
| 18037 | return arcs; |
| 18038 | } |
| 18039 | |
| 18040 | pie.value = function(_) { |
| 18041 | return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), pie) : value; |
| 18042 | }; |
| 18043 | |
| 18044 | pie.sortValues = function(_) { |
| 18045 | return arguments.length ? (sortValues = _, sort = null, pie) : sortValues; |
| 18046 | }; |
| 18047 | |
| 18048 | pie.sort = function(_) { |
| 18049 | return arguments.length ? (sort = _, sortValues = null, pie) : sort; |