UNPKG

@mui/x-charts

Version:

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

158 lines (157 loc) 8.52 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.ChartsAxisTooltipContent = ChartsAxisTooltipContent; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var React = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _utils = require("@mui/base/utils"); var _SeriesContextProvider = require("../context/SeriesContextProvider"); var _CartesianContextProvider = require("../context/CartesianContextProvider"); var _DefaultChartsAxisTooltipContent = require("./DefaultChartsAxisTooltipContent"); 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; } function ChartsAxisTooltipContent(props) { const { content, contentProps, axisData, sx, classes } = props; const isXaxis = (axisData.x && axisData.x.index) !== undefined; const dataIndex = isXaxis ? axisData.x && axisData.x.index : axisData.y && axisData.y.index; const axisValue = isXaxis ? axisData.x && axisData.x.value : axisData.y && axisData.y.value; const { xAxisIds, xAxis, yAxisIds, yAxis } = React.useContext(_CartesianContextProvider.CartesianContext); const series = React.useContext(_SeriesContextProvider.SeriesContext); const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0]; const relevantSeries = React.useMemo(() => { const rep = []; Object.keys(series).filter(seriesType => ['bar', 'line', 'scatter'].includes(seriesType)).forEach(seriesType => { series[seriesType].seriesOrder.forEach(seriesId => { const item = series[seriesType].series[seriesId]; const axisKey = isXaxis ? item.xAxisKey : item.yAxisKey; if (axisKey === undefined || axisKey === USED_AXIS_ID) { rep.push(series[seriesType].series[seriesId]); } }); }); return rep; }, [USED_AXIS_ID, isXaxis, series]); const relevantAxis = React.useMemo(() => { return isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID]; }, [USED_AXIS_ID, isXaxis, xAxis, yAxis]); const Content = content ?? _DefaultChartsAxisTooltipContent.DefaultChartsAxisTooltipContent; const chartTooltipContentProps = (0, _utils.useSlotProps)({ elementType: Content, externalSlotProps: contentProps, additionalProps: { axisData, series: relevantSeries, axis: relevantAxis, dataIndex, axisValue, sx, classes }, ownerState: {} }); return /*#__PURE__*/(0, _jsxRuntime.jsx)(Content, (0, _extends2.default)({}, chartTooltipContentProps)); } process.env.NODE_ENV !== "production" ? ChartsAxisTooltipContent.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the TypeScript types and run "yarn proptypes" | // ---------------------------------------------------------------------- axisData: _propTypes.default.shape({ x: _propTypes.default.shape({ index: _propTypes.default.number, value: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]).isRequired }), y: _propTypes.default.shape({ index: _propTypes.default.number, value: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]).isRequired }) }).isRequired, classes: _propTypes.default.object.isRequired, content: _propTypes.default.elementType, contentProps: _propTypes.default.shape({ axis: _propTypes.default.shape({ axisId: _propTypes.default.string, classes: _propTypes.default.object, data: _propTypes.default.array, dataKey: _propTypes.default.string, disableLine: _propTypes.default.bool, disableTicks: _propTypes.default.bool, fill: _propTypes.default.string, hideTooltip: _propTypes.default.bool, id: _propTypes.default.string.isRequired, label: _propTypes.default.string, labelFontSize: _propTypes.default.number, labelStyle: _propTypes.default.object, max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]), min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]), position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']), scale: _propTypes.default.func.isRequired, scaleType: _propTypes.default.oneOf(['time']).isRequired, slotProps: _propTypes.default.object, slots: _propTypes.default.object, stroke: _propTypes.default.string, tickFontSize: _propTypes.default.number, tickInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.array, _propTypes.default.func]), tickLabelInterval: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.func]), tickLabelStyle: _propTypes.default.object, tickMaxStep: _propTypes.default.number, tickMinStep: _propTypes.default.number, tickNumber: _propTypes.default.number.isRequired, tickSize: _propTypes.default.number, valueFormatter: _propTypes.default.func }), axisData: _propTypes.default.shape({ x: _propTypes.default.shape({ index: _propTypes.default.number, value: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]).isRequired }), y: _propTypes.default.shape({ index: _propTypes.default.number, value: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]).isRequired }) }), axisValue: _propTypes.default.any, classes: _propTypes.default.object, dataIndex: _propTypes.default.number, series: _propTypes.default.arrayOf(_propTypes.default.shape({ area: _propTypes.default.bool, color: _propTypes.default.string.isRequired, connectNulls: _propTypes.default.bool, curve: _propTypes.default.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']), data: _propTypes.default.arrayOf(_propTypes.default.number).isRequired, dataKey: _propTypes.default.string, disableHighlight: _propTypes.default.bool, highlightScope: _propTypes.default.shape({ faded: _propTypes.default.oneOf(['global', 'none', 'series']), highlighted: _propTypes.default.oneOf(['item', 'none', 'series']) }), id: _propTypes.default.string.isRequired, label: _propTypes.default.string, showMark: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.bool]), stack: _propTypes.default.string, stackOffset: _propTypes.default.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']), stackOrder: _propTypes.default.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']), type: _propTypes.default.oneOf(['line']).isRequired, valueFormatter: _propTypes.default.func.isRequired, xAxisKey: _propTypes.default.string, yAxisKey: _propTypes.default.string })), 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]) }), 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]) } : void 0;