Draw nodes on the grid

This commit is contained in:
Ian Gulliver
2019-06-26 18:27:52 +00:00
parent 8a458cc4ba
commit c8cf54350d
2 changed files with 29 additions and 8 deletions

View File

@@ -124,3 +124,11 @@ body {
display: grid;
align-content: center;
}
.gridNode {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}

View File

@@ -165,15 +165,16 @@ class Architype {
}
buildGraphNode(graph, node) {
node.clear();
if (node.getLabel() != '') {
let targets = graph.nodesByLabel.get(node.getLabel());
if (!targets) {
targets = [];
graph.nodesByLabel.set(node.getLabel(), targets);
}
targets.push(node);
if (node.getLabel() == '') {
return;
}
node.clear();
let targets = graph.nodesByLabel.get(node.getLabel());
if (!targets) {
targets = [];
graph.nodesByLabel.set(node.getLabel(), targets);
}
targets.push(node);
}
buildGraphGroup(graph, group) {
@@ -308,12 +309,24 @@ class Architype {
}
buildGrid() {
this.grid_.innerHTML = '';
this.grid_.style.gridTemplateColumns =
'repeat(' + this.graph_.size[0] + ',1fr)';
this.grid_.style.gridTemplateRows =
'repeat(' + this.graph_.size[1] +
',minmax(0, calc((100vw - var(--editor-width)) / ' +
this.graph_.size[0] + ')))';
// TODO: split this out
for (let node of this.graph_.nodes) {
node.gridElem = document.createElement('div');
node.gridElem.classList.add('gridNode');
this.grid_.appendChild(node.gridElem);
node.gridElem.innerText = node.getLabel();
node.gridElem.style.gridColumn = node.pos[0] + 1;
node.gridElem.style.gridRow = node.pos[1] + 1;
}
}
}