Skip to content

Commit

Permalink
feat: add event filter of scrollbar event
Browse files Browse the repository at this point in the history
  • Loading branch information
xile611 committed Feb 6, 2025
1 parent 3a09d67 commit 43197fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,11 @@ export abstract class DataFilterBaseComponent<T extends IDataFilterComponentSpec
return true;
};

protected _handleChartZoom = (params: { zoomDelta: number; zoomX?: number; zoomY?: number }) => {
if (!this._activeRoam) {
protected _handleChartZoom = (
params: { zoomDelta: number; zoomX?: number; zoomY?: number },
e?: BaseEventParams['event']
) => {
if (!this._activeRoam || (this._zoomAttr.filter && !this._zoomAttr.filter(params, e))) {
return;
}

Expand Down Expand Up @@ -846,7 +849,7 @@ export abstract class DataFilterBaseComponent<T extends IDataFilterComponentSpec
};

protected _handleChartScroll = (params: { scrollX: number; scrollY: number }, e: BaseEventParams['event']) => {
if (!this._activeRoam) {
if (!this._activeRoam || (this._scrollAttr.filter && !this._scrollAttr.filter(params, e))) {
return false;
}
const { scrollX, scrollY } = params;
Expand All @@ -869,7 +872,7 @@ export abstract class DataFilterBaseComponent<T extends IDataFilterComponentSpec
};

protected _handleChartDrag = (delta: [number, number], e: BaseEventParams['event']) => {
if (!this._activeRoam) {
if (!this._activeRoam || (this._dragAttr.filter && !this._dragAttr.filter(delta, e))) {
return;
}
const [dx, dy] = delta;
Expand Down
19 changes: 19 additions & 0 deletions packages/vchart/src/component/data-zoom/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { BaseEventParams } from '../../event/interface';
import type { IOrientType } from '../../typings';
import type { IDelayType } from '../../typings/event';
import type { IComponentSpec } from '../base/interface';
Expand Down Expand Up @@ -162,6 +163,12 @@ export interface IRoamDragSpec extends IRoamSpec {
* @default true
*/
reverse?: boolean;
/**
* 自定义的事件过滤器,返回true则触发datazoom/scrollbar的更新
* @since 1.13.5
* @returns
*/
filter?: (delta: [number, number], e?: BaseEventParams['event']) => boolean;
}

export interface IRoamScrollSpec extends IRoamSpec {
Expand All @@ -170,6 +177,12 @@ export interface IRoamScrollSpec extends IRoamSpec {
* @default true
*/
reverse?: boolean;
/**
* 自定义的事件过滤器,返回true则触发datazoom/scrollbar的更新
* @since 1.13.5
* @returns
*/
filter?: (params: { scrollX: number; scrollY: number }, e?: BaseEventParams['event']) => boolean;
}

export interface IRoamZoomSpec extends IRoamSpec {
Expand All @@ -180,6 +193,12 @@ export interface IRoamZoomSpec extends IRoamSpec {
* 关闭时, 以画布中心缩放
*/
focus?: boolean;
/**
* 自定义的事件过滤器,返回true则触发datazoom/scrollbar的更新
* @since 1.13.5
* @returns
*/
filter?: (params: { zoomDelta: number; zoomX?: number; zoomY?: number }, e?: BaseEventParams['event']) => boolean;
}

export interface IRoamSpec {
Expand Down

0 comments on commit 43197fa

Please sign in to comment.