mirror of
https://github.com/projectstorm/react-diagrams.git
synced 2025-08-16 09:40:44 +08:00
fixed more stuff
This commit is contained in:
@ -155,19 +155,31 @@ export class DiagramEngine extends BaseObserver<DiagramEngineListener> {
|
||||
return this.portFactories;
|
||||
}
|
||||
|
||||
getFactoryForNode(node: NodeModel) {
|
||||
getFactoryForNode(node: NodeModel | string) {
|
||||
if (typeof node === 'string') {
|
||||
return this.nodeFactories.getFactory(node);
|
||||
}
|
||||
return this.nodeFactories.getFactory(node.getType());
|
||||
}
|
||||
|
||||
getFactoryForLink(link: LinkModel) {
|
||||
getFactoryForLink(link: LinkModel | string) {
|
||||
if (typeof link === 'string') {
|
||||
return this.linkFactories.getFactory(link);
|
||||
}
|
||||
return this.linkFactories.getFactory(link.getType());
|
||||
}
|
||||
|
||||
getFactoryForLabel(label: LabelModel) {
|
||||
if (typeof label === 'string') {
|
||||
return this.labelFactories.getFactory(label);
|
||||
}
|
||||
return this.labelFactories.getFactory(label.getType());
|
||||
}
|
||||
|
||||
getFactoryForPort(port: PortModel) {
|
||||
if (typeof port === 'string') {
|
||||
return this.portFactories.getFactory(port);
|
||||
}
|
||||
return this.portFactories.getFactory(port.getType());
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,10 @@ export class BaseEntity<T extends BaseEntityGenerics = BaseEntityGenerics> exten
|
||||
return lookupTable[this.options.id];
|
||||
}
|
||||
let clone = _.clone(this);
|
||||
clone.options.id = Toolkit.UID();
|
||||
clone.options = {
|
||||
...this.options,
|
||||
id: Toolkit.UID()
|
||||
};
|
||||
clone.clearListeners();
|
||||
lookupTable[this.options.id] = clone;
|
||||
|
||||
|
@ -44,6 +44,8 @@ export class BaseModel<G extends BaseModelGenerics = BaseModelGenerics> extends
|
||||
serialize() {
|
||||
return {
|
||||
...super.serialize(),
|
||||
type: this.options.type,
|
||||
selected: this.options.selected,
|
||||
extras: this.options.extras
|
||||
};
|
||||
}
|
||||
@ -51,6 +53,7 @@ export class BaseModel<G extends BaseModelGenerics = BaseModelGenerics> extends
|
||||
deSerialize(data: { [p: string]: any }, engine: DiagramEngine) {
|
||||
super.deSerialize(data, engine);
|
||||
this.options.extras = data.extras;
|
||||
this.options.selected = data.selected;
|
||||
}
|
||||
|
||||
getType(): string {
|
||||
|
@ -97,7 +97,8 @@ export class DiagramModel<G extends DiagramModelGenerics = DiagramModelGenerics>
|
||||
}
|
||||
|
||||
serializeDiagram() {
|
||||
return _.merge(this.serialize(), {
|
||||
return {
|
||||
...this.serialize(),
|
||||
offsetX: this.options.offsetX,
|
||||
offsetY: this.options.offsetY,
|
||||
zoom: this.options.zoom,
|
||||
@ -108,7 +109,7 @@ export class DiagramModel<G extends DiagramModelGenerics = DiagramModelGenerics>
|
||||
nodes: _.map(this.nodes, node => {
|
||||
return node.serialize();
|
||||
})
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
clearSelection(ignore: BaseModel | null = null) {
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { BaseModel, BaseModelGenerics } from '../core-models/BaseModel';
|
||||
import * as _ from 'lodash';
|
||||
import { DiagramEngine } from '../DiagramEngine';
|
||||
|
||||
export class LabelModel<G extends BaseModelGenerics = BaseModelGenerics> extends BaseModel<G> {
|
||||
@ -19,9 +18,10 @@ export class LabelModel<G extends BaseModelGenerics = BaseModelGenerics> extends
|
||||
}
|
||||
|
||||
serialize() {
|
||||
return _.merge(super.serialize(), {
|
||||
return {
|
||||
...super.serialize(),
|
||||
offsetX: this.offsetX,
|
||||
offsetY: this.offsetY
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,8 @@ export class LinkModel<G extends LinkModelGenerics = LinkModelGenerics> extends
|
||||
}
|
||||
|
||||
serialize() {
|
||||
return _.merge(super.serialize(), {
|
||||
return {
|
||||
...super.serialize(),
|
||||
source: this.sourcePort ? this.sourcePort.getParent().getID() : null,
|
||||
sourcePort: this.sourcePort ? this.sourcePort.getID() : null,
|
||||
target: this.targetPort ? this.targetPort.getParent().getID() : null,
|
||||
@ -89,7 +90,7 @@ export class LinkModel<G extends LinkModelGenerics = LinkModelGenerics> extends
|
||||
labels: _.map(this.labels, label => {
|
||||
return label.serialize();
|
||||
})
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
doClone(lookupTable = {}, clone) {
|
||||
|
@ -44,7 +44,7 @@ export class PortModel<G extends PortModelGenerics = PortModelGenerics> extends
|
||||
...super.serialize(),
|
||||
parentNode: this.parent.getID(),
|
||||
links: _.map(this.links, link => {
|
||||
return link.getID;
|
||||
return link.getID();
|
||||
})
|
||||
};
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ export interface DefaultNodeModelGenerics {
|
||||
|
||||
export class DefaultNodeModel extends NodeModel<DefaultNodeModelGenerics & NodeModelGenerics> {
|
||||
constructor(name: string, color: string);
|
||||
constructor(options: DefaultNodeModelOptions);
|
||||
constructor(options?: DefaultNodeModelOptions);
|
||||
constructor(options: any = {}, color?: string) {
|
||||
if (typeof options === 'string') {
|
||||
options = {
|
||||
|
@ -33,6 +33,7 @@ export default () => {
|
||||
//!------------- SERIALIZING ------------------
|
||||
|
||||
var str = JSON.stringify(model.serializeDiagram());
|
||||
console.log(model.serializeDiagram());
|
||||
|
||||
//!------------- DESERIALIZING ----------------
|
||||
|
||||
|
Reference in New Issue
Block a user