UNPKG

@mui/x-charts

Version:

The community edition of the charts components (MUI X).

55 lines 2.47 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import { pie as d3Pie } from 'd3-shape'; var getSortingComparator = function getSortingComparator() { var comparator = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'none'; if (typeof comparator === 'function') { return comparator; } switch (comparator) { case 'none': return null; case 'desc': return function (a, b) { return b - a; }; case 'asc': return function (a, b) { return a - b; }; default: return null; } }; var formatter = function formatter(params) { var seriesOrder = params.seriesOrder, series = params.series; var defaultizedSeries = {}; seriesOrder.forEach(function (seriesId) { var _series$seriesId$star, _series$seriesId$endA, _series$seriesId$padd, _series$seriesId$sort; var arcs = d3Pie().startAngle(2 * Math.PI * ((_series$seriesId$star = series[seriesId].startAngle) != null ? _series$seriesId$star : 0) / 360).endAngle(2 * Math.PI * ((_series$seriesId$endA = series[seriesId].endAngle) != null ? _series$seriesId$endA : 360) / 360).padAngle(2 * Math.PI * ((_series$seriesId$padd = series[seriesId].paddingAngle) != null ? _series$seriesId$padd : 0) / 360).sortValues(getSortingComparator((_series$seriesId$sort = series[seriesId].sortingValues) != null ? _series$seriesId$sort : 'none'))(series[seriesId].data.map(function (piePoint) { return piePoint.value; })); defaultizedSeries[seriesId] = _extends({ valueFormatter: function valueFormatter(item) { return item.value.toLocaleString(); } }, series[seriesId], { data: series[seriesId].data.map(function (item, index) { var _item$id; return _extends({}, item, { id: (_item$id = item.id) != null ? _item$id : "auto-generated-pie-id-".concat(seriesId, "-").concat(index) }, arcs[index]); }).map(function (item) { var _series$seriesId$valu, _series$seriesId$valu2, _series$seriesId; return _extends({}, item, { formattedValue: (_series$seriesId$valu = (_series$seriesId$valu2 = (_series$seriesId = series[seriesId]).valueFormatter) == null ? void 0 : _series$seriesId$valu2.call(_series$seriesId, item)) != null ? _series$seriesId$valu : item.value.toLocaleString() }); }) }); }); return { seriesOrder: seriesOrder, series: defaultizedSeries }; }; export default formatter;