forked from KleeGroup-BaseCamp/appviz-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layer.js
40 lines (35 loc) · 930 Bytes
/
layer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Layer {
constructor(rows, columns) {
this.rows = rows;
this.columns = columns;
this.elements = [];
}
addElement(element) {
this.elements.push(element);
element.layer = this;
}
render() {
this.elements
.forEach( element => element.render());
}
selectElement(x, y) {
for (let element of this.elements) {
if (element.contains(x, y)) return element;
}
}
renderGrid(style = { stroke: 100, strokeWeight: 1 }) {
applyStyle(style);
const rowSize = windowHeight / this.rows;
const columnSize = windowWidth / this.columns;
for (let i = 0; i < this.rows; i++) {
line(0, rowSize * (i + 1), windowWidth, rowSize * (i + 1));
}
for (let j = 0; j < this.columns; j++) {
line(columnSize * (j + 1), 0, columnSize * (j + 1), windowHeight);
}
}
initStyle() {
this.elements
.forEach(element => element.initStyle());
}
}