Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 增加onChange回调函数 #2005

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 15 additions & 38 deletions packages/f2/src/components/zoom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface ZoomProps {
onPanEnd?: Function;
onPinchEnd?: Function;
onInit?: Function;
onChange?: Function;
/**
* 自动同步 x/y 的坐标值
*/
Expand Down Expand Up @@ -239,17 +240,13 @@ export default (View) => {

onPanStart = () => {
const { scale } = this;
const {
onPanStart,
} = this.props;
const { onPanStart } = this.props;
this.onStart();
onPanStart?.({ scale });
}
};

onPan = (ev) => {
const {
onPan,
} = this.props;
const { onPan } = this.props;
const { dims } = this;

const range = {};
Expand All @@ -268,28 +265,21 @@ export default (View) => {
onPan?.(ev);
};


onPanEnd = () => {
const { scale } = this;
const {
onPanEnd,
} = this.props;
const { onPanEnd } = this.props;
this.onEnd();
onPanEnd?.({ scale });
}
};

onPinchStart = () => {
const {
onPinchStart,
} = this.props;
const { onPinchStart } = this.props;
this.onStart();
onPinchStart?.();
}
};

onPinch = (ev) => {
const {
onPinch,
} = this.props;
const { onPinch } = this.props;
const { dims } = this;
const range = {};
each(dims, (dim) => {
Expand All @@ -308,20 +298,13 @@ export default (View) => {

onPinchEnd = () => {
const { scale } = this;
const {
onPinchEnd,
} = this.props;
const { onPinchEnd } = this.props;
this.onEnd();
onPinchEnd?.({ scale });
}
};

_bindEvents() {
const {
chart,
pan,
pinch,
swipe,
} = this.props;
const { chart, pan, pinch, swipe } = this.props;

// 统一绑定事件
if (pan !== false) {
Expand All @@ -342,12 +325,7 @@ export default (View) => {
}

_unBindEvents() {
const {
chart,
pan,
pinch,
swipe,
} = this.props;
const { chart, pan, pinch, swipe } = this.props;

// 统一绑定事件
if (pan !== false) {
Expand All @@ -374,7 +352,6 @@ export default (View) => {
this._cancelAnimationFrame();
};


update() {
const { startX, startY, endX, endY } = this.swipeEnd;
const x = lerp(startX, endX, 0.05);
Expand Down Expand Up @@ -483,7 +460,6 @@ export default (View) => {
this.update();
};


onEnd = () => {
this.startRange = null;
};
Expand Down Expand Up @@ -645,7 +621,8 @@ export default (View) => {
renderRange(range) {
const { state, props } = this;
if (isEqualRange(range, state.range)) return;
const { chart } = props;
const { chart, onChange } = props;
onChange && onChange({ range });
// 手势变化不执行动画
const { animate } = chart;
chart.setAnimate(false);
Expand Down
Loading