@mui/x-charts
Version:
The community edition of the charts components (MUI X).
143 lines (142 loc) • 6.43 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AreaElement = AreaElement;
exports.areaElementClasses = exports.AreaElementPath = void 0;
exports.getAreaElementUtilityClass = getAreaElementUtilityClass;
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 _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
var _utils = require("@mui/base/utils");
var _generateUtilityClass = _interopRequireDefault(require("@mui/utils/generateUtilityClass"));
var _styles = require("@mui/material/styles");
var _generateUtilityClasses = _interopRequireDefault(require("@mui/utils/generateUtilityClasses"));
var _d3Color = require("d3-color");
var _useInteractionItemProps = require("../hooks/useInteractionItemProps");
var _InteractionProvider = require("../context/InteractionProvider");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps"];
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function getAreaElementUtilityClass(slot) {
return (0, _generateUtilityClass.default)('MuiAreaElement', slot);
}
const areaElementClasses = exports.areaElementClasses = (0, _generateUtilityClasses.default)('MuiAreaElement', ['root', 'highlighted', 'faded']);
const useUtilityClasses = ownerState => {
const {
classes,
id,
isFaded,
isHighlighted
} = ownerState;
const slots = {
root: ['root', `series-${id}`, isHighlighted && 'highlighted', isFaded && 'faded']
};
return (0, _composeClasses.default)(slots, getAreaElementUtilityClass, classes);
};
const AreaElementPath = exports.AreaElementPath = (0, _styles.styled)('path', {
name: 'MuiAreaElement',
slot: 'Root',
overridesResolver: (_, styles) => styles.root
})(({
ownerState
}) => ({
stroke: 'none',
fill: ownerState.isHighlighted ? (0, _d3Color.color)(ownerState.color).brighter(1).formatHex() : (0, _d3Color.color)(ownerState.color).brighter(0.5).formatHex(),
transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
opacity: ownerState.isFaded ? 0.3 : 1
}));
AreaElementPath.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
as: _propTypes.default.elementType,
ownerState: _propTypes.default.shape({
classes: _propTypes.default.object,
color: _propTypes.default.string.isRequired,
id: _propTypes.default.string.isRequired,
isFaded: _propTypes.default.bool.isRequired,
isHighlighted: _propTypes.default.bool.isRequired
}).isRequired,
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])
};
/**
* Demos:
*
* - [Lines](https://mui.com/x/react-charts/lines/)
* - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
*
* API:
*
* - [AreaElement API](https://mui.com/x/api/charts/area-element/)
*/
function AreaElement(props) {
const {
id,
classes: innerClasses,
color,
highlightScope,
slots,
slotProps
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)(highlightScope);
const {
item
} = React.useContext(_InteractionProvider.InteractionContext);
const isHighlighted = (0, _useInteractionItemProps.getIsHighlighted)(item, {
type: 'line',
seriesId: id
}, highlightScope);
const isFaded = !isHighlighted && (0, _useInteractionItemProps.getIsFaded)(item, {
type: 'line',
seriesId: id
}, highlightScope);
const ownerState = {
id,
classes: innerClasses,
color,
isFaded,
isHighlighted
};
const classes = useUtilityClasses(ownerState);
const Area = slots?.area ?? AreaElementPath;
const areaProps = (0, _utils.useSlotProps)({
elementType: Area,
externalSlotProps: slotProps?.area,
additionalProps: (0, _extends2.default)({}, other, getInteractionItemProps({
type: 'line',
seriesId: id
}), {
className: classes.root
}),
ownerState
});
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Area, (0, _extends2.default)({}, areaProps));
}
process.env.NODE_ENV !== "production" ? AreaElement.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
classes: _propTypes.default.object,
highlightScope: _propTypes.default.shape({
faded: _propTypes.default.oneOf(['global', 'none', 'series']),
highlighted: _propTypes.default.oneOf(['item', 'none', 'series'])
}),
/**
* The props used for each component slot.
* @default {}
*/
slotProps: _propTypes.default.object,
/**
* Overridable component slots.
* @default {}
*/
slots: _propTypes.default.object
} : void 0;