-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGridMaker.js
70 lines (60 loc) · 2.21 KB
/
GridMaker.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class GridMaker {
#grid;
#rowNumber;
#colNumber;
#canvasId;
#tableElement;
#tableObject;
constructor({ grid, canvasId } = {}) {
this.#grid = grid;
this.#rowNumber = grid.length;
this.#colNumber = grid[0].length;
this.#canvasId = canvasId;
this.#tableElement = document.createElement("table");
this.#tableObject = Array(this.#rowNumber);
}
draw() {
this.#tableElement.classList.add("grid");
this.#tableElement.style.display = "inline-block";
this.#tableElement.style.margin = 0;
this.#tableElement.style.padding = 0;
for (let row = 0; row < this.#rowNumber; row += 1) {
const tableRow = document.createElement("tr");
tableRow.classList.add("row");
tableRow.dataset["row"] = row;
tableRow.style.display = "block";
tableRow.style.margin = 0;
tableRow.style.padding = 0;
tableRow.style.borderLeft = "1px solid black";
tableRow.style.borderRight = "1px solid black";
tableRow.style.borderTop = row == 0 ? "1px solid black" : 0;
tableRow.style.borderBottom = row == this.#rowNumber - 1 ? "1px solid black" : 0;
this.#tableObject[row] = Array(this.#colNumber);
for (let col = 0; col < this.#colNumber; col += 1) {
const tableCol = document.createElement("td");
tableCol.classList.add("col");
tableCol.dataset["row"] = row;
tableCol.dataset["col"] = col;
tableCol.style.display = "inline-block";
tableCol.style.textAlign = "center";
tableCol.style.verticalAlign = "center";
tableCol.style.minWidth = "20px";
tableCol.style.margin = 0;
tableCol.style.padding = "20px";
tableCol.style.fontSize = "14pt";
tableCol.style.fontWeight = 900;
tableCol.style.border = "2px solid #222";
tableCol.style.position = "relative";
tableCol.append(document.createTextNode(this.#grid[row][col]));
tableRow.append(tableCol);
this.#tableObject[row][col] = tableCol;
}
this.#tableElement.append(tableRow);
}
document.getElementById(this.#canvasId).replaceChildren();
document.getElementById(this.#canvasId).append(this.#tableElement);
}
get table() {
return this.#tableObject;
}
}