feat:新增当泄漏区出现节点时的事件

This commit is contained in:
黎智洲
2021-05-29 11:32:35 +08:00
parent 66a084ba12
commit 32f403b5aa
8 changed files with 117 additions and 29 deletions
+39 -14
View File
@@ -2,6 +2,13 @@ import { Model } from "../Model/modelData";
import { SV } from "../StructV";
export type animationConfig = {
duration: number;
timingFunction: string;
payload?: any;
callback?: Function;
}
/**
* 动画表
@@ -11,19 +18,17 @@ export const Animations = {
/**
* 添加节点 / 边时的动画效果
* @param model
* @param duration
* @param timingFunction
* @param callback
* @param animationConfig
*/
animate_append(model: Model, duration: number, timingFunction: string, callback: Function = null) {
animate_append(model: Model, animationConfig: animationConfig) {
const G6Item = model.G6Item,
type = G6Item.getType(),
group = G6Item.getContainer(),
Mat3 = SV.Mat3,
animateCfg = {
duration: duration,
easing: timingFunction,
callback
duration: animationConfig.duration,
easing: animationConfig.timingFunction,
callback: animationConfig.callback
};
if(type === 'node') {
@@ -49,19 +54,17 @@ export const Animations = {
/**
* 移除节点 / 边时的动画效果
* @param model
* @param duration
* @param timingFunction
* @param callback
* @param animationConfig
*/
animate_remove(model: Model, duration: number, timingFunction: string, callback: Function = null) {
animate_remove(model: Model, animationConfig: animationConfig) {
const G6Item = model.G6Item,
type = G6Item.getType(),
group = G6Item.getContainer(),
Mat3 = SV.Mat3,
animateCfg = {
duration: duration,
easing: timingFunction,
callback
duration: animationConfig.duration,
easing: animationConfig.timingFunction,
callback: animationConfig.callback
};
if(type === 'node') {
@@ -77,6 +80,28 @@ export const Animations = {
line.animate({ lineDash: [0, length], opacity: 0 }, animateCfg);
}
},
/**
* 移动节点 / 边的动画
* @param model
* @param animationConfig
*/
animate_moveTo(model: Model, animationConfig: animationConfig) {
const G6Item = model.G6Item,
group = G6Item.getContainer(),
Mat3 = SV.Mat3,
target = animationConfig.payload,
animateCfg = {
duration: animationConfig.duration,
easing: animationConfig.timingFunction,
callback: animationConfig.callback
};
let matrix = Mat3.clone(group.getMatrix());
Mat3.translate(matrix, matrix, [target.x, target.y]);
group.animate({ opacity: 0, matrix }, animateCfg);
}
};
+21 -13
View File
@@ -112,11 +112,15 @@ export class Container {
let counter = 0;
appendModels.forEach(item => {
Animations.animate_append(item, this.animationsOptions.duration, this.animationsOptions.timingFunction, () => {
counter++;
if(counter === appendModels.length) {
this.afterAppendModelsCallbacks.map(item => item(appendModels));
Animations.animate_append(item, {
duration: this.animationsOptions.duration,
timingFunction: this.animationsOptions.timingFunction,
callback: () => {
counter++;
if(counter === appendModels.length) {
this.afterAppendModelsCallbacks.map(item => item(appendModels));
}
}
});
});
@@ -130,14 +134,18 @@ export class Container {
let counter = 0;
removeModels.forEach(item => {
Animations.animate_remove(item, this.animationsOptions.duration, this.animationsOptions.timingFunction, () => {
this.renderer.removeModel(item);
item.renderG6Item = item.G6Item = null;
counter++;
if(counter === removeModels.length) {
this.afterRemoveModelsCallbacks.map(item => item(removeModels));
Animations.animate_remove(item, {
duration: this.animationsOptions.duration,
timingFunction: this.animationsOptions.timingFunction,
callback: () => {
this.renderer.removeModel(item);
item.renderG6Item = item.G6Item = null;
counter++;
if(counter === removeModels.length) {
this.afterRemoveModelsCallbacks.map(item => item(removeModels));
}
}
});
});
+3 -1
View File
@@ -3,4 +3,6 @@ import { Container } from "./container";
/**
* 泄漏区可视化视图
*/
export class LeakContainer extends Container { };
export class LeakContainer extends Container {
};
+2
View File
@@ -152,6 +152,8 @@ import { Container } from "./container";
});
}
protected
protected handleChangeModels(models: Model[]) {
const changeHighlightColor: string = this.interactionOptions.changeHighlight;
+3
View File
@@ -9,6 +9,7 @@ import { LeakContainer } from "./container/leak";
import { Layouter } from "./layouter";
import { LayoutGroup, LayoutGroupTable } from "../Model/modelConstructor";
import { Util } from "../Common/util";
import { EventBus } from "../Common/eventBus";
export class ViewManager {
@@ -226,6 +227,7 @@ export class ViewManager {
}
if(this.freedContainer) {
EventBus.emit('onFreed', freedList);
this.freedContainer.render(freedList);
}
@@ -237,6 +239,7 @@ export class ViewManager {
if(this.leakContainer && this.prevLayoutGroupTable) {
this.mainContainer.afterRemoveModels(() => {
EventBus.emit('onLeak', leakLayoutGroupTable);
this.leakContainer.render(Util.convertGroupTable2ModelList(leakLayoutGroupTable));
});
}