UNPKG

@mui/x-charts

Version:

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

416 lines (414 loc) 18.7 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.PieChart = PieChart; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var React = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _ResponsiveChartContainer = require("../ResponsiveChartContainer"); var _ChartsAxis = require("../ChartsAxis/ChartsAxis"); var _constants = require("../constants"); var _ChartsTooltip = require("../ChartsTooltip"); var _ChartsLegend = require("../ChartsLegend"); var _ChartsAxisHighlight = require("../ChartsAxisHighlight"); var _PiePlot = require("./PiePlot"); var _jsxRuntime = require("react/jsx-runtime"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } const defaultMargin = { top: 5, bottom: 5, left: 5, right: 100 }; /** * Demos: * * - [Pie](https://mui.com/x/react-charts/pie/) * - [Pie demonstration](https://mui.com/x/react-charts/pie-demo/) * * API: * * - [PieChart API](https://mui.com/x/api/charts/pie-chart/) */ function PieChart(props) { const { xAxis, yAxis, series, width, height, margin: marginProps, colors, sx, tooltip = { trigger: 'item' }, axisHighlight = { x: 'none', y: 'none' }, skipAnimation, legend = { direction: 'column', position: { vertical: 'middle', horizontal: 'right' } }, topAxis = null, leftAxis = null, rightAxis = null, bottomAxis = null, children, slots, slotProps, onClick } = props; const margin = (0, _extends2.default)({}, defaultMargin, marginProps); return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ResponsiveChartContainer.ResponsiveChartContainer, { series: series.map(s => (0, _extends2.default)({ type: 'pie' }, s)), width: width, height: height, margin: margin, xAxis: xAxis ?? [{ id: _constants.DEFAULT_X_AXIS_KEY, scaleType: 'point', data: [...new Array(Math.max(...series.map(s => s.data.length)))].map((_, index) => index) }], yAxis: yAxis, colors: colors, sx: sx, disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none', children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxis.ChartsAxis, { topAxis: topAxis, leftAxis: leftAxis, rightAxis: rightAxis, bottomAxis: bottomAxis, slots: slots, slotProps: slotProps }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_PiePlot.PiePlot, { slots: slots, slotProps: slotProps, onClick: onClick, skipAnimation: skipAnimation }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLegend.ChartsLegend, (0, _extends2.default)({}, legend, { slots: slots, slotProps: slotProps })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxisHighlight.ChartsAxisHighlight, (0, _extends2.default)({}, axisHighlight)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsTooltip.ChartsTooltip, (0, _extends2.default)({}, tooltip)), children] }); } process.env.NODE_ENV !== "production" ? PieChart.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the TypeScript types and run "yarn proptypes" | // ---------------------------------------------------------------------- axisHighlight: _propTypes.default.shape({ x: _propTypes.default.oneOf(['band', 'line', 'none']), y: _propTypes.default.oneOf(['band', 'line', 'none']) }), /** * Indicate which axis to display the bottom of the charts. * Can be a string (the id of the axis) or an object `ChartsXAxisProps`. * @default xAxisIds[0] The id of the first provided axis */ bottomAxis: _propTypes.default.oneOfType([_propTypes.default.shape({ axisId: _propTypes.default.string, classes: _propTypes.default.object, disableLine: _propTypes.default.bool, disableTicks: _propTypes.default.bool, fill: _propTypes.default.string, label: _propTypes.default.string, labelFontSize: _propTypes.default.number, labelStyle: _propTypes.default.object, position: _propTypes.default.oneOf(['bottom', 'top']), slotProps: _propTypes.default.object, slots: _propTypes.default.object, stroke: _propTypes.default.string, tickFontSize: _propTypes.default.number, tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]), tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]), tickLabelStyle: _propTypes.default.object, tickMaxStep: _propTypes.default.number, tickMinStep: _propTypes.default.number, tickNumber: _propTypes.default.number, tickSize: _propTypes.default.number }), _propTypes.default.string]), children: _propTypes.default.node, className: _propTypes.default.string, /** * Color palette used to colorize multiple series. */ colors: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.func]), /** * An array of objects that can be used to populate series and axes data using their `dataKey` property. */ dataset: _propTypes.default.arrayOf(_propTypes.default.object), desc: _propTypes.default.string, /** * If `true`, the charts will not listen to the mouse move event. * It might break interactive features, but will improve performance. * @default false */ disableAxisListener: _propTypes.default.bool, /** * The height of the chart in px. If not defined, it takes the height of the parent element. * @default undefined */ height: _propTypes.default.number, /** * Indicate which axis to display the left of the charts. * Can be a string (the id of the axis) or an object `ChartsYAxisProps`. * @default yAxisIds[0] The id of the first provided axis */ leftAxis: _propTypes.default.oneOfType([_propTypes.default.shape({ axisId: _propTypes.default.string, classes: _propTypes.default.object, disableLine: _propTypes.default.bool, disableTicks: _propTypes.default.bool, fill: _propTypes.default.string, label: _propTypes.default.string, labelFontSize: _propTypes.default.number, labelStyle: _propTypes.default.object, position: _propTypes.default.oneOf(['left', 'right']), slotProps: _propTypes.default.object, slots: _propTypes.default.object, stroke: _propTypes.default.string, tickFontSize: _propTypes.default.number, tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]), tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]), tickLabelStyle: _propTypes.default.object, tickMaxStep: _propTypes.default.number, tickMinStep: _propTypes.default.number, tickNumber: _propTypes.default.number, tickSize: _propTypes.default.number }), _propTypes.default.string]), /** * @deprecated Consider using `slotProps.legend` instead. */ legend: _propTypes.default.shape({ classes: _propTypes.default.object, direction: _propTypes.default.oneOf(['column', 'row']), hidden: _propTypes.default.bool, position: _propTypes.default.shape({ horizontal: _propTypes.default.oneOf(['left', 'middle', 'right']).isRequired, vertical: _propTypes.default.oneOf(['bottom', 'middle', 'top']).isRequired }), slotProps: _propTypes.default.object, slots: _propTypes.default.object }), /** * The margin between the SVG and the drawing area. * It's used for leaving some space for extra information such as the x- and y-axis or legend. * Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`. * @default object Depends on the charts type. */ margin: _propTypes.default.shape({ bottom: _propTypes.default.number, left: _propTypes.default.number, right: _propTypes.default.number, top: _propTypes.default.number }), onClick: _propTypes.default.func, /** * Indicate which axis to display the right of the charts. * Can be a string (the id of the axis) or an object `ChartsYAxisProps`. * @default null */ rightAxis: _propTypes.default.oneOfType([_propTypes.default.shape({ axisId: _propTypes.default.string, classes: _propTypes.default.object, disableLine: _propTypes.default.bool, disableTicks: _propTypes.default.bool, fill: _propTypes.default.string, label: _propTypes.default.string, labelFontSize: _propTypes.default.number, labelStyle: _propTypes.default.object, position: _propTypes.default.oneOf(['left', 'right']), slotProps: _propTypes.default.object, slots: _propTypes.default.object, stroke: _propTypes.default.string, tickFontSize: _propTypes.default.number, tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]), tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]), tickLabelStyle: _propTypes.default.object, tickMaxStep: _propTypes.default.number, tickMinStep: _propTypes.default.number, tickNumber: _propTypes.default.number, tickSize: _propTypes.default.number }), _propTypes.default.string]), series: _propTypes.default.arrayOf(_propTypes.default.shape({ arcLabel: _propTypes.default.oneOfType([_propTypes.default.oneOf(['formattedValue', 'label', 'value']), _propTypes.default.func]), arcLabelMinAngle: _propTypes.default.number, color: _propTypes.default.string, cornerRadius: _propTypes.default.number, cx: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]), cy: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]), data: _propTypes.default.arrayOf(_propTypes.default.shape({ color: _propTypes.default.string, id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]), label: _propTypes.default.string, value: _propTypes.default.number.isRequired })).isRequired, endAngle: _propTypes.default.number, faded: _propTypes.default.shape({ additionalRadius: _propTypes.default.number, color: _propTypes.default.string, cornerRadius: _propTypes.default.number, innerRadius: _propTypes.default.number, outerRadius: _propTypes.default.number, paddingAngle: _propTypes.default.number }), highlighted: _propTypes.default.shape({ additionalRadius: _propTypes.default.number, color: _propTypes.default.string, cornerRadius: _propTypes.default.number, innerRadius: _propTypes.default.number, outerRadius: _propTypes.default.number, paddingAngle: _propTypes.default.number }), highlightScope: _propTypes.default.shape({ faded: _propTypes.default.oneOf(['global', 'none', 'series']), highlighted: _propTypes.default.oneOf(['item', 'none', 'series']) }), id: _propTypes.default.string, innerRadius: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]), outerRadius: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]), paddingAngle: _propTypes.default.number, sortingValues: _propTypes.default.oneOfType([_propTypes.default.oneOf(['asc', 'desc', 'none']), _propTypes.default.func]), startAngle: _propTypes.default.number, type: _propTypes.default.oneOf(['pie']), valueFormatter: _propTypes.default.func })).isRequired, /** * If `true`, animations are skiped. * @default false */ skipAnimation: _propTypes.default.bool, /** * The props used for each component slot. * @default {} */ slotProps: _propTypes.default.object, slots: _propTypes.default.object, sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]), title: _propTypes.default.string, tooltip: _propTypes.default.shape({ axisContent: _propTypes.default.elementType, classes: _propTypes.default.object, itemContent: _propTypes.default.elementType, slotProps: _propTypes.default.object, slots: _propTypes.default.object, trigger: _propTypes.default.oneOf(['axis', 'item', 'none']) }), /** * Indicate which axis to display the top of the charts. * Can be a string (the id of the axis) or an object `ChartsXAxisProps`. * @default null */ topAxis: _propTypes.default.oneOfType([_propTypes.default.shape({ axisId: _propTypes.default.string, classes: _propTypes.default.object, disableLine: _propTypes.default.bool, disableTicks: _propTypes.default.bool, fill: _propTypes.default.string, label: _propTypes.default.string, labelFontSize: _propTypes.default.number, labelStyle: _propTypes.default.object, position: _propTypes.default.oneOf(['bottom', 'top']), slotProps: _propTypes.default.object, slots: _propTypes.default.object, stroke: _propTypes.default.string, tickFontSize: _propTypes.default.number, tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]), tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]), tickLabelStyle: _propTypes.default.object, tickMaxStep: _propTypes.default.number, tickMinStep: _propTypes.default.number, tickNumber: _propTypes.default.number, tickSize: _propTypes.default.number }), _propTypes.default.string]), viewBox: _propTypes.default.shape({ height: _propTypes.default.number, width: _propTypes.default.number, x: _propTypes.default.number, y: _propTypes.default.number }), /** * The width of the chart in px. If not defined, it takes the width of the parent element. * @default undefined */ width: _propTypes.default.number, /** * The configuration of the x-axes. * If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`. */ xAxis: _propTypes.default.arrayOf(_propTypes.default.shape({ axisId: _propTypes.default.string, classes: _propTypes.default.object, data: _propTypes.default.array, dataKey: _propTypes.default.string, disableLine: _propTypes.default.bool, disableTicks: _propTypes.default.bool, fill: _propTypes.default.string, hideTooltip: _propTypes.default.bool, id: _propTypes.default.string, label: _propTypes.default.string, labelFontSize: _propTypes.default.number, labelStyle: _propTypes.default.object, max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]), min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]), position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']), scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']), slotProps: _propTypes.default.object, slots: _propTypes.default.object, stroke: _propTypes.default.string, tickFontSize: _propTypes.default.number, tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]), tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]), tickLabelStyle: _propTypes.default.object, tickMaxStep: _propTypes.default.number, tickMinStep: _propTypes.default.number, tickNumber: _propTypes.default.number, tickSize: _propTypes.default.number, valueFormatter: _propTypes.default.func })), /** * The configuration of the y-axes. * If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`. */ yAxis: _propTypes.default.arrayOf(_propTypes.default.shape({ axisId: _propTypes.default.string, classes: _propTypes.default.object, data: _propTypes.default.array, dataKey: _propTypes.default.string, disableLine: _propTypes.default.bool, disableTicks: _propTypes.default.bool, fill: _propTypes.default.string, hideTooltip: _propTypes.default.bool, id: _propTypes.default.string, label: _propTypes.default.string, labelFontSize: _propTypes.default.number, labelStyle: _propTypes.default.object, max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]), min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]), position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']), scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']), slotProps: _propTypes.default.object, slots: _propTypes.default.object, stroke: _propTypes.default.string, tickFontSize: _propTypes.default.number, tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]), tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]), tickLabelStyle: _propTypes.default.object, tickMaxStep: _propTypes.default.number, tickMinStep: _propTypes.default.number, tickNumber: _propTypes.default.number, tickSize: _propTypes.default.number, valueFormatter: _propTypes.default.func })) } : void 0;