Skip to content

Commit

Permalink
Update view.js (#1122)
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder committed Aug 30, 2023
1 parent 43b10b1 commit 1afb385
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 8 additions & 3 deletions source/grapher.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,17 @@ grapher.Node = class {
}

select() {
this.element.classList.add('select');
return [ this.element ];
if (this.element) {
this.element.classList.add('select');
return [ this.element ];
}
return [];
}

deselect() {
this.element.classList.remove('select');
if (this.element) {
this.element.classList.remove('select');
}
}

static roundedRect(x, y, width, height, r1, r2, r3, r4) {
Expand Down
8 changes: 5 additions & 3 deletions source/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -1594,23 +1594,20 @@ view.Graph = class extends grapher.Graph {
createNode(node) {
const value = new view.Node(this, node);
value.name = (this._nodeKey++).toString();
this.setNode(value);
this._table.set(node, value);
return value;
}

createInput(input) {
const value = new view.Input(this, input);
value.name = (this._nodeKey++).toString();
this.setNode(value);
this._table.set(input, value);
return value;
}

createOutput(output) {
const value = new view.Output(this, output);
value.name = (this._nodeKey++).toString();
this.setNode(value);
this._table.set(output, value);
return value;
}
Expand Down Expand Up @@ -1647,12 +1644,14 @@ view.Graph = class extends grapher.Graph {
}
for (const input of graph.inputs) {
const viewInput = this.createInput(input);
this.setNode(viewInput);
for (const value of input.value) {
this.createValue(value).from = viewInput;
}
}
for (const node of graph.nodes) {
const viewNode = this.createNode(node);
this.setNode(viewNode);
const inputs = node.inputs;
for (const input of inputs) {
for (const value of input.value) {
Expand Down Expand Up @@ -1720,6 +1719,7 @@ view.Graph = class extends grapher.Graph {
}
for (const output of graph.outputs) {
const viewOutput = this.createOutput(output);
this.setNode(viewOutput);
for (const value of output.value) {
this.createValue(value).to.push(viewOutput);
}
Expand Down Expand Up @@ -1910,10 +1910,12 @@ view.Node = class extends grapher.Node {
}
if (Array.isArray(node.chain) && node.chain.length > 0) {
for (const innerNode of node.chain) {
this.context.createNode(innerNode);
this._add(innerNode);
}
}
if (node.inner) {
this.context.createNode(node.inner);
this._add(node.inner);
}
if (node.nodes) {
Expand Down

0 comments on commit 1afb385

Please sign in to comment.