102 lines
3.6 KiB
JavaScript
102 lines
3.6 KiB
JavaScript
'use client';
|
|
|
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
const _excluded = ["children", "className", "title", "desc"];
|
|
import { styled, useThemeProps } from '@mui/material/styles';
|
|
import PropTypes from 'prop-types';
|
|
import * as React from 'react';
|
|
import useForkRef from '@mui/utils/useForkRef';
|
|
import { ChartsAxesGradients } from "../internals/components/ChartsAxesGradients/index.js";
|
|
import { useSvgRef } from "../hooks/useSvgRef.js";
|
|
import { useSelector } from "../internals/store/useSelector.js";
|
|
import { useStore } from "../internals/store/useStore.js";
|
|
import { selectorChartContainerSize, selectorChartPropsSize } from "../internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.js";
|
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
const ChartsSurfaceStyles = styled('svg', {
|
|
name: 'MuiChartsSurface',
|
|
slot: 'Root'
|
|
})(({
|
|
ownerState
|
|
}) => ({
|
|
width: ownerState.width ?? '100%',
|
|
height: ownerState.height ?? '100%',
|
|
display: 'flex',
|
|
position: 'relative',
|
|
flexDirection: 'column',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
overflow: 'hidden',
|
|
// This prevents default touch actions when using the svg on mobile devices.
|
|
// For example, prevent page scroll & zoom.
|
|
touchAction: 'pan-y',
|
|
userSelect: 'none'
|
|
}));
|
|
|
|
/**
|
|
* It provides the drawing area for the chart elements.
|
|
* It is the root `<svg>` of all the chart elements.
|
|
*
|
|
* It also provides the `title` and `desc` elements for the chart.
|
|
*
|
|
* Demos:
|
|
*
|
|
* - [Composition](https://mui.com/x/api/charts/composition/)
|
|
*
|
|
* API:
|
|
*
|
|
* - [ChartsSurface API](https://mui.com/x/api/charts/charts-surface/)
|
|
*/
|
|
const ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurface(inProps, ref) {
|
|
const store = useStore();
|
|
const {
|
|
width: svgWidth,
|
|
height: svgHeight
|
|
} = useSelector(store, selectorChartContainerSize);
|
|
const {
|
|
width: propsWidth,
|
|
height: propsHeight
|
|
} = useSelector(store, selectorChartPropsSize);
|
|
const svgRef = useSvgRef();
|
|
const handleRef = useForkRef(svgRef, ref);
|
|
const themeProps = useThemeProps({
|
|
props: inProps,
|
|
name: 'MuiChartsSurface'
|
|
});
|
|
const {
|
|
children,
|
|
className,
|
|
title,
|
|
desc
|
|
} = themeProps,
|
|
other = _objectWithoutPropertiesLoose(themeProps, _excluded);
|
|
const hasIntrinsicSize = svgHeight > 0 && svgWidth > 0;
|
|
return /*#__PURE__*/_jsxs(ChartsSurfaceStyles, _extends({
|
|
ownerState: {
|
|
width: propsWidth,
|
|
height: propsHeight
|
|
},
|
|
viewBox: `${0} ${0} ${svgWidth} ${svgHeight}`,
|
|
className: className
|
|
}, other, {
|
|
ref: handleRef,
|
|
children: [title && /*#__PURE__*/_jsx("title", {
|
|
children: title
|
|
}), desc && /*#__PURE__*/_jsx("desc", {
|
|
children: desc
|
|
}), /*#__PURE__*/_jsx(ChartsAxesGradients, {}), hasIntrinsicSize && children]
|
|
}));
|
|
});
|
|
if (process.env.NODE_ENV !== "production") ChartsSurface.displayName = "ChartsSurface";
|
|
process.env.NODE_ENV !== "production" ? ChartsSurface.propTypes = {
|
|
// ----------------------------- Warning --------------------------------
|
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
// ----------------------------------------------------------------------
|
|
children: PropTypes.node,
|
|
className: PropTypes.string,
|
|
desc: PropTypes.string,
|
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
title: PropTypes.string
|
|
} : void 0;
|
|
export { ChartsSurface }; |