213 lines
8.1 KiB
JavaScript
213 lines
8.1 KiB
JavaScript
"use strict";
|
|
'use client';
|
|
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.PieChart = void 0;
|
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
var React = _interopRequireWildcard(require("react"));
|
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
var _styles = require("@mui/material/styles");
|
|
var _constants = require("../internals/constants");
|
|
var _ChartsTooltip = require("../ChartsTooltip");
|
|
var _ChartsLegend = require("../ChartsLegend");
|
|
var _PiePlot = require("./PiePlot");
|
|
var _ChartsOverlay = require("../ChartsOverlay");
|
|
var _ChartsSurface = require("../ChartsSurface");
|
|
var _ChartDataProvider = require("../ChartDataProvider");
|
|
var _useChartContainerProps = require("../ChartContainer/useChartContainerProps");
|
|
var _ChartsWrapper = require("../ChartsWrapper");
|
|
var _PieChart2 = require("./PieChart.plugins");
|
|
var _defaultizeMargin = require("../internals/defaultizeMargin");
|
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
const _excluded = ["series", "width", "height", "margin", "colors", "sx", "skipAnimation", "hideLegend", "children", "slots", "slotProps", "onItemClick", "loading", "highlightedItem", "onHighlightChange", "className", "showToolbar"];
|
|
/**
|
|
* 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/)
|
|
*/
|
|
const PieChart = exports.PieChart = /*#__PURE__*/React.forwardRef(function PieChart(inProps, ref) {
|
|
const props = (0, _styles.useThemeProps)({
|
|
props: inProps,
|
|
name: 'MuiPieChart'
|
|
});
|
|
const {
|
|
series,
|
|
width,
|
|
height,
|
|
margin: marginProps,
|
|
colors,
|
|
sx,
|
|
skipAnimation,
|
|
hideLegend,
|
|
children,
|
|
slots,
|
|
slotProps,
|
|
onItemClick,
|
|
loading,
|
|
highlightedItem,
|
|
onHighlightChange,
|
|
className,
|
|
showToolbar
|
|
} = props,
|
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
const margin = (0, _defaultizeMargin.defaultizeMargin)(marginProps, _constants.DEFAULT_PIE_CHART_MARGIN);
|
|
const {
|
|
chartDataProviderProps,
|
|
chartsSurfaceProps
|
|
} = (0, _useChartContainerProps.useChartContainerProps)((0, _extends2.default)({}, other, {
|
|
series: series.map(s => (0, _extends2.default)({
|
|
type: 'pie'
|
|
}, s)),
|
|
width,
|
|
height,
|
|
margin,
|
|
colors,
|
|
highlightedItem,
|
|
onHighlightChange,
|
|
className,
|
|
skipAnimation,
|
|
plugins: _PieChart2.PIE_CHART_PLUGINS
|
|
}), ref);
|
|
const Tooltip = slots?.tooltip ?? _ChartsTooltip.ChartsTooltip;
|
|
const Toolbar = props.slots?.toolbar;
|
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartDataProvider.ChartDataProvider, (0, _extends2.default)({}, chartDataProviderProps, {
|
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ChartsWrapper.ChartsWrapper, {
|
|
legendPosition: props.slotProps?.legend?.position,
|
|
legendDirection: props.slotProps?.legend?.direction ?? 'vertical',
|
|
sx: sx,
|
|
children: [showToolbar && Toolbar ? /*#__PURE__*/(0, _jsxRuntime.jsx)(Toolbar, (0, _extends2.default)({}, props.slotProps?.toolbar)) : null, !hideLegend && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLegend.ChartsLegend, {
|
|
direction: props.slotProps?.legend?.direction ?? 'vertical',
|
|
slots: slots,
|
|
slotProps: slotProps
|
|
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ChartsSurface.ChartsSurface, (0, _extends2.default)({}, chartsSurfaceProps, {
|
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_PiePlot.PiePlot, {
|
|
slots: slots,
|
|
slotProps: slotProps,
|
|
onItemClick: onItemClick
|
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsOverlay.ChartsOverlay, {
|
|
loading: loading,
|
|
slots: slots,
|
|
slotProps: slotProps
|
|
}), children]
|
|
})), !loading && /*#__PURE__*/(0, _jsxRuntime.jsx)(Tooltip, (0, _extends2.default)({
|
|
trigger: "item"
|
|
}, slotProps?.tooltip))]
|
|
})
|
|
}));
|
|
});
|
|
if (process.env.NODE_ENV !== "production") PieChart.displayName = "PieChart";
|
|
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 "pnpm proptypes" |
|
|
// ----------------------------------------------------------------------
|
|
apiRef: _propTypes.default.shape({
|
|
current: _propTypes.default.object
|
|
}),
|
|
children: _propTypes.default.node,
|
|
className: _propTypes.default.string,
|
|
/**
|
|
* Color palette used to colorize multiple series.
|
|
* @default rainbowSurgePalette
|
|
*/
|
|
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,
|
|
/**
|
|
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
*/
|
|
height: _propTypes.default.number,
|
|
/**
|
|
* If `true`, the legend is not rendered.
|
|
*/
|
|
hideLegend: _propTypes.default.bool,
|
|
/**
|
|
* The highlighted item.
|
|
* Used when the highlight is controlled.
|
|
*/
|
|
highlightedItem: _propTypes.default.shape({
|
|
dataIndex: _propTypes.default.number,
|
|
seriesId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired
|
|
}),
|
|
/**
|
|
* This prop is used to help implement the accessibility logic.
|
|
* If you don't provide this prop. It falls back to a randomly generated id.
|
|
*/
|
|
id: _propTypes.default.string,
|
|
/**
|
|
* If `true`, a loading overlay is displayed.
|
|
* @default false
|
|
*/
|
|
loading: _propTypes.default.bool,
|
|
/**
|
|
* Localized text for chart components.
|
|
*/
|
|
localeText: _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 a `number` to be used on all sides or an object with the optional properties: `top`, `bottom`, `left`, and `right`.
|
|
*/
|
|
margin: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.shape({
|
|
bottom: _propTypes.default.number,
|
|
left: _propTypes.default.number,
|
|
right: _propTypes.default.number,
|
|
top: _propTypes.default.number
|
|
})]),
|
|
/**
|
|
* The callback fired when the highlighted item changes.
|
|
*
|
|
* @param {HighlightItemData | null} highlightedItem The newly highlighted item.
|
|
*/
|
|
onHighlightChange: _propTypes.default.func,
|
|
/**
|
|
* Callback fired when a pie arc is clicked.
|
|
*/
|
|
onItemClick: _propTypes.default.func,
|
|
/**
|
|
* The series to display in the pie chart.
|
|
* An array of [[PieSeries]] objects.
|
|
*/
|
|
series: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
|
|
/**
|
|
* If true, shows the default chart toolbar.
|
|
* @default false
|
|
*/
|
|
showToolbar: _propTypes.default.bool,
|
|
/**
|
|
* If `true`, animations are skipped.
|
|
* If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.
|
|
*/
|
|
skipAnimation: _propTypes.default.bool,
|
|
/**
|
|
* The props used for each component slot.
|
|
* @default {}
|
|
*/
|
|
slotProps: _propTypes.default.object,
|
|
/**
|
|
* Overridable component slots.
|
|
* @default {}
|
|
*/
|
|
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]),
|
|
theme: _propTypes.default.oneOf(['dark', 'light']),
|
|
title: _propTypes.default.string,
|
|
/**
|
|
* The width of the chart in px. If not defined, it takes the width of the parent element.
|
|
*/
|
|
width: _propTypes.default.number
|
|
} : void 0; |