Skip to content

Commit b5921c9

Browse files
skie1997xuefei1313
authored andcommitted
feat: interactive params add event. feat #4421
1 parent ca6d639 commit b5921c9

File tree

5 files changed

+36
-25
lines changed

5 files changed

+36
-25
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@visactor/vchart",
5+
"comment": "feat: interactive params add event. feat #4421",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@visactor/vchart"
10+
}

packages/vchart/src/interaction/interface/trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface ITrigger<TriggerOptions extends IBaseTriggerOptions = any> {
1313
release: () => void;
1414

1515
init: () => void;
16-
start: (g: any) => void;
16+
start: (g: any, e?: BaseEventParams) => void;
1717
reset: (g?: IMarkGraphic) => void;
1818
getStartState: () => string;
1919
getResetState: () => string;

packages/vchart/src/interaction/triggers/base.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { IBaseTriggerOptions, ITrigger, ITriggerEventHandler } from '../int
33
import type { IMark, IMarkGraphic } from '../../mark/interface/common';
44
import { MarkSet } from '../../mark/mark-set';
55
import { groupMarksByState } from './util';
6+
import type { BaseEventParams } from '../../core';
67

78
export abstract class BaseTrigger<T extends IBaseTriggerOptions> implements ITrigger<T> {
89
options: T;
@@ -111,11 +112,11 @@ export abstract class BaseTrigger<T extends IBaseTriggerOptions> implements ITri
111112
}
112113
}
113114

114-
start(g: IMarkGraphic | string) {
115+
start(g: IMarkGraphic | string, e?: BaseEventParams) {
115116
// do nothing
116117
}
117118

118-
reset(g?: IMarkGraphic) {
119+
reset(g?: IMarkGraphic, e?: BaseEventParams) {
119120
// do nothing
120121
}
121122

packages/vchart/src/interaction/triggers/element-highlight.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ export class ElementHighlight
6565
return events;
6666
}
6767

68-
resetAll = () => {
68+
resetAll = (e?: BaseEventParams) => {
6969
const { highlightState, blurState, interaction } = this.options;
7070

7171
if (this._lastGraphic) {
7272
interaction.clearAllStatesOfTrigger(this, highlightState, blurState);
7373

74-
this.dispatchEvent('reset', { graphics: [this._lastGraphic], options: this.options });
74+
this.dispatchEvent('reset', { graphics: [this._lastGraphic], options: this.options, ...e });
7575

7676
this._lastGraphic = null;
7777

@@ -80,7 +80,7 @@ export class ElementHighlight
8080
};
8181

8282
handleStart = (e: BaseEventParams) => {
83-
this.start(e.item);
83+
this.start(e.item, e);
8484
};
8585

8686
handleReset = (e: BaseEventParams) => {
@@ -94,13 +94,13 @@ export class ElementHighlight
9494
const hasActiveElement = markGraphic && this._markSet.getMarkInId(markGraphic.context.markId);
9595

9696
if (this._resetType.includes('view') && !hasActiveElement) {
97-
this.resetAll();
97+
this.resetAll(e);
9898
} else if (this._resetType.includes('self') && hasActiveElement) {
99-
this.resetAll();
99+
this.resetAll(e);
100100
}
101101
};
102102

103-
start(markGraphic: IMarkGraphic) {
103+
start(markGraphic: IMarkGraphic, e?: BaseEventParams) {
104104
if (markGraphic && this._markSet.getMarkInId(markGraphic.context.markId)) {
105105
const { highlightState, blurState, interaction } = this.options;
106106

@@ -119,19 +119,19 @@ export class ElementHighlight
119119

120120
this._lastGraphic = markGraphic;
121121

122-
this.dispatchEvent('start', { graphics: newStatedGraphics, options: this.options });
122+
this.dispatchEvent('start', { graphics: newStatedGraphics, options: this.options, ...e });
123123
} else if (this._lastGraphic && this._resetType === 'view') {
124-
this.resetAll();
124+
this.resetAll(e);
125125
}
126126
}
127127

128-
reset(markGraphic: IMarkGraphic) {
128+
reset(markGraphic: IMarkGraphic, e?: BaseEventParams) {
129129
if (markGraphic) {
130130
if (this._markSet.getMarkInId(markGraphic.context.markId)) {
131131
markGraphic.removeState([this.options.highlightState, this.options.blurState]);
132132
}
133133
} else {
134-
this.resetAll();
134+
this.resetAll(e);
135135
}
136136
}
137137
}

packages/vchart/src/interaction/triggers/element-select.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ export class ElementSelect extends BaseTrigger<IElementSelectOptions> implements
6161
return events;
6262
}
6363

64-
resetAll = () => {
64+
resetAll = (e?: BaseEventParams) => {
6565
const { state, reverseState, interaction } = this.options;
6666

6767
const statedGraphics = interaction.getStatedGraphics(this);
6868

6969
if (statedGraphics && statedGraphics.length) {
7070
interaction.clearAllStatesOfTrigger(this, state, reverseState);
71-
this.dispatchEvent('reset', { graphics: statedGraphics, options: this.options });
71+
this.dispatchEvent('reset', { graphics: statedGraphics, options: this.options, ...e });
7272

7373
interaction.setStatedGraphics(this, []);
7474
}
7575
};
7676

7777
handleStart = (e: BaseEventParams) => {
78-
this.start(e.item);
78+
this.start(e.item, e);
7979
};
8080

8181
handleReset = (e: BaseEventParams) => {
@@ -89,13 +89,13 @@ export class ElementSelect extends BaseTrigger<IElementSelectOptions> implements
8989
const hasActiveElement = markGraphic && this._markSet.getMarkInId(markGraphic.context.markId);
9090

9191
if (this._resetType.includes('view') && !hasActiveElement) {
92-
this.resetAll();
92+
this.resetAll(e);
9393
} else if (this._resetType.includes('self') && hasActiveElement) {
94-
this.resetAll();
94+
this.resetAll(e);
9595
}
9696
};
9797

98-
start(markGraphic: IMarkGraphic) {
98+
start(markGraphic: IMarkGraphic, e?: BaseEventParams) {
9999
const { state, reverseState, isMultiple, interaction } = this.options;
100100
const statedGraphics = interaction.getStatedGraphics(this);
101101

@@ -110,7 +110,7 @@ export class ElementSelect extends BaseTrigger<IElementSelectOptions> implements
110110
interaction.updateStates(this, newStatedGraphics, statedGraphics, state, reverseState)
111111
);
112112
} else {
113-
this.resetAll();
113+
this.resetAll(e);
114114
}
115115
}
116116
} else {
@@ -127,26 +127,26 @@ export class ElementSelect extends BaseTrigger<IElementSelectOptions> implements
127127
reverseState
128128
);
129129
interaction.setStatedGraphics(this, newStatedGraphics);
130-
this.dispatchEvent('start', { graphics: newStatedGraphics, options: this.options });
130+
this.dispatchEvent('start', { graphics: newStatedGraphics, options: this.options, ...e });
131131

132132
if (this._resetType.includes('timeout')) {
133133
this._timer = setTimeout(() => {
134-
this.resetAll();
134+
this.resetAll(e);
135135
}, this.options.triggerOff as number) as unknown as number;
136136
}
137137
}
138138
} else if (this._resetType.includes('view') && statedGraphics && statedGraphics.length) {
139-
this.resetAll();
139+
this.resetAll(e);
140140
}
141141
}
142142

143-
reset(markGraphic: IMarkGraphic) {
143+
reset(markGraphic: IMarkGraphic, e?: BaseEventParams) {
144144
if (markGraphic) {
145145
if (this._markSet.getMarkInId(markGraphic.context.markId)) {
146146
markGraphic.removeState([this.options.state, this.options.reverseState]);
147147
}
148148
} else {
149-
this.resetAll();
149+
this.resetAll(e);
150150
}
151151
}
152152
}

0 commit comments

Comments
 (0)