@mui/x-charts
Version:
The community edition of the Charts components (MUI X).
202 lines (201 loc) • 7.92 kB
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.RadarDataProvider = RadarDataProvider;
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 _ChartDataProvider = require("../../ChartDataProvider");
var _defaultizeMargin = require("../../internals/defaultizeMargin");
var _useChartPolarAxis = require("../../internals/plugins/featurePlugins/useChartPolarAxis");
var _useChartHighlight = require("../../internals/plugins/featurePlugins/useChartHighlight");
var _useChartInteraction = require("../../internals/plugins/featurePlugins/useChartInteraction");
var _seriesConfig = require("../seriesConfig");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["series", "children", "width", "height", "colors", "highlightedItem", "onHighlightChange", "className", "skipAnimation", "margin", "radar", "highlight"];
const RADAR_SERIES_CONFIG = {
radar: _seriesConfig.radarSeriesConfig
};
const RADAR_PLUGINS = [_useChartPolarAxis.useChartPolarAxis, _useChartInteraction.useChartInteraction, _useChartHighlight.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 = (0, _objectWithoutPropertiesLoose2.default)(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 => (0, _extends2.default)({
type: 'radar',
highlightScope: s.highlightScope ?? (highlight === 'series' ? {
highlight: 'series',
fade: 'global'
} : undefined)
}, s)), [series, highlight]);
const defaultizedMargin = React.useMemo(() => (0, _defaultizeMargin.defaultizeMargin)(margin, DEFAULT_RADAR_MARGIN), [margin]);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartDataProvider.ChartDataProvider, (0, _extends2.default)({}, 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.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]),
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.
*/
height: _propTypes.default.number,
/**
* Indicates if the chart should highlight items per axis or per series.
* @default 'axis'
*/
highlight: _propTypes.default.oneOf(['axis', 'none', 'series']),
/**
* 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,
/**
* 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,
/**
* The configuration of the radar scales.
*/
radar: _propTypes.default.shape({
labelFormatter: _propTypes.default.func,
labelGap: _propTypes.default.number,
max: _propTypes.default.number,
metrics: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.arrayOf(_propTypes.default.shape({
max: _propTypes.default.number,
min: _propTypes.default.number,
name: _propTypes.default.string.isRequired
}))]).isRequired,
startAngle: _propTypes.default.number
}).isRequired,
/**
* The series to display in the bar chart.
* An array of [[RadarSeriesType]] objects.
*/
series: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
/**
* The configuration helpers used to compute attributes according to the series type.
* @ignore Unstable props for internal usage.
*/
seriesConfig: _propTypes.default.object,
/**
* If `true`, animations are skipped.
* If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.
*/
skipAnimation: _propTypes.default.bool,
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;