Skip to content

Commit

Permalink
feat: 修改tooltip & zoom事件监听 (#1720)
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 Feb 10, 2023
1 parent f741414 commit 00c082b
Show file tree
Hide file tree
Showing 13 changed files with 461 additions and 461 deletions.
3 changes: 2 additions & 1 deletion packages/f2/src/components/scrollBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import withScrollBar, { ScrollBarProps } from './withScrollBar';
import ScrollBarView from './scrollBarView';
import withZoom from '../zoom';

export { ScrollBarProps, withScrollBar, ScrollBarView };
export default withScrollBar(ScrollBarView);
export default withZoom(withScrollBar(ScrollBarView));
5 changes: 3 additions & 2 deletions packages/f2/src/components/scrollBar/withScrollBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { jsx } from '@antv/f-engine';
import { Component, jsx } from '@antv/f-engine';
import Zoom, { ZoomProps } from '../zoom';
import { ChartChildProps } from '../../chart';

export interface ScrollBarProps extends ZoomProps {
/**
Expand All @@ -17,7 +18,7 @@ export interface ScrollBarProps extends ZoomProps {
}

export default (View) => {
return class ScrollBar extends Zoom<ScrollBarProps> {
return class ScrollBar extends Component<ScrollBarProps & ChartChildProps> {
willMount() {
super.willMount();
const { context, props } = this;
Expand Down
68 changes: 38 additions & 30 deletions packages/f2/src/components/tooltip/withTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export default (View) => {

didMount() {
this._initShow();
this._initEvent();
}

willReceiveProps(nextProps) {
Expand All @@ -117,17 +116,6 @@ export default (View) => {
}
}

didUnmount(): void {
this._clearEvents();
}

_clearEvents() {
const { props, context } = this;
const { triggerOn = 'press', triggerOff = 'pressend' } = props;
// 解绑事件
context.gesture.off(triggerOn, this._triggerOn);
context.gesture.off(triggerOff, this._triggerOff);
}
_initShow() {
const { props } = this;
const { defaultItem } = props;
Expand Down Expand Up @@ -156,20 +144,6 @@ export default (View) => {
this.hide();
}
};
_initEvent() {
const { context, props } = this;
const { triggerOn = 'press', triggerOff = 'pressend', alwaysShow = false } = props;
context.gesture.on(triggerOn, (ev) => {
const { points } = ev;
this.show(points[0], ev);
});

context.gesture.on(triggerOff, (_ev) => {
if (!alwaysShow) {
this.hide();
}
});
}

show(point, _ev?) {
const { props } = this;
Expand Down Expand Up @@ -225,14 +199,48 @@ export default (View) => {

render() {
const { props, state } = this;
const { visible } = props;
const {
visible,
coord,
triggerOn = 'press',
triggerOff = 'pressend',
alwaysShow = false,
} = props;
if (visible === false) {
return null;
}
const { records } = state;
if (!records || !records.length) return null;

return <View {...props} records={records} />;
const { width, height, left, top } = coord;

return (
<group>
<rect
style={{
zIndex: 10,
x: left,
y: top,
width,
height,
fill: 'transparent',
}}
onPress={(ev) => {
if (triggerOn !== 'press') return;
const { points } = ev;
this.show(points[0], ev);
}}
onPressEnd={() => {
if (alwaysShow || triggerOff !== 'pressend') this.hide();
}}
onClick={(ev) => {
if (triggerOn !== 'click') return;
const { points } = ev;
this.show(points[0], ev);
}}
></rect>

{records && records.length && <View {...props} records={records} />}
</group>
);
}
};
};
Loading

0 comments on commit 00c082b

Please sign in to comment.