Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[charts] Add initial Zoom&Pan to the Pro charts #13405

Merged
merged 97 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
9bfce7f
setup zoom context
JCQuintas Jun 10, 2024
f92d3db
Render Zoom Provider
JCQuintas Jun 10, 2024
b6c5aa7
Move cartesian context to its own folder and improve types
JCQuintas Jun 10, 2024
a7b8e0b
Ensure correct usage of useCartesianContext
JCQuintas Jun 10, 2024
38b026c
Add axis normalization function
JCQuintas Jun 10, 2024
567ded6
Divide cartesian provider logic
JCQuintas Jun 10, 2024
2416fb4
Setup Cartesian provider pro
JCQuintas Jun 10, 2024
954992c
Fix jittering
JCQuintas Jun 10, 2024
637881f
Remove CartesianContextProviderProps from pro
JCQuintas Jun 10, 2024
1cfba05
add extremums and domain to defautlized axis
JCQuintas Jun 10, 2024
3843dca
Remove unnecessary props
JCQuintas Jun 10, 2024
f17d00d
Calculate zoom using range
JCQuintas Jun 10, 2024
f9e4c5a
Use mouse position
JCQuintas Jun 12, 2024
8e68d62
Ignore events if mouse outside chart
JCQuintas Jun 12, 2024
ca67c56
throttle and try to fix spillover
JCQuintas Jun 13, 2024
d905a09
Try fix for getting out of bounds issue
JCQuintas Jun 13, 2024
b75b121
Improve zoom on mouse wheel vs trackpad
JCQuintas Jun 17, 2024
5bee9b4
Fix zoom math
alexfauquette Jun 17, 2024
575551e
Fix spillover logic for maxrange
JCQuintas Jun 17, 2024
5533615
Start zoom&pan markdown page
JCQuintas Jun 18, 2024
cfdd251
scale to scaleratio
JCQuintas Jun 18, 2024
50bc7e5
Merge commit '59e3a45693a2883612d7f2b975cc498dc8a45752' into zoom-poc
JCQuintas Jun 18, 2024
872f997
update internals
JCQuintas Jun 18, 2024
6c9301f
Move zoom code to pro package
JCQuintas Jun 18, 2024
f713bf5
Handle chart container pro
JCQuintas Jun 18, 2024
4a3fedc
Divide cartesianContextProvider
JCQuintas Jun 18, 2024
765499e
Use new useCartesianContext hook
JCQuintas Jun 18, 2024
4575461
Fix import
JCQuintas Jun 18, 2024
67c106f
Fix import
JCQuintas Jun 18, 2024
2f03e6c
Fix missing component
JCQuintas Jun 18, 2024
9a3a6f1
Add exports
JCQuintas Jun 18, 2024
7341f89
Add .nice back to prevent issues
JCQuintas Jun 18, 2024
5fec816
Improve ResponsiveChartContainer tests
JCQuintas Jun 18, 2024
3c22714
Compartimentize ChartContainer logic
JCQuintas Jun 18, 2024
c0fb9a1
Create ChartContainerPro
JCQuintas Jun 18, 2024
c5595c0
Run scripts
JCQuintas Jun 18, 2024
a5ee2ef
Both scale and domain should be nice
JCQuintas Jun 18, 2024
808a18e
run scripts
JCQuintas Jun 18, 2024
f9a953e
Add ticknumber to nice()
JCQuintas Jun 18, 2024
2c750e2
Update packages/x-charts/src/context/CartesianProvider/CartesianConte…
JCQuintas Jun 18, 2024
ca5319a
Dont error as MUI Y
JCQuintas Jun 18, 2024
f0040c9
Simplify computeValue for X
JCQuintas Jun 18, 2024
6971548
computeValue for Y
JCQuintas Jun 18, 2024
7449501
Update packages/x-charts-pro/src/ChartContainerPro/ChartContainerPro.tsx
JCQuintas Jun 19, 2024
5062469
Update packages/x-charts/src/context/CartesianProvider/computeValue.ts
JCQuintas Jun 19, 2024
b606028
Update packages/x-charts/src/context/CartesianProvider/computeValue.ts
JCQuintas Jun 19, 2024
a45bbc3
Move consts back out
JCQuintas Jun 19, 2024
a863c8b
Use nested imports
JCQuintas Jun 19, 2024
cefe954
Merge commit 'a863c8b88f2708d5f237200065ff46d37670f339' into zoom-poc
JCQuintas Jun 19, 2024
f08526b
Merge commit 'a45bbc3f3047367f4d77923bebe31588dbee6add' into zoom-poc
JCQuintas Jun 19, 2024
d48f263
Refactor CartesianProvider logic
JCQuintas Jun 19, 2024
622e004
remove nice
JCQuintas Jun 19, 2024
483f290
Export ScatterChartPro
JCQuintas Jun 19, 2024
af0cb89
Export BarChartPro
JCQuintas Jun 19, 2024
dd5b00b
Export LineChartPro
JCQuintas Jun 19, 2024
cee58be
Correctly export linechartpro from index
JCQuintas Jun 19, 2024
094d9ce
Merge commit 'dc0a2905c4fa2673641f2acbeede5a7148423bd8' into zoom-poc
JCQuintas Jun 19, 2024
4fbc1f1
Merge commit 'cee58beb3e8b9d3bd6e394e8e7af23155d6d5aed' into zoom-poc
JCQuintas Jun 19, 2024
37055e6
Merge commit '83b4130b121ccc9558eb0edd8b5e23a40939c3ff' into zoom-poc
JCQuintas Jun 20, 2024
698b55a
Merge commit '5f1034bcdd62d008fedf96721ff52a18789c491c' into zoom-poc
JCQuintas Jun 21, 2024
877de8a
Initial Pan
JCQuintas Jun 21, 2024
5f9cf2d
Properly clamp range for pan
JCQuintas Jun 21, 2024
704b501
Prevent text selection
JCQuintas Jun 21, 2024
fc3dc34
Pan on touch
JCQuintas Jun 21, 2024
b08491c
Zoom on pinch and pan using pointer events
JCQuintas Jun 21, 2024
0958dd7
Rename panning ref
JCQuintas Jun 24, 2024
d8c78af
Call panup on all cancel events
JCQuintas Jun 24, 2024
26f9caf
Remove pointer out from logic
JCQuintas Jun 24, 2024
0a76330
reuse smaller logic
JCQuintas Jun 24, 2024
8c95cc4
Merge commit '31f8dddc080ec16a7ffdb9f8bf031f57ed58d50a' into zoom-poc
JCQuintas Jun 24, 2024
c44e425
Improve zoom behavior
JCQuintas Jun 25, 2024
45f3170
Zoom on ordinal scale
JCQuintas Jun 25, 2024
f8bc63f
prevent some animations when interacting
JCQuintas Jun 26, 2024
73b1e93
separate scale range logic
JCQuintas Jun 26, 2024
35e7ebf
fix scroll wheel direction
JCQuintas Jun 26, 2024
1fbc672
revert scale changes
JCQuintas Jun 26, 2024
cbde110
Add zoom control
JCQuintas Jun 26, 2024
b1d58b0
Add demos
JCQuintas Jun 26, 2024
83e1533
Merge commit '2375a651d3f46bd7a343ae1e33209190b7a0cec2' into zoom-poc
JCQuintas Jun 26, 2024
e5a5fe6
proposal
alexfauquette Jun 26, 2024
1edfe32
Merge branch 'zoom-poc' of github.com:JCQuintas/mui-x into zoom-poc
alexfauquette Jun 26, 2024
ae71710
Follow same rules for all scale types
JCQuintas Jun 26, 2024
318449b
Return .nice() call since it doesnt affect our scale anymore
JCQuintas Jun 26, 2024
15c033e
Improve docs
JCQuintas Jun 26, 2024
2a71644
Increase tick number based on the amount of zoom so we get a nice scale
JCQuintas Jun 26, 2024
049ee9f
Update demos
JCQuintas Jun 26, 2024
258b230
Merge commit '8380f864e51eb329eddd0ac295f4573a2fbbcdea' into zoom-poc
JCQuintas Jun 27, 2024
ea3ce3e
Adapt x axis to scale
alexfauquette Jun 28, 2024
63b8e5b
fix overflowing dots
alexfauquette Jun 28, 2024
cc44455
Make zoom not affect tick number in nice()
JCQuintas Jun 28, 2024
8ef5d37
Merge commit 'e8e8d306d276627cb7312f4576b1c8d65d9dbe07' into zoom-poc
JCQuintas Jun 28, 2024
2880e06
Improve panning behavior
JCQuintas Jun 28, 2024
b0aa41b
Only prevent wheel if we are actually zoom
JCQuintas Jun 28, 2024
d653c96
Merge commit '18b7be634544487866a0e29242de3885ca42a460' into zoom-poc
JCQuintas Jul 2, 2024
192a56d
Prevent pro props from being passed down
JCQuintas Jul 2, 2024
a3d1756
Merge commit '13403cdfcbc15737a169b355ad4e340987622094' into zoom-poc
JCQuintas Jul 3, 2024
5a257e2
Prevent panning from outside the chart
JCQuintas Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/x-charts/src/BarChart/BarPlot.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { useTransition } from '@react-spring/web';
import { CartesianContext } from '../context/CartesianContextProvider';
import { useCartesianContext } from '../context/CartesianProvider';
import { BarElement, BarElementSlotProps, BarElementSlots } from './BarElement';
import { AxisDefaultized } from '../models/axis';
import { FormatterResult } from '../models/seriesType/config';
Expand Down Expand Up @@ -89,7 +89,7 @@ const useAggregatedData = (): {
const seriesData =
useBarSeries() ??
({ series: {}, stackingGroups: [], seriesOrder: [] } as FormatterResult<'bar'>);
const axisData = React.useContext(CartesianContext);
const axisData = useCartesianContext();
const chartId = useChartId();

const { series, stackingGroups } = seriesData;
Expand Down
12 changes: 6 additions & 6 deletions packages/x-charts/src/BarChart/checkScaleErrors.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
import { AxisDefaultized, isBandScaleConfig, isPointScaleConfig } from '../models/axis';
import { AxisDefaultized, AxisId, isBandScaleConfig, isPointScaleConfig } from '../models/axis';
import { SeriesId } from '../models/seriesType/common';

const getAxisMessage = (axisDirection: 'x' | 'y', axisKey: string) => {
const getAxisMessage = (axisDirection: 'x' | 'y', axisKey: AxisId) => {
const axisName = `${axisDirection}-axis`;
const axisKeyName = `${axisDirection}Axis`;
const axisDefaultKey = axisDirection === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY;
Expand All @@ -14,10 +14,10 @@ const getAxisMessage = (axisDirection: 'x' | 'y', axisKey: string) => {
export function checkScaleErrors(
verticalLayout: boolean,
seriesId: SeriesId,
xAxisKey: string,
xAxis: { DEFAULT_X_AXIS_KEY: AxisDefaultized } & { [axisKey: string]: AxisDefaultized },
yAxisKey: string,
yAxis: { DEFAULT_X_AXIS_KEY: AxisDefaultized } & { [axisKey: string]: AxisDefaultized },
xAxisKey: AxisId,
xAxis: { [axisKey: AxisId]: AxisDefaultized },
yAxisKey: AxisId,
yAxis: { [axisKey: AxisId]: AxisDefaultized },
): void {
const xAxisConfig = xAxis[xAxisKey];
const yAxisConfig = yAxis[yAxisKey];
Expand Down
85 changes: 49 additions & 36 deletions packages/x-charts/src/ChartContainer/ChartContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import { ChartsSurface, ChartsSurfaceProps } from '../ChartsSurface';
import {
CartesianContextProvider,
CartesianContextProviderProps,
} from '../context/CartesianContextProvider';
} from '../context/CartesianProvider';
import { ChartsAxesGradients } from '../internals/components/ChartsAxesGradients';
import { HighlightedProvider, HighlightedProviderProps } from '../context';
import { ChartsPluginType } from '../models/plugin';
import { ChartSeriesType } from '../models/seriesType/config';
import { usePluginsMerge } from './usePluginsMerge';
import { ZoomProvider } from '../context/ZoomProvider';
import { CartesianContextProviderPro } from '../context/CartesianProvider/CartesianProviderPro';

export type ChartContainerProps = Omit<
ChartsSurfaceProps &
Expand Down Expand Up @@ -63,44 +65,55 @@ const ChartContainer = React.forwardRef(function ChartContainer(props: ChartCont
useReducedMotion(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)

return (
<DrawingProvider width={width} height={height} margin={margin} svgRef={svgRef}>
<ColorProvider colorProcessors={colorProcessors}>
<SeriesContextProvider
series={series}
colors={colors}
dataset={dataset}
seriesFormatters={seriesFormatters}
>
<CartesianContextProvider
xAxis={xAxis}
yAxis={yAxis}
// TODO: Remove to pro package
<ZoomProvider>
<DrawingProvider width={width} height={height} margin={margin} svgRef={svgRef}>
<ColorProvider colorProcessors={colorProcessors}>
<SeriesContextProvider
series={series}
colors={colors}
dataset={dataset}
xExtremumGetters={xExtremumGetters}
yExtremumGetters={yExtremumGetters}
seriesFormatters={seriesFormatters}
>
<InteractionProvider>
<HighlightedProvider
highlightedItem={highlightedItem}
onHighlightChange={onHighlightChange}
<CartesianContextProviderPro
xAxis={xAxis}
yAxis={yAxis}
dataset={dataset}
xExtremumGetters={xExtremumGetters}
yExtremumGetters={yExtremumGetters}
>
<CartesianContextProvider
xAxis={xAxis}
yAxis={yAxis}
dataset={dataset}
xExtremumGetters={xExtremumGetters}
yExtremumGetters={yExtremumGetters}
>
<ChartsSurface
width={width}
height={height}
ref={handleRef}
sx={sx}
title={title}
desc={desc}
disableAxisListener={disableAxisListener}
>
<ChartsAxesGradients />
{children}
</ChartsSurface>
</HighlightedProvider>
</InteractionProvider>
</CartesianContextProvider>
</SeriesContextProvider>
</ColorProvider>
</DrawingProvider>
<InteractionProvider>
<HighlightedProvider
highlightedItem={highlightedItem}
onHighlightChange={onHighlightChange}
>
<ChartsSurface
width={width}
height={height}
ref={handleRef}
sx={sx}
title={title}
desc={desc}
disableAxisListener={disableAxisListener}
>
<ChartsAxesGradients />
{children}
</ChartsSurface>
</HighlightedProvider>
</InteractionProvider>
</CartesianContextProvider>
</CartesianContextProviderPro>
</SeriesContextProvider>
</ColorProvider>
</DrawingProvider>
</ZoomProvider>
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/x-charts/src/ChartContainer/usePluginsMerge.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { ChartsPluginType, ColorProcessorsConfig } from '../models';
import { ChartSeriesType } from '../models/seriesType/config';
import { ExtremumGettersConfig } from '../context/CartesianContextProvider';
import { ExtremumGettersConfig } from '../context/CartesianProvider';
import { SeriesFormatterConfig } from '../context/SeriesContextProvider';
import { defaultPlugins } from './defaultPlugins';

Expand Down
10 changes: 5 additions & 5 deletions packages/x-charts/src/ChartsAxis/ChartsAxis.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { CartesianContext } from '../context/CartesianContextProvider';
import { useCartesianContext } from '../context/CartesianProvider';
import { ChartsXAxis } from '../ChartsXAxis';
import { ChartsYAxis } from '../ChartsYAxis';
import {
Expand Down Expand Up @@ -49,8 +49,8 @@ export interface ChartsAxisProps {
}

const getAxisId = (
propsValue: undefined | null | string | ChartsXAxisProps | ChartsYAxisProps,
defaultAxisId?: string,
propsValue: undefined | null | AxisId | ChartsXAxisProps | ChartsYAxisProps,
defaultAxisId?: AxisId,
): AxisId | null => {
if (propsValue == null) {
return null;
Expand All @@ -62,7 +62,7 @@ const getAxisId = (
};

const mergeProps = (
axisConfig: undefined | null | string | ChartsXAxisProps | ChartsYAxisProps,
axisConfig: undefined | null | AxisId | ChartsXAxisProps | ChartsYAxisProps,
slots?: Partial<ChartsAxisSlots>,
slotProps?: Partial<ChartsAxisSlotProps>,
) => {
Expand All @@ -86,7 +86,7 @@ const mergeProps = (
*/
function ChartsAxis(props: ChartsAxisProps) {
const { topAxis, leftAxis, rightAxis, bottomAxis, slots, slotProps } = props;
const { xAxis, xAxisIds, yAxis, yAxisIds } = React.useContext(CartesianContext);
const { xAxis, xAxisIds, yAxis, yAxisIds } = useCartesianContext();

// TODO: use for plotting line without ticks or any thing
// const drawingArea = React.useContext(DrawingContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import generateUtilityClass from '@mui/utils/generateUtilityClass';
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
import { styled } from '@mui/material/styles';
import { InteractionContext } from '../context/InteractionProvider';
import { CartesianContext } from '../context/CartesianContextProvider';
import { useCartesianContext } from '../context/CartesianProvider';
import { getValueToPositionMapper } from '../hooks/useScale';
import { isBandScale } from '../internals/isBandScale';

Expand Down Expand Up @@ -67,7 +67,7 @@ export type ChartsAxisHighlightProps = {
*/
function ChartsAxisHighlight(props: ChartsAxisHighlightProps) {
const { x: xAxisHighlight, y: yAxisHighlight } = props;
const { xAxisIds, xAxis, yAxisIds, yAxis } = React.useContext(CartesianContext);
const { xAxisIds, xAxis, yAxisIds, yAxis } = useCartesianContext();
const classes = useUtilityClasses();

const USED_X_AXIS_ID = xAxisIds[0];
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/ChartsGrid/ChartsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import composeClasses from '@mui/utils/composeClasses';
import { styled, useThemeProps } from '@mui/material/styles';

import { CartesianContext } from '../context/CartesianContextProvider';
import { useCartesianContext } from '../context/CartesianProvider';
import { useTicks } from '../hooks/useTicks';
import {
ChartsGridClasses,
Expand Down Expand Up @@ -69,7 +69,7 @@ function ChartsGrid(props: ChartsGridProps) {
const themeProps = useThemeProps({ props, name: 'MuiChartsGrid' });

const { vertical, horizontal, ...other } = themeProps;
const { xAxis, xAxisIds, yAxis, yAxisIds } = React.useContext(CartesianContext);
const { xAxis, xAxisIds, yAxis, yAxisIds } = useCartesianContext();

const classes = useUtilityClasses(themeProps);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { InteractionContext } from '../context/InteractionProvider';
import { CartesianContext } from '../context/CartesianContextProvider';
import { useSeries } from '../hooks/useSeries';
import { useSvgRef } from '../hooks';
import { useCartesianContext } from '../context/CartesianProvider';

type AxisData = {
dataIndex: number;
Expand All @@ -27,7 +27,7 @@ function ChartsOnAxisClickHandler(props: ChartsOnAxisClickHandlerProps) {
const svgRef = useSvgRef();
const series = useSeries();
const { axis } = React.useContext(InteractionContext);
const { xAxisIds, xAxis, yAxisIds, yAxis } = React.useContext(CartesianContext);
const { xAxisIds, xAxis, yAxisIds, yAxis } = useCartesianContext();

React.useEffect(() => {
const element = svgRef.current;
Expand Down
2 changes: 2 additions & 0 deletions packages/x-charts/src/ChartsSurface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { styled, SxProps, Theme } from '@mui/material/styles';
import PropTypes from 'prop-types';
import * as React from 'react';
import { useAxisEvents } from './hooks/useAxisEvents';
import { useSetupZoom } from './context/ZoomProvider';

type ViewBox = {
x?: number;
Expand Down Expand Up @@ -55,6 +56,7 @@ const ChartsSurface = React.forwardRef<SVGSVGElement, ChartsSurfaceProps>(functi
const svgView = { width, height, x: 0, y: 0, ...viewBox };

useAxisEvents(disableAxisListener);
useSetupZoom();

return (
<ChartChartsSurfaceStyles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { SxProps, Theme } from '@mui/material/styles';
import { useSlotProps } from '@mui/base/utils';
import { AxisInteractionData } from '../context/InteractionProvider';
import { CartesianContext } from '../context/CartesianContextProvider';
import { useCartesianContext } from '../context/CartesianProvider';
import { ChartSeriesDefaultized, ChartSeriesType } from '../models/seriesType/config';
import { AxisDefaultized } from '../models/axis';
import { ChartsTooltipClasses } from './chartsTooltipClasses';
Expand Down Expand Up @@ -59,7 +59,7 @@ function ChartsAxisTooltipContent(props: {
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(CartesianContext);
const { xAxisIds, xAxis, yAxisIds, yAxis } = useCartesianContext();
const { zAxisIds, zAxis } = React.useContext(ZAxisContext);
const series = useSeries();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ItemInteractionData } from '../context/InteractionProvider';
import { ChartSeriesDefaultized, ChartSeriesType } from '../models/seriesType/config';
import { ChartsTooltipClasses } from './chartsTooltipClasses';
import { DefaultChartsItemTooltipContent } from './DefaultChartsItemTooltipContent';
import { CartesianContext } from '../context/CartesianContextProvider';
import { useCartesianContext } from '../context/CartesianProvider';
import { ZAxisContext } from '../context/ZAxisContextProvider';
import { useColorProcessor } from '../hooks/useColor';
import { useSeries } from '../hooks/useSeries';
Expand Down Expand Up @@ -44,7 +44,7 @@ function ChartsItemTooltipContent<T extends ChartSeriesType>(props: {

const series = useSeries()[itemData.type]!.series[itemData.seriesId] as ChartSeriesDefaultized<T>;

const { xAxis, yAxis, xAxisIds, yAxisIds } = React.useContext(CartesianContext);
const { xAxis, yAxis, xAxisIds, yAxisIds } = useCartesianContext();
const { zAxis, zAxisIds } = React.useContext(ZAxisContext);
const colorProcessors = useColorProcessor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { Delaunay } from 'd3-delaunay';
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
import { InteractionContext } from '../context/InteractionProvider';
import { CartesianContext } from '../context/CartesianContextProvider';
import { useCartesianContext } from '../context/CartesianProvider';
import { getValueToPositionMapper } from '../hooks/useScale';
import { getSVGPoint } from '../internals/utils';
import { ScatterItemIdentifier } from '../models';
Expand Down Expand Up @@ -32,7 +32,7 @@ function ChartsVoronoiHandler(props: ChartsVoronoiHandlerProps) {
const { voronoiMaxRadius, onItemClick } = props;
const svgRef = useSvgRef();
const { left, top, width, height } = useDrawingArea();
const { xAxis, yAxis, xAxisIds, yAxisIds } = React.useContext(CartesianContext);
const { xAxis, yAxis, xAxisIds, yAxisIds } = useCartesianContext();
const { dispatch } = React.useContext(InteractionContext);

const { series, seriesOrder } = useScatterSeries() ?? {};
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/ChartsXAxis/ChartsXAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { useSlotProps } from '@mui/base/utils';
import { unstable_composeClasses as composeClasses } from '@mui/utils';
import { useThemeProps, useTheme, Theme } from '@mui/material/styles';
import { CartesianContext } from '../context/CartesianContextProvider';
import { useCartesianContext } from '../context/CartesianProvider';
import { useTicks, TickItemType } from '../hooks/useTicks';
import { AxisDefaultized, ChartsXAxisProps } from '../models/axis';
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
Expand Down Expand Up @@ -98,7 +98,7 @@ const defaultProps = {
* - [ChartsXAxis API](https://mui.com/x/api/charts/charts-x-axis/)
*/
function ChartsXAxis(inProps: ChartsXAxisProps) {
const { xAxisIds, xAxis } = React.useContext(CartesianContext);
const { xAxisIds, xAxis } = useCartesianContext();
const { scale: xScale, tickNumber, reverse, ...settings } = xAxis[inProps.axisId ?? xAxisIds[0]];

const isMounted = useMounted();
Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/ChartsYAxis/ChartsYAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { useSlotProps } from '@mui/base/utils';
import { unstable_composeClasses as composeClasses } from '@mui/utils';
import { useThemeProps, useTheme, Theme } from '@mui/material/styles';
import { CartesianContext } from '../context/CartesianContextProvider';
import { useCartesianContext } from '../context/CartesianProvider';
import { useTicks } from '../hooks/useTicks';
import { useDrawingArea } from '../hooks/useDrawingArea';
import { ChartsYAxisProps } from '../models/axis';
Expand Down Expand Up @@ -44,7 +44,7 @@ const defaultProps = {
* - [ChartsYAxis API](https://mui.com/x/api/charts/charts-y-axis/)
*/
function ChartsYAxis(inProps: ChartsYAxisProps) {
const { yAxisIds, yAxis } = React.useContext(CartesianContext);
const { yAxisIds, yAxis } = useCartesianContext();
const { scale: yScale, tickNumber, ...settings } = yAxis[inProps.axisId ?? yAxisIds[0]];

const themedProps = useThemeProps({ props: { ...settings, ...inProps }, name: 'MuiChartsYAxis' });
Expand Down
7 changes: 4 additions & 3 deletions packages/x-charts/src/LineChart/AreaPlot.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { area as d3Area } from 'd3-shape';
import { CartesianContext } from '../context/CartesianContextProvider';
import { useCartesianContext } from '../context/CartesianProvider';
import {
AreaElement,
AreaElementProps,
Expand All @@ -14,6 +14,7 @@ import { DEFAULT_X_AXIS_KEY } from '../constants';
import { LineItemIdentifier } from '../models/seriesType/line';
import { useChartGradient } from '../internals/components/ChartsAxesGradients';
import { useLineSeries } from '../hooks/useSeries';
import { AxisId } from '../models/axis';

export interface AreaPlotSlots extends AreaElementSlots {}

Expand All @@ -35,7 +36,7 @@ export interface AreaPlotProps

const useAggregatedData = () => {
const seriesData = useLineSeries();
const axisData = React.useContext(CartesianContext);
const axisData = useCartesianContext();

if (seriesData === undefined) {
return [];
Expand All @@ -62,7 +63,7 @@ const useAggregatedData = () => {
const yScale = yAxis[yAxisKey].scale;
const xData = xAxis[xAxisKey].data;

const gradientUsed: [string, 'x' | 'y'] | undefined =
const gradientUsed: [AxisId, 'x' | 'y'] | undefined =
(yAxis[yAxisKey].colorScale && [yAxisKey, 'y']) ||
(xAxis[xAxisKey].colorScale && [xAxisKey, 'x']) ||
undefined;
Expand Down
Loading