@mui/x-charts
Version:
The community edition of the Charts components (MUI X).
75 lines • 3.06 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import PropTypes from 'prop-types';
import { useSlotProps } from '@mui/base/utils';
import { DefaultChartsItemTooltipContent } from './DefaultChartsItemTooltipContent';
import { useCartesianContext } from '../context/CartesianProvider';
import { ZAxisContext } from '../context/ZAxisContextProvider';
import { useColorProcessor } from '../hooks/useColor';
import { useSeries } from '../hooks/useSeries';
import { jsx as _jsx } from "react/jsx-runtime";
function ChartsItemTooltipContent(props) {
const {
content,
itemData,
sx,
classes,
contentProps
} = props;
const series = useSeries()[itemData.type].series[itemData.seriesId];
const {
xAxis,
yAxis,
xAxisIds,
yAxisIds
} = useCartesianContext();
const {
zAxis,
zAxisIds
} = React.useContext(ZAxisContext);
const colorProcessors = useColorProcessor();
const xAxisKey = series.xAxisKey ?? xAxisIds[0];
const yAxisKey = series.yAxisKey ?? yAxisIds[0];
const zAxisKey = series.zAxisKey ?? zAxisIds[0];
const getColor = colorProcessors[series.type]?.(series, xAxisKey && xAxis[xAxisKey], yAxisKey && yAxis[yAxisKey], zAxisKey && zAxis[zAxisKey]) ?? (() => '');
const Content = content ?? DefaultChartsItemTooltipContent;
const chartTooltipContentProps = useSlotProps({
elementType: Content,
externalSlotProps: contentProps,
additionalProps: {
itemData,
series,
sx,
classes,
getColor
},
ownerState: {}
});
return /*#__PURE__*/_jsx(Content, _extends({}, chartTooltipContentProps));
}
process.env.NODE_ENV !== "production" ? ChartsItemTooltipContent.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
classes: PropTypes.object.isRequired,
content: PropTypes.elementType,
contentProps: PropTypes.shape({
classes: PropTypes.object,
getColor: PropTypes.func,
itemData: PropTypes.shape({
dataIndex: PropTypes.number,
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
}),
series: PropTypes.object,
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
}),
itemData: PropTypes.shape({
dataIndex: PropTypes.number,
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired
}).isRequired,
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
} : void 0;
export { ChartsItemTooltipContent };