Skip to content

Commit

Permalink
move to plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
JCQuintas committed Jan 31, 2025
1 parent 12e239f commit 86b3461
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
17 changes: 0 additions & 17 deletions packages/x-charts/src/ChartsAxis/ChartsAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
ChartsYAxisProps,
} from '../models/axis';
import { useXAxes, useYAxes } from '../hooks';
import { useChartContext } from '../context/ChartProvider';

export interface ChartsAxisProps {
/**
Expand Down Expand Up @@ -90,7 +89,6 @@ function ChartsAxis(props: ChartsAxisProps) {
const { topAxis, leftAxis, rightAxis, bottomAxis, slots, slotProps } = props;
const { xAxis, xAxisIds } = useXAxes();
const { yAxis, yAxisIds } = useYAxes();
const { instance } = useChartContext();

const leftId = getAxisId(leftAxis === undefined ? yAxisIds[0] : leftAxis, yAxisIds[0]);
const bottomId = getAxisId(bottomAxis === undefined ? xAxisIds[0] : bottomAxis, xAxisIds[0]);
Expand Down Expand Up @@ -134,21 +132,6 @@ function ChartsAxis(props: ChartsAxisProps) {
const leftAxisProps = mergeProps(leftAxis, slots, slotProps);
const rightAxisProps = mergeProps(rightAxis, slots, slotProps);

React.useEffect(() => {
if (topId) {
instance.addAxisSide('top');
}
if (bottomId) {
instance.addAxisSide('bottom');
}
if (leftId) {
instance.addAxisSide('left');
}
if (rightId) {
instance.addAxisSide('right');
}
}, [topId, bottomId, leftId, rightId, instance]);

return (
<React.Fragment>
{topId && <ChartsXAxis {...topAxisProps} position="top" axisId={topId} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { defaultizeAxis } from './defaultizeAxis';

export const useChartCartesianAxis: ChartPlugin<
UseChartCartesianAxisSignature<ChartSeriesType>
> = ({ params, store, seriesConfig }) => {
> = ({ params, store, seriesConfig, instance }) => {
const { xAxis, yAxis, dataset } = params;

if (process.env.NODE_ENV !== 'production') {
Expand All @@ -31,6 +31,13 @@ export const useChartCartesianAxis: ChartPlugin<
}
}

React.useEffect(() => {
instance.addAxisSide('top');
instance.addAxisSide('bottom');
instance.addAxisSide('left');
instance.addAxisSide('right');
}, [instance]);

const drawingArea = useSelector(store, selectorChartDrawingArea);
const formattedSeries = useSelector(store, selectorChartSeriesState);

Expand Down

0 comments on commit 86b3461

Please sign in to comment.