Skip to content
Snippets Groups Projects
Commit 75bd3fd6 authored by Matthias Konitzny's avatar Matthias Konitzny :fire:
Browse files

Fixed multiple bugs caused by the group ids.

parent 82460d29
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,7 @@ export class Graph
public nodes: Node[];
public links: Link[];
public objectGroups: NodeType[];
private defaultGroup: NodeType;
public initialized: boolean;
public idToObjectGroup: Map<number, NodeType>;
......@@ -64,6 +65,7 @@ export class Graph
this.reset();
Object.assign(this, data);
this.initializeIdGeneration();
this.createDefaultObjectGroupIfNeeded();
this.objectGroups.forEach((group) =>
......@@ -77,7 +79,6 @@ export class Graph
});
this.updateNodeData();
this.initializeIdGeneration();
}
protected reset() {
......@@ -127,6 +128,7 @@ export class Graph
this.reset();
data.objectGroups.forEach((group) => this.createObjectGroup(group));
this.initializeIdGeneration(); // This is necessary to prevent the default group from overwriting an existing group
this.createDefaultObjectGroupIfNeeded();
data.nodes.forEach((node) => this.createNode(node));
......@@ -139,12 +141,17 @@ export class Graph
}
private createDefaultObjectGroupIfNeeded() {
if (this.objectGroups.length == 0) {
this.createObjectGroup({
id: 0,
const defaultGroup = this.objectGroups.find(
(group) => group.name == "Default"
);
if (defaultGroup == undefined) {
this.defaultGroup = this.createObjectGroup({
id: ++this.nextObjectGroupId,
name: "Default",
color: "#000000",
});
} else {
this.defaultGroup = defaultGroup;
}
}
......@@ -188,7 +195,8 @@ export class Graph
public createNode(data?: NodeData | SimNodeData): Node {
const node = new Node();
node.fromSerializedObject(data);
node.type = this.idToObjectGroup.get(data.type);
const group = this.idToObjectGroup.get(data.type);
node.type = group != undefined ? group : this.defaultGroup;
node.neighbors = [];
node.links = [];
this.addNode(node);
......
......@@ -102,7 +102,7 @@ export class Node
banner: this.banner,
video: this.video,
references: this.references,
type: this.type.id,
type: this.type ? this.type.id : undefined,
};
}
......
......@@ -31,7 +31,7 @@ export class NodeTypeEntry extends React.Component<propTypes, stateTypes> {
}
private deleteType() {
this.props.type.delete();
//this.props.type.delete();
}
private isValidColor(color: string): boolean {
......
......@@ -31,12 +31,13 @@ export class DynamicGraph extends Common.Graph {
return this;
}
public createObjectGroup(data: NodeTypeData): NodeType {
if (data.name == undefined) {
data.name = "Unnamed";
}
if (data.color == undefined) {
data.color = "#000000";
public createObjectGroup(data?: NodeTypeData): NodeType {
if (data == undefined) {
data = {
id: 0,
name: "Unnamed",
color: "#000000",
};
}
return super.createObjectGroup(data);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment