1- import { type AxisConfig , type ScaleName } from '../../../../models' ;
1+ import type { ContinuousScaleName , AxisConfig , ScaleName } from '../../../../models' ;
22import {
33 type ChartsAxisProps ,
44 isBandScaleConfig ,
55 isPointScaleConfig ,
6+ isContinuousScaleConfig ,
67 type ChartsRotationAxisProps ,
78 type ChartsRadiusAxisProps ,
89 type PolarAxisDefaultized ,
910 type AxisId ,
1011 type PolarAxisConfig ,
11- isContinuousScaleConfig ,
12+ type ComputedAxis ,
1213} from '../../../../models/axis' ;
1314import {
1415 type ChartSeriesType ,
@@ -26,6 +27,7 @@ import { deg2rad } from '../../../angleConversion';
2627import { getAxisTriggerTooltip } from './getAxisTriggerTooltip' ;
2728import { scaleBand , scalePoint } from '../../../scales' ;
2829import { type ComputedAxisConfig } from '../useChartCartesianAxis' ;
30+ import { EPSILON } from '../../../../utils/epsilon' ;
2931
3032export type DefaultizedAxisConfig <
3133 AxisProps extends ChartsRotationAxisProps | ChartsRadiusAxisProps ,
@@ -40,30 +42,28 @@ function getRange(
4042 drawingArea : ChartDrawingArea ,
4143 axisDirection : 'rotation' | 'radius' ,
4244 axis : PolarAxisConfig < ScaleName , any > ,
43- ) {
45+ ) : { range : number [ ] ; isFullCircle : boolean } {
4446 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- if ( diff > Math . PI * 2 - 0.1 ) {
52- // If we cover a full circle, we remove a slice to avoid having data point at the same place.
53- angles [ 1 ] -= diff / axis . data ! . length ;
54- }
55- return angles ;
56- }
57- return [
47+ const angles = [
5848 deg2rad ( ( axis as RotationConfig ) . startAngle , 0 ) ,
5949 deg2rad ( ( axis as RotationConfig ) . endAngle , 2 * Math . PI ) ,
6050 ] ;
51+ const diff = angles [ 1 ] - angles [ 0 ] ;
52+ const isFullCircle = diff >= Math . PI * 2 - EPSILON ;
53+ if ( axis . scaleType === 'point' && isFullCircle ) {
54+ // For point scale, remove a slice to avoid overlapping first and last points.
55+ angles [ 1 ] -= diff / axis . data ! . length ;
56+ }
57+ return { range : angles , isFullCircle } ;
6158 }
6259 const availableRadius = Math . min ( drawingArea . height , drawingArea . width ) / 2 ;
63- return [
64- ( axis as RadiusConfig ) . minRadius ?? 0 ,
65- ( axis as RadiusConfig ) . maxRadius ?? availableRadius ,
66- ] ;
60+ return {
61+ range : [
62+ ( axis as RadiusConfig ) . minRadius ?? 0 ,
63+ ( axis as RadiusConfig ) . maxRadius ?? availableRadius ,
64+ ] ,
65+ isFullCircle : false ,
66+ } ;
6767}
6868
6969const DEFAULT_CATEGORY_GAP_RATIO = 0.2 ;
@@ -116,10 +116,10 @@ export function computeAxisValue<SeriesType extends ChartSeriesType>({
116116 allAxis [ 0 ] . id ,
117117 ) ;
118118
119- const completeAxis : DefaultizedAxisConfig < ChartsAxisProps > = { } ;
119+ const completeAxis : ComputedAxisConfig < ChartsAxisProps > = { } ;
120120 allAxis . forEach ( ( eachAxis , axisIndex ) => {
121121 const axis = eachAxis as Readonly < AxisConfig < ScaleName , any , Readonly < ChartsAxisProps > > > ;
122- const range = getRange ( drawingArea , axisDirection , axis ) ;
122+ const { range, isFullCircle } = getRange ( drawingArea , axisDirection , axis ) ;
123123
124124 const [ minData , maxData ] = getAxisExtremum (
125125 axis ,
@@ -153,7 +153,8 @@ export function computeAxisValue<SeriesType extends ChartSeriesType>({
153153 ( axis . colorMap . type === 'ordinal'
154154 ? getOrdinalColorScale ( { values : axis . data , ...axis . colorMap } )
155155 : getColorScale ( axis . colorMap ) ) ,
156- } ;
156+ isFullCircle,
157+ } as ComputedAxis < 'band' , any , ChartsAxisProps > ;
157158
158159 if ( isDateData ( axis . data ) ) {
159160 const dateFormatter = createDateFormatter ( axis . data , range , axis . tickNumber ) ;
@@ -173,7 +174,8 @@ export function computeAxisValue<SeriesType extends ChartSeriesType>({
173174 ( axis . colorMap . type === 'ordinal'
174175 ? getOrdinalColorScale ( { values : axis . data , ...axis . colorMap } )
175176 : getColorScale ( axis . colorMap ) ) ,
176- } ;
177+ isFullCircle,
178+ } as ComputedAxis < 'point' , any , ChartsAxisProps > ;
177179
178180 if ( isDateData ( axis . data ) ) {
179181 const dateFormatter = createDateFormatter ( axis . data , range , axis . tickNumber ) ;
@@ -223,7 +225,7 @@ export function computeAxisValue<SeriesType extends ChartSeriesType>({
223225 scale : finalScale . domain ( domain ) as any ,
224226 tickNumber,
225227 colorScale : axis . colorMap && getColorScale ( axis . colorMap ) ,
226- } ;
228+ } as ComputedAxis < ContinuousScaleName , any , ChartsAxisProps > ;
227229 } ) ;
228230 return {
229231 axis : completeAxis ,
0 commit comments