UNPKG

@mui/x-charts

Version:

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

41 lines (40 loc) 957 B
'use client'; import * as React from 'react'; import { ZAxisContext } from "../context/ZAxisContextProvider.js"; import { useCartesianContext } from "../context/CartesianProvider/useCartesianContext.js"; /** * Helper to select an axis definition according to its direction and id. */ export function useAxis({ axisDirection, axisId }) { const { xAxis, xAxisIds, yAxis, yAxisIds } = useCartesianContext(); const { zAxis, zAxisIds } = React.useContext(ZAxisContext); switch (axisDirection) { case 'x': { const id = typeof axisId === 'string' ? axisId : xAxisIds[axisId ?? 0]; return xAxis[id]; } case 'y': { const id = typeof axisId === 'string' ? axisId : yAxisIds[axisId ?? 0]; return yAxis[id]; } case 'z': default: { const id = typeof axisId === 'string' ? axisId : zAxisIds[axisId ?? 0]; return zAxis[id]; } } }