Skip to content

Commit

Permalink
fix(chart): 修复 gesture 重复创建 (#1820)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue authored Jul 27, 2023
1 parent fd89b46 commit 8fa1e63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions packages/f2/src/chart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Component,
Children,
jsx,
Gesture,
Ref,
createRef,
} from '@antv/f-engine';
Expand Down Expand Up @@ -63,7 +62,6 @@ class Chart<
public coord: CoordController;
public scale: ScaleController;

public gesture: Gesture;
public coordRef: Ref;
constructor(props: IProps, context?: IContext) {
super(props);
Expand Down Expand Up @@ -141,12 +139,17 @@ class Chart<
}

on(eventName: string, listener: (...args: any[]) => void) {
this.gesture = this.gesture ? this.gesture : new Gesture(this.coordRef.current);
this.gesture.on(eventName, listener);
const roolEl = this.coordRef.current;
if (!roolEl || !roolEl.gesture) return;
const gesture = roolEl.gesture;
gesture.on(eventName, listener);
}

off(eventName: string, listener: (...args: any[]) => void) {
this.gesture.off(eventName, listener);
const roolEl = this.coordRef.current;
if (!roolEl || !roolEl.gesture) return;
const gesture = roolEl.gesture;
gesture.off(eventName, listener);
}

// 给需要显示的组件留空
Expand Down
4 changes: 2 additions & 2 deletions site/examples/candlestick/candlestick/demo/base.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const data = [
const { props } = (
<Canvas context={context} pixelRatio={window.devicePixelRatio}>
<Chart data={data}>
<Axis field="time" />
<Axis field="value" />
<Axis field="time" type="timeCat" />
<Axis field="value" formatter={(v) => Number(v).toFixed(0)} />
<Candlestick x="time" y="value" />
<Tooltip showCrosshairs={true} yPositionType="coord" crosshairsType="xy" showXTip showYTip />
</Chart>
Expand Down

0 comments on commit 8fa1e63

Please sign in to comment.