Skip to content

Commit 825bcfc

Browse files
zamhownkkxxkk2019
authored andcommitted
fix: gauge pointer default position
1 parent 283ed91 commit 825bcfc

4 files changed

Lines changed: 21 additions & 9 deletions

File tree

docs/assets/examples/en/gauge-chart/gauge-track.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const spec = {
9292
visible: true,
9393
width: 0.04,
9494
height: 0.04,
95+
inOnCenter: false,
9596
style: {
9697
fill: {
9798
type: 'threshold',
@@ -107,6 +108,7 @@ const spec = {
107108
pointer: {
108109
width: 0.2,
109110
height: 0.1,
111+
inOnCenter: false,
110112
style: {
111113
fill: {
112114
type: 'threshold',

docs/assets/examples/zh/gauge-chart/gauge-track.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const spec = {
9292
visible: true,
9393
width: 0.04,
9494
height: 0.04,
95+
inOnCenter: false,
9596
style: {
9697
fill: {
9798
type: 'threshold',
@@ -107,6 +108,7 @@ const spec = {
107108
pointer: {
108109
width: 0.2,
109110
height: 0.1,
111+
inOnCenter: false,
110112
style: {
111113
fill: {
112114
type: 'threshold',

packages/vchart/src/series/gauge/gauge-pointer.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MarkTypeEnum } from '../../mark/interface/type';
44
import { isValid } from '@visactor/vutils';
55
import type { SeriesMarkMap } from '../interface';
66
import { SeriesMarkNameEnum, SeriesTypeEnum } from '../interface/type';
7-
import type { IGaugePointerSeriesSpec, IGaugePointerSeriesTheme } from './interface';
7+
import type { IGaugePointerSeriesSpec, IGaugePointerSeriesTheme, PinMarkSpec, PointerMarkSpec } from './interface';
88
import type { Datum, Maybe } from '../../typings';
99
import type { IPathMark } from '../../mark/path';
1010
import { animationConfig, userAnimationConfig } from '../../animation/utils';
@@ -71,17 +71,17 @@ export class GaugePointerSeries<
7171
if (pointerMark) {
7272
this.setMarkStyle(pointerMark, {
7373
x: (datum: Datum) => {
74-
const { x } = this._getPointerAnchor(datum);
74+
const { x } = this._getPointerAnchor(datum, pointerSpec);
7575
const dx = this._getPointerWidth() * (pointerSpec?.center?.[0] ?? 0);
7676
return x - dx;
7777
},
7878
y: (datum: Datum) => {
79-
const { y } = this._getPointerAnchor(datum);
79+
const { y } = this._getPointerAnchor(datum, pointerSpec);
8080
const dy = this._getPointerHeight(datum) * (pointerSpec?.center?.[1] ?? 0);
8181
return y - dy;
8282
},
8383
anchor: (datum: Datum) => {
84-
const { x, y } = this._getPointerAnchor(datum);
84+
const { x, y } = this._getPointerAnchor(datum, pointerSpec);
8585
return [x, y];
8686
},
8787
fill: this.getColorAttribute(),
@@ -110,7 +110,10 @@ export class GaugePointerSeries<
110110
this._pointerMark && this._tooltipHelper.activeTriggerSet.mark.add(this._pointerMark);
111111
}
112112

113-
protected _getPointerAnchor(datum: Datum) {
113+
protected _getPointerAnchor(datum: Datum, markSpec: PinMarkSpec | PointerMarkSpec) {
114+
if (markSpec.isOnCenter ?? true) {
115+
return this.angleAxisHelper.center();
116+
}
114117
return this.radiusAxisHelper.coordToPoint({
115118
radius: this._innerRadius * this._computeLayoutRadius(),
116119
angle: this.angleAxisHelper.dataToPosition([datum[this._angleField[0]]])
@@ -158,8 +161,8 @@ export class GaugePointerSeries<
158161
const pinBackgroundSpec = this._spec.pinBackground;
159162
if (pinBackgroundMark) {
160163
this.setMarkStyle(pinBackgroundMark, {
161-
x: (datum: Datum) => this._getPointerAnchor(datum).x,
162-
y: (datum: Datum) => this._getPointerAnchor(datum).y,
164+
x: (datum: Datum) => this._getPointerAnchor(datum, pinBackgroundSpec).x,
165+
y: (datum: Datum) => this._getPointerAnchor(datum, pinBackgroundSpec).y,
163166
scaleX: () => pinBackgroundSpec.width * this._computeLayoutRadius(),
164167
scaleY: () => pinBackgroundSpec.height * this._computeLayoutRadius(),
165168
fill: this.getColorAttribute(),
@@ -173,8 +176,8 @@ export class GaugePointerSeries<
173176
const pinSpec = this._spec.pin;
174177
if (pinMark) {
175178
this.setMarkStyle(pinMark, {
176-
x: (datum: Datum) => this._getPointerAnchor(datum).x,
177-
y: (datum: Datum) => this._getPointerAnchor(datum).y,
179+
x: (datum: Datum) => this._getPointerAnchor(datum, pinSpec).x,
180+
y: (datum: Datum) => this._getPointerAnchor(datum, pinSpec).y,
178181
scaleX: () => pinSpec.width * this._computeLayoutRadius(),
179182
scaleY: () => pinSpec.height * this._computeLayoutRadius(),
180183
fill: this.getColorAttribute(),

packages/vchart/src/series/gauge/interface.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ export type PointerMarkSpec = {
4141

4242
/** 中心点坐标(0~1) */
4343
center?: [number, number];
44+
45+
/** 是否定位于极坐标系的中心,默认为 true。如果为 false,则位置受 innerRadius 影响 */
46+
isOnCenter?: boolean;
4447
};
4548

4649
export type PinMarkSpec = {
4750
/** 宽度 */
4851
width?: number;
4952
/** 高度 */
5053
height?: number;
54+
/** 是否定位于极坐标系的中心,默认为 true。如果为 false,则位置受 innerRadius 影响 */
55+
isOnCenter?: boolean;
5156
};
5257

5358
export interface IGaugePointerSeriesTheme extends IProgressLikeSeriesTheme {

0 commit comments

Comments
 (0)