UNPKG

@mui/x-charts

Version:

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

196 lines (195 loc) 6.92 kB
'use client'; import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; const _excluded = ["series", "children", "width", "height", "colors", "highlightedItem", "onHighlightChange", "className", "skipAnimation", "margin", "radar", "highlight"]; import * as React from 'react'; import PropTypes from 'prop-types'; import { ChartDataProvider } from "../../ChartDataProvider/index.js"; import { defaultizeMargin } from "../../internals/defaultizeMargin.js"; import { useChartPolarAxis } from "../../internals/plugins/featurePlugins/useChartPolarAxis/index.js"; import { useChartHighlight } from "../../internals/plugins/featurePlugins/useChartHighlight/index.js"; import { useChartInteraction } from "../../internals/plugins/featurePlugins/useChartInteraction/index.js"; import { radarSeriesConfig } from "../seriesConfig/index.js"; import { jsx as _jsx } from "react/jsx-runtime"; const RADAR_SERIES_CONFIG = { radar: radarSeriesConfig }; const RADAR_PLUGINS = [useChartPolarAxis, useChartInteraction, useChartHighlight]; const DEFAULT_RADAR_MARGIN = { top: 30, bottom: 30, left: 50, right: 50 }; function RadarDataProvider(props) { const { series, children, width, height, colors, highlightedItem, onHighlightChange, skipAnimation, margin, radar, highlight } = props, other = _objectWithoutPropertiesLoose(props, _excluded); const rotationAxes = React.useMemo(() => [{ id: 'radar-rotation-axis', scaleType: 'point', data: radar.metrics.map(metric => typeof metric === 'string' ? metric : metric.name), startAngle: radar.startAngle, endAngle: radar.startAngle !== undefined ? radar.startAngle + 360 : undefined, labelGap: radar.labelGap, valueFormatter: (name, { location }) => radar.labelFormatter?.(name, { location: location }) ?? name }], [radar]); const radiusAxis = React.useMemo(() => radar.metrics.map(m => { const { name, min = 0, max = radar.max } = typeof m === 'string' ? { name: m } : m; return { id: name, label: name, scaleType: 'linear', min, max }; }), [radar]); const defaultizedSeries = React.useMemo(() => series.map(s => _extends({ type: 'radar', highlightScope: s.highlightScope ?? (highlight === 'series' ? { highlight: 'series', fade: 'global' } : undefined) }, s)), [series, highlight]); const defaultizedMargin = React.useMemo(() => defaultizeMargin(margin, DEFAULT_RADAR_MARGIN), [margin]); return /*#__PURE__*/_jsx(ChartDataProvider, _extends({}, other, { series: defaultizedSeries, width: width, height: height, margin: defaultizedMargin, colors: colors, highlightedItem: highlightedItem, onHighlightChange: onHighlightChange, skipAnimation: skipAnimation, plugins: RADAR_PLUGINS, rotationAxis: rotationAxes, radiusAxis: radiusAxis, seriesConfig: RADAR_SERIES_CONFIG, children: children })); } process.env.NODE_ENV !== "production" ? RadarDataProvider.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 }), children: PropTypes.node, className: PropTypes.string, /** * Color palette used to colorize multiple series. * @default rainbowSurgePalette */ colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]), 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, /** * The height of the chart in px. If not defined, it takes the height of the parent element. */ height: PropTypes.number, /** * Indicates if the chart should highlight items per axis or per series. * @default 'axis' */ highlight: PropTypes.oneOf(['axis', 'none', 'series']), /** * The highlighted item. * Used when the highlight is controlled. */ highlightedItem: PropTypes.shape({ dataIndex: PropTypes.number, seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.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.string, /** * 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 callback fired when the highlighted item changes. * * @param {HighlightItemData | null} highlightedItem The newly highlighted item. */ onHighlightChange: PropTypes.func, /** * The configuration of the radar scales. */ radar: PropTypes.shape({ labelFormatter: PropTypes.func, labelGap: PropTypes.number, max: PropTypes.number, metrics: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.arrayOf(PropTypes.shape({ max: PropTypes.number, min: PropTypes.number, name: PropTypes.string.isRequired }))]).isRequired, startAngle: PropTypes.number }).isRequired, /** * The series to display in the bar chart. * An array of [[RadarSeriesType]] objects. */ series: PropTypes.arrayOf(PropTypes.object).isRequired, /** * The configuration helpers used to compute attributes according to the series type. * @ignore Unstable props for internal usage. */ seriesConfig: PropTypes.object, /** * If `true`, animations are skipped. * If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting. */ skipAnimation: PropTypes.bool, sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]), theme: PropTypes.oneOf(['dark', 'light']), title: PropTypes.string, /** * The width of the chart in px. If not defined, it takes the width of the parent element. */ width: PropTypes.number } : void 0; export { RadarDataProvider };