Draw group borders

This commit is contained in:
Ian Gulliver
2019-07-04 06:42:05 +00:00
parent 9a4e90de51
commit b86994093b
4 changed files with 58 additions and 16 deletions

View File

@@ -1,5 +1,6 @@
class LayoutGroup {
constructor(nodes) {
constructor(graphGroup, nodes) {
this.graphGroup_ = graphGroup;
this.nodes = new Set(nodes);
this.tension = 0;
}
@@ -49,4 +50,34 @@ class LayoutGroup {
}
}
}
getMinMax() {
let min = [Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER];
let max = [Number.MIN_SAFE_INTEGER, Number.MIN_SAFE_INTEGER];
for (let node of this.nodes) {
for (let i of [0, 1]) {
min[i] = Math.min(min[i], node.pos[i]);
max[i] = Math.max(max[i], node.pos[i]);
}
}
if (this.graphGroup_ && this.graphGroup_.label) {
// Room for the label
--min[1];
}
return [min, max];
}
getStep() {
if (!this.graphGroup_) {
return null;
}
let [min, max] = this.getMinMax();
return {
type: 'group',
min: min,
max: max,
label: this.graphGroup_.label,
};
}
}