fix:修复一些bug
This commit is contained in:
parent
ad9333bd3b
commit
66a084ba12
2
dist/sv.js
vendored
2
dist/sv.js
vendored
File diff suppressed because one or more lines are too long
@ -57,10 +57,9 @@ export class ModelConstructor {
|
||||
}
|
||||
|
||||
const options: LayoutGroupOptions = optionsTable[layouterName],
|
||||
sourceData = layouter.sourcesPreprocess(sourceGroup.data),
|
||||
elementOptions = options.element || { },
|
||||
pointerOptions = options.pointer || { };
|
||||
|
||||
const sourceData = layouter.sourcesPreprocess? layouter.sourcesPreprocess(sourceGroup.data): sourceGroup.data;
|
||||
|
||||
elementList = this.constructElements(elementOptions, name, sourceData, layouterName);
|
||||
pointerList = this.constructPointers(pointerOptions, elementList);
|
||||
|
||||
@ -9,6 +9,9 @@ import twoCellNode from "./RegisteredShape/twoCellNode";
|
||||
import { Vector } from "./Common/vector";
|
||||
import indexedNode from "./RegisteredShape/indexedNode";
|
||||
import { EngineOptions, Layouter } from "./options";
|
||||
import { LayoutGroup } from "./Model/modelConstructor";
|
||||
import { SourceElement } from "./sources";
|
||||
import { Element } from "./Model/modelData";
|
||||
|
||||
|
||||
export interface StructV {
|
||||
@ -54,7 +57,24 @@ SV.registeredShape = [
|
||||
];
|
||||
|
||||
SV.registerShape = G6.registerNode;
|
||||
SV.registerLayouter = function(name: string, layouter) {
|
||||
SV.registerLayouter = function(name: string, layouter: Layouter) {
|
||||
|
||||
if(typeof layouter.sourcesPreprocess !== 'function') {
|
||||
layouter.sourcesPreprocess = function(data: SourceElement[]): SourceElement[] {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
if(typeof layouter.defineLeakRule !== 'function') {
|
||||
layouter.defineLeakRule = function(elements: Element[]): Element[] {
|
||||
return elements;
|
||||
}
|
||||
}
|
||||
|
||||
if(typeof layouter.defineOptions !== 'function' || typeof layouter.layout !== 'function') {
|
||||
return;
|
||||
}
|
||||
|
||||
SV.registeredLayouter[name] = layouter;
|
||||
};
|
||||
|
||||
|
||||
@ -26,32 +26,38 @@ export class Container {
|
||||
this.interactionOptions = engine.interactionOptions;
|
||||
this.prevModelList = [];
|
||||
|
||||
const tooltip = new SV.G6.Tooltip({
|
||||
offsetX: 10,
|
||||
offsetY: 20,
|
||||
shouldBegin(event) {
|
||||
return event.item.getModel().SVModelType === 'element';
|
||||
},
|
||||
getContent(event) {
|
||||
const data = event.item.SVModel.data,
|
||||
wrapper = document.createElement('div');
|
||||
const g6Plugins = [];
|
||||
|
||||
wrapper.style.padding = '0 4px 0 4px';
|
||||
wrapper.innerHTML = `
|
||||
<h5>id: ${ event.item.SVModel.sourceId }</h5>
|
||||
<h5>data: ${ data? data: '' }</h5>
|
||||
`
|
||||
return wrapper;
|
||||
},
|
||||
itemTypes: ['node']
|
||||
});
|
||||
if(g6Options.tooltip) {
|
||||
const tooltip = new SV.G6.Tooltip({
|
||||
offsetX: 10,
|
||||
offsetY: 20,
|
||||
shouldBegin(event) {
|
||||
return event.item.getModel().SVModelType === 'element';
|
||||
},
|
||||
getContent(event) {
|
||||
const data = event.item.SVModel.data,
|
||||
wrapper = document.createElement('div');
|
||||
|
||||
wrapper.style.padding = '0 4px 0 4px';
|
||||
wrapper.innerHTML = `
|
||||
<h5>id: ${ event.item.SVModel.sourceId }</h5>
|
||||
<h5>data: ${ data? data: '' }</h5>
|
||||
`
|
||||
return wrapper;
|
||||
},
|
||||
itemTypes: ['node']
|
||||
});
|
||||
|
||||
g6Plugins.push(tooltip);
|
||||
}
|
||||
|
||||
this.renderer = new Renderer(engine, DOMContainer, {
|
||||
...g6Options,
|
||||
fitCenter: g6Options.fitCenter,
|
||||
modes: {
|
||||
default: this.initBehaviors(this.engine.optionsTable)
|
||||
},
|
||||
plugins: [tooltip]
|
||||
plugins: g6Plugins
|
||||
});
|
||||
|
||||
this.afterInitRenderer();
|
||||
|
||||
@ -25,17 +25,17 @@ export class ViewManager {
|
||||
constructor(engine: Engine, DOMContainer: HTMLElement) {
|
||||
this.engine = engine;
|
||||
this.layouter = new Layouter(engine);
|
||||
this.mainContainer = new MainContainer(engine, DOMContainer);
|
||||
this.mainContainer = new MainContainer(engine, DOMContainer, { tooltip: true });
|
||||
this.prevLayoutGroupTable = null;
|
||||
|
||||
const options: EngineOptions = this.engine.engineOptions;
|
||||
|
||||
if(options.freedContainer) {
|
||||
this.freedContainer = new FreedContainer(engine, options.freedContainer, { fitCenter: true });
|
||||
this.freedContainer = new FreedContainer(engine, options.freedContainer, { fitCenter: true, tooltip: false });
|
||||
}
|
||||
|
||||
if(options.leakContainer) {
|
||||
this.leakContainer = new LeakContainer(engine, options.leakContainer, { fitCenter: true });
|
||||
this.leakContainer = new LeakContainer(engine, options.leakContainer, { fitCenter: true, tooltip: false });
|
||||
}
|
||||
|
||||
this.shadowG6Instance = new SV.G6.Graph({
|
||||
@ -119,11 +119,16 @@ export class ViewManager {
|
||||
|
||||
if(curGroup) {
|
||||
elements = prevGroup.element.filter(item => !curGroup.element.find(n => n.id === item.id)).filter(item => item.freed === false),
|
||||
links = prevGroup.link.filter(item => !curGroup.link.find(n => n.id === item.id)),
|
||||
elementIds = elements.map(item => item.id);
|
||||
links = prevGroup.link.filter(item => !curGroup.link.find(n => n.id === item.id));
|
||||
elements = curGroup.layouter.defineLeakRule(elements);
|
||||
}
|
||||
else {
|
||||
elements = prevGroup.element;
|
||||
links = prevGroup.link;
|
||||
}
|
||||
|
||||
elements.forEach(item => {
|
||||
elementIds.push(item.id);
|
||||
item.set('style', {
|
||||
fill: '#ccc'
|
||||
});
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { LayoutGroup } from "./Model/modelConstructor";
|
||||
import { Element } from "./Model/modelData";
|
||||
import { SourceElement } from "./sources";
|
||||
|
||||
@ -118,7 +119,8 @@ export interface EngineOptions {
|
||||
export interface Layouter {
|
||||
defineOptions(): LayoutGroupOptions;
|
||||
sourcesPreprocess?(sources: SourceElement[]): SourceElement[];
|
||||
defineLeakRule?(elements: Element[]): Element[];
|
||||
layout(elements: Element[], layoutOptions: LayoutOptions);
|
||||
[key: string]: Function;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user