Skip to content

Commit bdd6fcc

Browse files
committed
refactor(charts): rename to isFullCircle and compute for all rotation axes
Address review feedback: rename the flag to `isFullCircle` and compute it for every rotation axis (point/band/continuous), not only the point-scale branch. Wire the flag through to `ChartsRadiusGrid` as a prop so it drops its local `EPSILON`-based derivation. The point-scale shortening keeps its existing `2π - 0.1` threshold as a local decision.
1 parent c07e306 commit bdd6fcc

4 files changed

Lines changed: 26 additions & 34 deletions

File tree

packages/x-charts/src/ChartsRadialGrid/ChartsRadialGrid.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ function ChartsRadialGrid(inProps: ChartsRadialGridProps) {
6666
const outerRadius = radiusAxisConfig?.scale.range()[1] ?? 0;
6767

6868
const startAngle = rotationAxisConfig?.scale.range()[0] ?? 0;
69-
const endAngle = rotationAxisConfig?.isPointScaleFullCircle
70-
? startAngle + 2 * Math.PI
71-
: (rotationAxisConfig?.scale.range()[1] ?? 0);
69+
const endAngle = rotationAxisConfig?.scale.range()[1] ?? 0;
70+
const isFullCircle = rotationAxisConfig?.isFullCircle ?? false;
7271

7372
return (
7473
<GridRoot {...other} className={clsx(classes.root, className)}>
@@ -86,6 +85,7 @@ function ChartsRadialGrid(inProps: ChartsRadialGridProps) {
8685
axis={radiusAxisConfig}
8786
startAngle={startAngle}
8887
endAngle={endAngle}
88+
isFullCircle={isFullCircle}
8989
classes={classes}
9090
/>
9191
)}

packages/x-charts/src/ChartsRadialGrid/ChartsRadiusGrid.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import {
88
type UseChartPolarAxisSignature,
99
} from '../internals/plugins/featurePlugins/useChartPolarAxis';
1010
import { type PolarAxisDefaultized } from '../models/axis';
11-
import { EPSILON } from '../utils/epsilon';
1211

1312
interface ChartsRadiusGridProps {
1413
axis: PolarAxisDefaultized<any, any, any>;
1514
startAngle: number;
1615
endAngle: number;
16+
isFullCircle: boolean;
1717
classes: Partial<ChartsRadialGridClasses>;
1818
}
1919

@@ -22,7 +22,7 @@ interface ChartsRadiusGridProps {
2222
*/
2323
export function ChartsRadiusGrid(props: ChartsRadiusGridProps) {
2424
const { store } = useChartsContext<[UseChartPolarAxisSignature]>();
25-
const { axis, startAngle, endAngle, classes } = props;
25+
const { axis, startAngle, endAngle, isFullCircle, classes } = props;
2626
const { cx, cy } = store.use(selectorChartPolarCenter);
2727

2828
const { scale, tickNumber, tickInterval, tickSpacing } = axis;
@@ -35,8 +35,6 @@ export function ChartsRadiusGrid(props: ChartsRadiusGridProps) {
3535
direction: 'radius',
3636
});
3737

38-
const isFullCircle = Math.abs(endAngle - startAngle) >= 2 * Math.PI - EPSILON;
39-
4038
if (isFullCircle) {
4139
return (
4240
<React.Fragment>

packages/x-charts/src/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.ts

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { deg2rad } from '../../../angleConversion';
2626
import { getAxisTriggerTooltip } from './getAxisTriggerTooltip';
2727
import { scaleBand, scalePoint } from '../../../scales';
2828
import { type ComputedAxisConfig } from '../useChartCartesianAxis';
29+
import { EPSILON } from '../../../../utils/epsilon';
2930

3031
export type DefaultizedAxisConfig<
3132
AxisProps extends ChartsRotationAxisProps | ChartsRadiusAxisProps,
@@ -40,36 +41,27 @@ function getRange(
4041
drawingArea: ChartDrawingArea,
4142
axisDirection: 'rotation' | 'radius',
4243
axis: PolarAxisConfig<ScaleName, any>,
43-
): { range: number[]; isPointScaleFullCircle: boolean } {
44+
): { range: number[]; isFullCircle: boolean } {
4445
if (axisDirection === 'rotation') {
45-
if (axis.scaleType === 'point') {
46-
const angles = [
47-
deg2rad((axis as RotationConfig).startAngle, 0),
48-
deg2rad((axis as RotationConfig).endAngle, 2 * Math.PI),
49-
];
50-
const diff = angles[1] - angles[0];
51-
const isPointScaleFullCircle = diff > Math.PI * 2 - 0.1;
52-
if (isPointScaleFullCircle) {
53-
// If we cover a full circle, we remove a slice to avoid having data point at the same place.
54-
angles[1] -= diff / axis.data!.length;
55-
}
56-
return { range: angles, isPointScaleFullCircle };
46+
const angles = [
47+
deg2rad((axis as RotationConfig).startAngle, 0),
48+
deg2rad((axis as RotationConfig).endAngle, 2 * Math.PI),
49+
];
50+
const diff = angles[1] - angles[0];
51+
const isFullCircle = diff >= Math.PI * 2 - EPSILON;
52+
if (axis.scaleType === 'point' && diff > Math.PI * 2 - 0.1) {
53+
// For point scale, remove a slice to avoid overlapping first and last points.
54+
angles[1] -= diff / axis.data!.length;
5755
}
58-
return {
59-
range: [
60-
deg2rad((axis as RotationConfig).startAngle, 0),
61-
deg2rad((axis as RotationConfig).endAngle, 2 * Math.PI),
62-
],
63-
isPointScaleFullCircle: false,
64-
};
56+
return { range: angles, isFullCircle };
6557
}
6658
const availableRadius = Math.min(drawingArea.height, drawingArea.width) / 2;
6759
return {
6860
range: [
6961
(axis as RadiusConfig).minRadius ?? 0,
7062
(axis as RadiusConfig).maxRadius ?? availableRadius,
7163
],
72-
isPointScaleFullCircle: false,
64+
isFullCircle: false,
7365
};
7466
}
7567

@@ -126,7 +118,7 @@ export function computeAxisValue<SeriesType extends ChartSeriesType>({
126118
const completeAxis: DefaultizedAxisConfig<ChartsAxisProps> = {};
127119
allAxis.forEach((eachAxis, axisIndex) => {
128120
const axis = eachAxis as Readonly<AxisConfig<ScaleName, any, Readonly<ChartsAxisProps>>>;
129-
const { range, isPointScaleFullCircle } = getRange(drawingArea, axisDirection, axis);
121+
const { range, isFullCircle } = getRange(drawingArea, axisDirection, axis);
130122

131123
const [minData, maxData] = getAxisExtremum(
132124
axis,
@@ -160,6 +152,7 @@ export function computeAxisValue<SeriesType extends ChartSeriesType>({
160152
(axis.colorMap.type === 'ordinal'
161153
? getOrdinalColorScale({ values: axis.data, ...axis.colorMap })
162154
: getColorScale(axis.colorMap)),
155+
isFullCircle,
163156
};
164157

165158
if (isDateData(axis.data)) {
@@ -180,7 +173,7 @@ export function computeAxisValue<SeriesType extends ChartSeriesType>({
180173
(axis.colorMap.type === 'ordinal'
181174
? getOrdinalColorScale({ values: axis.data, ...axis.colorMap })
182175
: getColorScale(axis.colorMap)),
183-
isPointScaleFullCircle,
176+
isFullCircle,
184177
};
185178

186179
if (isDateData(axis.data)) {
@@ -231,6 +224,7 @@ export function computeAxisValue<SeriesType extends ChartSeriesType>({
231224
scale: finalScale.domain(domain) as any,
232225
tickNumber,
233226
colorScale: axis.colorMap && getColorScale(axis.colorMap),
227+
isFullCircle,
234228
};
235229
});
236230
return {

packages/x-charts/src/models/axis.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,8 @@ export type PolarAxisDefaultized<
609609
* If true, the contents of the axis will be displayed by a tooltip with `trigger='axis'`.
610610
*/
611611
triggerTooltip?: boolean;
612-
/** @ignore - internal. True when a point-scale rotation axis covers a full circle. */
613-
isPointScaleFullCircle?: boolean;
612+
/** @ignore - internal. True when a rotation axis covers a full circle. */
613+
isFullCircle?: boolean;
614614
};
615615

616616
export type ComputedAxis<
@@ -628,8 +628,8 @@ export type ComputedAxis<
628628
* Indicate if the axis should be consider by a tooltip with `trigger='axis'`.
629629
*/
630630
triggerTooltip?: boolean;
631-
/** @ignore - internal. True when a point-scale rotation axis covers a full circle. */
632-
isPointScaleFullCircle?: boolean;
631+
/** @ignore - internal. True when a rotation axis covers a full circle. */
632+
isFullCircle?: boolean;
633633
} & (AxisProps extends ChartsXAxisProps
634634
? AxisSideConfig<AxisProps> & { height: number }
635635
: AxisProps extends ChartsYAxisProps

0 commit comments

Comments
 (0)