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