@mui/x-charts
Version:
The community edition of the charts components (MUI X).
76 lines (73 loc) • 3.24 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DrawingContext = void 0;
exports.DrawingProvider = DrawingProvider;
exports.SVGContext = void 0;
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _useChartDimensions = _interopRequireDefault(require("../hooks/useChartDimensions"));
var _jsxRuntime = require("react/jsx-runtime");
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; }
/**
* Defines the area in which it is possible to draw the charts.
*/
const DrawingContext = exports.DrawingContext = /*#__PURE__*/React.createContext({
top: 0,
left: 0,
bottom: 0,
right: 0,
height: 300,
width: 400
});
const SVGContext = exports.SVGContext = /*#__PURE__*/React.createContext({
current: null
});
/**
* API:
*
* - [DrawingProvider API](https://mui.com/x/api/charts/drawing-provider/)
*/
function DrawingProvider({
width,
height,
margin,
svgRef,
children
}) {
const drawingArea = (0, _useChartDimensions.default)(width, height, margin);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(SVGContext.Provider, {
value: svgRef,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DrawingContext.Provider, {
value: drawingArea,
children: children
})
});
}
process.env.NODE_ENV !== "production" ? DrawingProvider.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
children: _propTypes.default.node,
height: _propTypes.default.number.isRequired,
/**
* 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 an object with the optional properties: `top`, `bottom`, `left`, and `right`.
* @default object Depends on the charts type.
*/
margin: _propTypes.default.shape({
bottom: _propTypes.default.number,
left: _propTypes.default.number,
right: _propTypes.default.number,
top: _propTypes.default.number
}),
svgRef: _propTypes.default.shape({
current: _propTypes.default.object
}).isRequired,
width: _propTypes.default.number.isRequired
} : void 0;
;