UNPKG

@mui/x-charts

Version:

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

48 lines (47 loc) 1.26 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import * as React from 'react'; import useId from '@mui/utils/useId'; import useChartDimensions from '../hooks/useChartDimensions'; /** * Defines the area in which it is possible to draw the charts. */ import { jsx as _jsx } from "react/jsx-runtime"; export const DrawingContext = /*#__PURE__*/React.createContext({ top: 0, left: 0, bottom: 0, right: 0, height: 300, width: 400, chartId: '' }); if (process.env.NODE_ENV !== 'production') { DrawingContext.displayName = 'DrawingContext'; } export const SvgContext = /*#__PURE__*/React.createContext({ current: null }); if (process.env.NODE_ENV !== 'production') { SvgContext.displayName = 'SvgContext'; } export function DrawingProvider(props) { const { width, height, margin, svgRef, children } = props; const drawingArea = useChartDimensions(width, height, margin); const chartId = useId(); const value = React.useMemo(() => _extends({ chartId: chartId ?? '' }, drawingArea), [chartId, drawingArea]); return /*#__PURE__*/_jsx(SvgContext.Provider, { value: svgRef, children: /*#__PURE__*/_jsx(DrawingContext.Provider, { value: value, children: children }) }); }