fix: bug修复

This commit is contained in:
黎智洲 2021-12-03 16:08:37 +08:00
parent 34679ff328
commit aa9381c9c2
8 changed files with 26 additions and 33 deletions

2
dist/sv.js vendored

File diff suppressed because one or more lines are too long

View File

@ -11,15 +11,21 @@ import { ViewContainer } from "../View/viewContainer";
*/
export function InitDragCanvasWithLeak(viewContainer: ViewContainer) {
let g6Instance = viewContainer.getG6Instance(),
isDragStart = false,
startPositionY = 0,
currentLeakAreaY = 0;
g6Instance.on('canvas:dragstart', event => {
isDragStart = true;
startPositionY = event.canvasY;
currentLeakAreaY = viewContainer.leakAreaY;
});
g6Instance.on('canvas:drag', event => {
if(!isDragStart) {
return false;
}
let zoom = g6Instance.getZoom(),
dy = (event.canvasY - startPositionY) / zoom,
leakAreaY = currentLeakAreaY + dy;
@ -34,6 +40,7 @@ export function InitDragCanvasWithLeak(viewContainer: ViewContainer) {
});
g6Instance.on('canvas:dragend', event => {
isDragStart = false;
startPositionY = 0;
})
}

View File

@ -1,10 +1,10 @@
import { Util } from '@antv/g6';
import { Util, Item } from '@antv/g6';
export type animationConfig = {
duration: number;
timingFunction: string;
callback?: Function;
callback?: () => void;
[key: string]: any;
}
@ -19,7 +19,7 @@ export const Animations = {
* @param G6Item
* @param animationConfig
*/
APPEND(G6Item: any, animationConfig: animationConfig) {
APPEND(G6Item: Item, animationConfig: animationConfig) {
const type = G6Item.getType(),
group = G6Item.getContainer(),
Mat3 = Util.mat3,
@ -54,7 +54,7 @@ export const Animations = {
* @param G6Item
* @param animationConfig
*/
REMOVE(G6Item: any, animationConfig: animationConfig) {
REMOVE(G6Item: Item, animationConfig: animationConfig) {
const type = G6Item.getType(),
group = G6Item.getContainer(),
Mat3 = Util.mat3,
@ -84,7 +84,7 @@ export const Animations = {
* @param G6Item
* @param animationConfig
*/
FADE_IN(G6Item: any, animationConfig: animationConfig) {
FADE_IN(G6Item: Item, animationConfig: animationConfig) {
const group = G6Item.getContainer(),
animateCfg = {
duration: animationConfig.duration,

View File

@ -186,8 +186,8 @@ export class LayoutProvider {
// 左往右布局
for (let i = 0; i < modelGroupList.length; i++) {
group = modelGroupList[i],
bound = group.getPaddingBound(this.viewOptions.groupPadding);
group = modelGroupList[i];
bound = group.getPaddingBound(this.viewOptions.groupPadding);
if (prevBound) {
dx = prevBound.x + prevBound.width - bound.x;
@ -231,7 +231,7 @@ export class LayoutProvider {
height = this.viewContainer.getG6Instance().getHeight(),
leakAreaHeightRatio = this.engine.viewOptions.leakAreaHeight;
if(this.viewContainer.hasLeak) {
if (this.viewContainer.hasLeak) {
height = height * (1 - leakAreaHeightRatio);
}

View File

@ -6,7 +6,7 @@ import { SVModel } from "../Model/SVModel";
import { Renderer } from "./renderer";
import { Reconcile } from "./reconcile";
import { FixNodeMarkerDrag } from "../BehaviorHelper/fixNodeMarkerDrag";
import { InitDragCanvasWithLeak } from "../BehaviorHelper/dragCanavsWithLeak";
import { InitDragCanvasWithLeak } from "../BehaviorHelper/dragCanvasWithLeak";
import { EventBus } from "../Common/eventBus";
import { Group } from "../Common/group";
@ -144,6 +144,10 @@ export class ViewContainer {
this.prevLayoutGroupTable = layoutGroupTable;
this.prevModelList = modelList;
// modelList.forEach(item => {
// console.log(item.getModelType(), item.getBound());
// });
}
/**

View File

@ -10,7 +10,7 @@ import { SVMarker } from "./Model/SVMarker";
export class Engine {
private modelConstructor: ModelConstructor = null;
private modelConstructor: ModelConstructor;
private viewContainer: ViewContainer
private prevStringSourceData: string;
@ -50,12 +50,6 @@ export class Engine {
Object.keys(SV.registeredLayout).forEach(layout => {
if(this.optionsTable[layout] === undefined) {
const options: LayoutGroupOptions = SV.registeredLayout[layout].defineOptions();
options.behavior = Object.assign({
dragNode: true,
selectNode: true
}, options.behavior);
this.optionsTable[layout] = options;
}
});
@ -73,10 +67,6 @@ export class Engine {
return;
}
if(this.viewContainer.getG6Instance().isAnimating()) {
return;
}
let stringSourceData = JSON.stringify(sourceData);
if(this.prevStringSourceData === stringSourceData) {
return;
@ -202,12 +192,12 @@ export class Engine {
* 使id查找某个节点
* @param id
*/
public findElement(id: string) {
const elements = this.getNodes();
public findNode(id: string): SVNode {
const nodes = this.getNodes();
const stringId = id.toString();
const targetElement = elements.find(item => item.sourceId === stringId);
const targetNode = nodes.find(item => item.sourceId === stringId);
return targetElement;
return targetNode;
}
/**

View File

@ -71,24 +71,16 @@ export interface MarkerOption extends NodeOption {
};
export interface LayoutOptions {
[key: string]: any;
};
export interface BehaviorOptions {
dragNode: boolean | string[];
selectNode: boolean | string[];
};
export interface LayoutGroupOptions {
node: { [key: string]: NodeOption };
link?: { [key: string]: LinkOption }
marker?: { [key: string]: MarkerOption }
layout?: LayoutOptions;
behavior?: BehaviorOptions;
};