@mui/x-charts
Version:
The community edition of MUI X Charts components.
102 lines • 3.58 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["seriesId", "onItemClick", "classes"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { useRadarSeriesData } from "./useRadarSeriesData.mjs";
import { getAreaPath } from "./getAreaPath.mjs";
import { useUtilityClasses } from "../radarClasses.mjs";
import { useItemHighlightStateGetter } from "../../hooks/useItemHighlightStateGetter.mjs";
import { useInteractionAllItemProps } from "./useInteractionAllItemProps.mjs";
import { useRadarRotationIndex } from "./useRadarRotationIndex.mjs";
import { jsx as _jsx } from "react/jsx-runtime";
export function getPathProps(params) {
const {
getHighlightState,
seriesId,
classes,
points,
fillArea,
color
} = params;
const highlightState = getHighlightState({
type: 'radar',
seriesId
});
const isItemHighlighted = highlightState === 'highlighted';
const isItemFaded = highlightState === 'faded';
return {
d: getAreaPath(points),
fill: fillArea ? color : 'transparent',
stroke: color,
className: classes.seriesArea,
strokeOpacity: isItemFaded ? 0.5 : 1,
fillOpacity: isItemHighlighted && 0.4 || isItemFaded && 0.1 || 0.2,
strokeWidth: !fillArea && isItemHighlighted ? 2 : 1,
'data-highlighted': isItemHighlighted || undefined,
'data-faded': isItemFaded || undefined
};
}
function RadarSeriesArea(props) {
const {
seriesId,
onItemClick,
classes: inClasses
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const seriesCoordinates = useRadarSeriesData(seriesId);
const getRotationIndex = useRadarRotationIndex();
const interactionProps = useInteractionAllItemProps(seriesCoordinates);
const getHighlightState = useItemHighlightStateGetter();
const classes = useUtilityClasses(inClasses);
return /*#__PURE__*/_jsx(React.Fragment, {
children: seriesCoordinates?.map(({
seriesId: id,
points,
color,
fillArea,
hidden
}, seriesIndex) => {
if (hidden) {
return null;
}
return /*#__PURE__*/_jsx("path", _extends({}, getPathProps({
seriesId: id,
points,
color,
fillArea,
getHighlightState,
classes
}), {
onClick: event => onItemClick?.(event, {
type: 'radar',
seriesId: id,
dataIndex: getRotationIndex(event)
}),
cursor: onItemClick ? 'pointer' : 'unset'
}, interactionProps[seriesIndex], other), id);
})
});
}
process.env.NODE_ENV !== "production" ? RadarSeriesArea.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
/**
* Override or extend the styles applied to the component.
*/
classes: PropTypes.object,
/**
* Callback fired when an area is clicked.
* @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
* @param {RadarItemIdentifier} radarItemIdentifier The radar item identifier.
*/
onItemClick: PropTypes.func,
/**
* The id of the series to display.
* If undefined all series are displayed.
*/
seriesId: PropTypes.string
} : void 0;
export { RadarSeriesArea };