Skip to content

Commit

Permalink
feat: 增加onRangeChange回调函数 (#2005)
Browse files Browse the repository at this point in the history
Co-authored-by: xuying.xu <xuying.xu@alibaba-inc.com>
  • Loading branch information
tangying1027 and xuying.xu authored Oct 9, 2024
1 parent ee4f100 commit 97ba27b
Showing 1 changed file with 15 additions and 38 deletions.
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

0 comments on commit 97ba27b

Please sign in to comment.