Skip to content

Commit

Permalink
feat(interaction): avoid event error
Browse files Browse the repository at this point in the history
  • Loading branch information
dxq613 authored and simaQ committed Apr 1, 2020
1 parent 6356363 commit 3ae581b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,21 +409,20 @@ registerInteraction('brush-visible', {
start: [
{
trigger: 'plot:mousedown',
action: ['rect-mask:start', 'rect-mask:show', 'element-range-highlight:start'],
action: ['rect-mask:start', 'rect-mask:show'],
},
],
processing: [
{
trigger: 'plot:mousemove',
action: ['rect-mask:resize','element-range-highlight:highlight'],
action: ['rect-mask:resize'],
},
{trigger: 'mask:end',action: ['element-filter:filter']}
{trigger: 'mask:change',action: ['element-range-highlight:highlight']}
],
end: [
{
trigger: 'mouseup',
isEnable: isPointInView,
action: ['rect-mask:end', 'rect-mask:hide', 'element-range-highlight:end', 'element-range-highlight:clear'],
trigger: 'plot:mouseup',
action: ['rect-mask:end', 'rect-mask:hide','element-filter:filter', 'element-range-highlight:clear'],
},
],
rollback: [
Expand Down
4 changes: 4 additions & 0 deletions src/interaction/action/element/range-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class ElementRangeState extends StateBase {
} else {
const startPoint = this.startPoint;
const endPoint = this.isStarted ? this.getCurrentPoint() : this.endPoint;
// 如果没有开始,则不允许范围设置状态,保护性质
if (!startPoint || !endPoint) {
return;
}
// 计算框选区域
const box = {
minX: Math.min(startPoint.x, endPoint.x),
Expand Down
5 changes: 4 additions & 1 deletion src/interaction/grammar-interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,21 @@ export default class GrammarInteraction extends Interaction {
if (!callbackCaches[key]) {
// 动态生成执行的方法,执行对应 action 的名称
const actionCallback = (event) => {
context.event = event;
context.event = event; // 保证检测时的 event
if (this.isAllowExcute(stepName, step)) {
// 如果是数组时,则依次执行
if (isArray(actionObject)) {
each(actionObject, (obj: ActionObject) => {
context.event = event; // 可能触发新的事件,保证执行前的 context.event 是正确的
executeAction(obj);
});
} else {
context.event = event; // 保证执行前的 context.event 是正确的
executeAction(actionObject);
}
this.afterExecute(stepName, step);
if (step.callback) {
context.event = event; // 保证执行前的 context.event 是正确的
step.callback(context);
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/interaction/action/highlight-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ describe('test highlight action', () => {
x: bbox1.x - 5,
y: bbox1.y - 5,
};
expect(() => {
action.highlight(); // pre test
}).not.toThrow();
action.start();
context.event = {
x: bbox1.maxX + 5,
Expand Down

0 comments on commit 3ae581b

Please sign in to comment.