Skip to content

Commit fa1035f

Browse files
committed
feat: support polygon crosshair for angleAxis in polar coordinate
1 parent 77eba1e commit fa1035f

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

packages/vchart/src/component/crosshair/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export interface IHair {
5454
};
5555
}
5656

57-
export interface IHairRadius extends IHair {
57+
export interface IPolarHair extends IHair {
5858
smooth?: boolean;
5959
}
6060

packages/vchart/src/component/crosshair/interface/spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ export interface ICrosshairRectSpec {
126126
* @default '100%''
127127
*/
128128
width?: number | string | ICrosshairRectWidthCallback;
129+
/** 极坐标系下是否平滑 */
130+
smooth?: boolean;
129131
style?: ICrosshairRectStyle;
130132
}
131133

packages/vchart/src/component/crosshair/polar.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ import { ComponentTypeEnum } from '../interface/type';
55
import type { AxisCurrentValueMap, IPolarCrosshairInfo, IPolarCrosshairSpec } from './interface';
66
import { isDiscrete } from '@visactor/vscale';
77
import { Tag } from '@visactor/vrender-components';
8-
import { LineCrosshair, SectorCrosshair, CircleCrosshair, PolygonCrosshair } from '@visactor/vrender-components';
8+
import {
9+
LineCrosshair,
10+
SectorCrosshair,
11+
CircleCrosshair,
12+
PolygonCrosshair,
13+
PolygonSectorCrosshair
14+
} from '@visactor/vrender-components';
915
import type { IPolarAxis } from '../axis/polar/interface';
1016
import type { IPoint, StringOrNumber, TooltipActiveType, TooltipData } from '../../typings';
11-
import type { IAxisInfo, IHair, IHairRadius } from './base';
17+
import type { IAxisInfo, IHair, IPolarHair } from './base';
1218
import { BaseCrossHair } from './base';
1319
import type { Maybe } from '@visactor/vutils';
1420
import { polarToCartesian, PointService, isArray, isNil } from '@visactor/vutils';
@@ -32,8 +38,8 @@ export class PolarCrossHair<T extends IPolarCrosshairSpec = IPolarCrosshairSpec>
3238
private _currValueAngle: AxisCurrentValueMap;
3339
private _currValueRadius: AxisCurrentValueMap;
3440

35-
private _angleHair: IHair | undefined;
36-
private _radiusHair: IHairRadius | undefined;
41+
private _angleHair: IPolarHair | undefined;
42+
private _radiusHair: IPolarHair | undefined;
3743

3844
private _cacheAngleCrossHairInfo: IPolarCrosshairInfo | undefined;
3945
private _cacheRadiusCrossHairInfo: IPolarCrosshairInfo | undefined;
@@ -267,9 +273,11 @@ export class PolarCrossHair<T extends IPolarCrosshairSpec = IPolarCrosshairSpec>
267273
}
268274

269275
const container = this.getContainer();
270-
const { angle, radius, label, center, visible } = crosshairInfo;
276+
const { angle, radius, label, center, visible, axis } = crosshairInfo;
271277
if (visible) {
272-
const crosshairType = this._angleHair.type === 'rect' ? 'sector' : 'line';
278+
const isSmooth = this._angleHair.smooth === true;
279+
const crosshairType = this._angleHair.type === 'rect' ? (isSmooth ? 'sector' : 'polygon-sector') : 'line';
280+
273281
const positionAttrs = layoutAngleCrosshair(this._angleHair, crosshairInfo);
274282

275283
if (this._angleCrosshair) {
@@ -297,6 +305,20 @@ export class PolarCrossHair<T extends IPolarCrosshairSpec = IPolarCrosshairSpec>
297305
zIndex: this.gridZIndex,
298306
pickable: false
299307
});
308+
} else if (crosshairType === 'polygon-sector') {
309+
crosshair = new PolygonSectorCrosshair({
310+
...(positionAttrs as {
311+
center: IPoint;
312+
innerRadius: number;
313+
radius: number;
314+
startAngle: number;
315+
endAngle: number;
316+
}),
317+
offset: axis.getSpec()?.offset ?? 0.5,
318+
polygonSectorStyle: this._angleHair.style,
319+
zIndex: this.gridZIndex,
320+
pickable: false
321+
});
300322
}
301323
this._angleCrosshair = crosshair as unknown as IGroup;
302324
// 添加至场景树
@@ -389,6 +411,7 @@ export class PolarCrossHair<T extends IPolarCrosshairSpec = IPolarCrosshairSpec>
389411
const { categoryField, valueField } = this._spec as IPolarCrosshairSpec;
390412
if (categoryField && categoryField.visible) {
391413
this._angleHair = this._parseField(categoryField, 'categoryField');
414+
this._angleHair.smooth = categoryField?.line?.smooth;
392415
}
393416
if (valueField && valueField.visible) {
394417
this._radiusHair = this._parseField(valueField, 'valueField');

packages/vchart/src/component/crosshair/utils/polar.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BandScale } from '@visactor/vscale';
22
import type { IPolarSeries } from '../../../series';
3-
import type { IHair, IHairRadius } from '../base';
3+
import type { IHair, IPolarHair } from '../base';
44
import type { AxisCurrentValueMap, IPolarCrosshairInfo } from '../interface';
55
import { getAxisLabelOffset } from '../../axis/util';
66
import { PointService, clamp, getAngleByPoint, getIntersectPoint, isValid, polarToCartesian } from '@visactor/vutils';
@@ -63,6 +63,7 @@ export const layoutByValue = (
6363

6464
angleCrossHairInfo.startAngle = angle - bandWidth / 2;
6565
angleCrossHairInfo.endAngle = angle + bandWidth / 2;
66+
angleCrossHairInfo.axis = axis as IPolarAxis;
6667
});
6768
}
6869

@@ -152,7 +153,7 @@ export const layoutAngleCrosshair = (angleHair: IHair, crosshairInfo: IPolarCros
152153
return positionAttrs;
153154
};
154155

155-
export const layoutRadiusCrosshair = (radiusHair: IHairRadius, crosshairInfo: IPolarCrosshairInfo) => {
156+
export const layoutRadiusCrosshair = (radiusHair: IPolarHair, crosshairInfo: IPolarCrosshairInfo) => {
156157
const { center, startAngle, endAngle, distance, sides, axis, point, radius, innerRadius } = crosshairInfo;
157158

158159
const crosshairType = radiusHair.smooth ? 'circle' : 'polygon';

0 commit comments

Comments
 (0)