UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

363 lines (361 loc) 12.9 kB
'use client'; import _extends from "@babel/runtime/helpers/esm/extends"; import * as React from 'react'; import PropTypes from 'prop-types'; import { ChartsDataProvider } from "../ChartsDataProvider/index.mjs"; import { useChartsContainerProps } from "./useChartsContainerProps.mjs"; import { ChartsSurface } from "../ChartsSurface/index.mjs"; import { jsx as _jsx } from "react/jsx-runtime"; /** * It sets up the data providers as well as the `<svg>` for the chart. * * This is a combination of both the `ChartsDataProvider` and `ChartsSurface` components. * * Demos: * * - [Composition](https://mui.com/x/api/charts/composition/) * * API: * * - [ChartsContainer API](https://mui.com/x/api/charts/charts-container/) * * @example * ```jsx * <ChartsContainer * series={[{ label: "Label", type: "bar", data: [10, 20] }]} * xAxis={[{ data: ["A", "B"], scaleType: "band", id: "x-axis" }]} * > * <BarPlot /> * <ChartsXAxis axisId="x-axis" /> * </ChartsContainer> * ``` */ const ChartsContainer = /*#__PURE__*/React.forwardRef(function ChartsContainer(props, ref) { const { chartsDataProviderProps, children, chartsSurfaceProps } = useChartsContainerProps(props); return /*#__PURE__*/_jsx(ChartsDataProvider, _extends({}, chartsDataProviderProps, { children: /*#__PURE__*/_jsx(ChartsSurface, _extends({}, chartsSurfaceProps, { ref: ref, children: children })) })); }); // @ts-ignore if (process.env.NODE_ENV !== "production") ChartsContainer.displayName = "ChartsContainer"; process.env.NODE_ENV !== "production" ? ChartsContainer.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the TypeScript types and run "pnpm proptypes" | // ---------------------------------------------------------------------- apiRef: PropTypes.shape({ current: PropTypes.object }), /** * A gap added between axes when multiple axes are rendered on the same side of the chart. * @default 0 */ axesGap: PropTypes.number, /** * Configuration for the brush interaction. */ brushConfig: PropTypes.shape({ enabled: PropTypes.bool, preventHighlight: PropTypes.bool, preventTooltip: PropTypes.bool }), children: PropTypes.node, className: PropTypes.string, /** * Color palette used to colorize multiple series. * @default rainbowSurgePalette */ colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]), /** * An array of objects that can be used to populate series and axes data using their `dataKey` property. */ dataset: PropTypes.arrayOf(PropTypes.object), /** * The description of the chart. * Used to provide an accessible description for the chart. */ desc: PropTypes.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.bool, /** * If true, the hit area interaction is disabled and falls back to hover events. */ disableHitArea: PropTypes.bool, /** * If `true`, disables keyboard navigation for the chart. */ disableKeyboardNavigation: PropTypes.bool, /** * Options to enable features planned for the next major. */ experimentalFeatures: PropTypes.any, /** * The height of the chart in px. If not defined, it takes the height of the parent element. */ height: PropTypes.number, /** * List of hidden series and/or items. * * Different chart types use different keys. * * @example * ```ts * [ * { * type: 'pie', * seriesId: 'series-1', * dataIndex: 3, * }, * { * type: 'line', * seriesId: 'series-2', * } * ] * ``` */ hiddenItems: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.shape({ dataIndex: PropTypes.number, seriesId: PropTypes.string.isRequired, type: PropTypes.oneOf(['bar', 'line', 'pie', 'radar', 'scatter']).isRequired }), PropTypes.shape({ dataIndex: PropTypes.number, seriesId: PropTypes.string.isRequired, type: PropTypes.oneOf(['bar', 'line', 'pie', 'radar', 'scatter']) })]).isRequired), /** * The controlled axis highlight. * Identified by the axis id, and data index. */ highlightedAxis: PropTypes.arrayOf(PropTypes.shape({ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired, dataIndex: PropTypes.number.isRequired })), /** * The highlighted item. * Used when the highlight is controlled. */ highlightedItem: PropTypes.oneOfType([PropTypes.shape({ dataIndex: PropTypes.number, seriesId: PropTypes.string.isRequired }), PropTypes.shape({ dataIndex: PropTypes.number, seriesId: PropTypes.string.isRequired, type: PropTypes.oneOf(['bar', 'line', 'pie', 'radar', 'scatter']).isRequired })]), /** * Defines the maximum distance between a scatter point and the pointer that triggers the interaction. * If set to `'item'`, the radius is the `markerSize`. * If `undefined`, the radius is assumed to be infinite. */ hitAreaRadius: PropTypes.oneOfType([PropTypes.oneOf(['item']), PropTypes.number]), /** * 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.string, /** * List of initially hidden series and/or items. * Used for uncontrolled state. * * Different chart types use different keys. * * @example * ```ts * [ * { * type: 'pie', * seriesId: 'series-1', * dataIndex: 3, * }, * { * type: 'line', * seriesId: 'series-2', * } * ] * ``` */ initialHiddenItems: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.shape({ dataIndex: PropTypes.number, seriesId: PropTypes.string.isRequired, type: PropTypes.oneOf(['bar', 'line', 'pie', 'radar', 'scatter']).isRequired }), PropTypes.shape({ dataIndex: PropTypes.number, seriesId: PropTypes.string.isRequired, type: PropTypes.oneOf(['bar', 'line', 'pie', 'radar', 'scatter']) })]).isRequired), /** * Localized text for chart components. */ localeText: PropTypes.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.oneOfType([PropTypes.number, PropTypes.shape({ bottom: PropTypes.number, left: PropTypes.number, right: PropTypes.number, top: PropTypes.number })]), /** * The function called for onClick events. * The second argument contains information about all line/bar elements at the current mouse position. * @param {MouseEvent} event The mouse event recorded on the `<svg/>` element. * @param {null | ChartsAxisData} data The data about the clicked axis and items associated with it. */ onAxisClick: PropTypes.func, /** * Callback fired when any hidden identifiers change. * @param {VisibilityIdentifierWithType[]} hiddenItems The new list of hidden identifiers. */ onHiddenItemsChange: PropTypes.func, /** * The callback fired when the highlighted item changes. * * @param {HighlightItemIdentifierWithType<SeriesType> | null} highlightedItem The newly highlighted item. */ onHighlightChange: PropTypes.func, /** * The function called when the pointer position corresponds to a new axis data item. * This update can either be caused by a pointer movement, or an axis update. * In case of multiple axes, the function is called if at least one axis is updated. * The argument contains the identifier for all axes with a `data` property. * @param {AxisItemIdentifier[]} axisItems The array of axes item identifiers. */ onHighlightedAxisChange: PropTypes.func, /** * Callback fired when clicking close to an item. * This is only available for scatter plot for now. * @param {MouseEvent} event Mouse event caught at the svg level * @param {ScatterItemIdentifier} scatterItemIdentifier Identify which item got clicked */ onItemClick: PropTypes.func, /** * The function called when the pointer position corresponds to a new axis data item. * This update can either be caused by a pointer movement, or an axis update. * In case of multiple axes, the function is called if at least one axis is updated. * The argument contains the identifier for all axes with a `data` property. * @param {AxisItemIdentifier[]} axisItems The array of axes item identifiers. */ onTooltipAxisChange: PropTypes.func, /** * The callback fired when the tooltip item changes. * * @param {SeriesItemIdentifier<SeriesType> | null} tooltipItem The newly highlighted item. */ onTooltipItemChange: PropTypes.func, /** * The configuration of the radial-axes. * If not provided, a default axis config is used. * An array of [[AxisConfig]] objects. */ radiusAxis: PropTypes.arrayOf(PropTypes.object), /** * The configuration of the rotation-axes. * If not provided, a default axis config is used. * An array of [[AxisConfig]] objects. */ rotationAxis: PropTypes.arrayOf(PropTypes.object), /** * The array of series to display. * Each type of series has its own specificity. * Please refer to the appropriate docs page to learn more about it. */ series: PropTypes.arrayOf(PropTypes.object), /** * If `true`, animations are skipped. * If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting. */ skipAnimation: PropTypes.bool, /** * The props for the slots. */ slotProps: PropTypes.object, /** * Slots to customize charts' components. */ slots: PropTypes.object, sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]), theme: PropTypes.oneOf(['dark', 'light']), /** * The title of the chart. * Used to provide an accessible label for the chart. */ title: PropTypes.string, /** * The controlled axis tooltip. * Identified by the axis id, and data index. */ tooltipAxis: PropTypes.arrayOf(PropTypes.shape({ axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired, dataIndex: PropTypes.number.isRequired })), /** * The tooltip item. * Used when the tooltip is controlled. */ tooltipItem: PropTypes.oneOfType([PropTypes.shape({ dataIndex: PropTypes.number, seriesId: PropTypes.string.isRequired }), PropTypes.shape({ dataIndex: PropTypes.number, seriesId: PropTypes.string.isRequired, type: PropTypes.oneOf(['bar', 'line', 'pie', 'radar', 'scatter']).isRequired })]), /** * The width of the chart in px. If not defined, it takes the width of the parent element. */ width: PropTypes.number, /** * The configuration of the x-axes. * If not provided, a default axis config is used. * An array of [[AxisConfig]] objects. */ xAxis: PropTypes.arrayOf(PropTypes.object), /** * The configuration of the y-axes. * If not provided, a default axis config is used. * An array of [[AxisConfig]] objects. */ yAxis: PropTypes.arrayOf(PropTypes.object), /** * The configuration of the z-axes. */ zAxis: PropTypes.arrayOf(PropTypes.shape({ colorMap: PropTypes.oneOfType([PropTypes.shape({ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired, max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]), min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]), type: PropTypes.oneOf(['continuous']).isRequired }), PropTypes.shape({ colors: PropTypes.arrayOf(PropTypes.string).isRequired, thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired, type: PropTypes.oneOf(['piecewise']).isRequired }), PropTypes.shape({ colors: PropTypes.arrayOf(PropTypes.string).isRequired, type: PropTypes.oneOf(['ordinal']).isRequired, unknownColor: PropTypes.string, values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired) })]), data: PropTypes.array, dataKey: PropTypes.string, id: PropTypes.string, max: PropTypes.number, min: PropTypes.number, valueGetter: PropTypes.func })) } : void 0; export { ChartsContainer };