Skip to content

Commit ad1193c

Browse files
committed
html utils
1 parent 42eac10 commit ad1193c

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

src/main/scala/Main.scala

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,20 @@ def registerEvents(): Unit =
1717
input.onclick = (e: dom.Event) =>
1818
window.console.log("Button clicked")
1919
val decmatoutput: HTMLDivElement = document.getElementById("div_decmat_output").asInstanceOf[HTMLDivElement]
20-
val textarea : HTMLTextAreaElement = document.getElementById("textarea_decmat").asInstanceOf[HTMLTextAreaElement]
21-
val textcontent = textarea.value
22-
decmatoutput.innerHTML = ""
23-
decmatoutput.appendChild(HtmlUtils.makeTable(HtmlUtils.parseTextToTable(textcontent)))
20+
21+
val decmat = Array(
22+
Array(1.0, 2.0, 3.0),
23+
Array(4.0, 5.0, 6.0),
24+
Array(7.0, 8.0, 9.0)
25+
)
26+
val weights = Array(0.3, 0.5, 0.2)
27+
val directions = Array(Direction.Maximize, Direction.Maximize, Direction.Maximize)
28+
val result = topsis(decmat, weights, directions)
29+
val result2 = aras(decmat, weights, directions)
30+
val result3 = saw(decmat, weights, directions)
31+
val result4 = critic(decmat, directions)
32+
val table1 = HtmlUtils.makeOutput(result)
33+
decmatoutput.appendChild(table1)
2434
@main def hello(): Unit =
2535
window.console.log("Hello, world!")
2636
registerEvents()

src/main/scala/htmlutils.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ object HtmlUtils:
88
val document = dom.document
99
val window = dom.window
1010

11+
def makeOutput(input: TopsisResult): HTMLDivElement =
12+
val div = document.createElement("div").asInstanceOf[HTMLDivElement]
13+
val table1 = makeTable(input.normalizedMatrix)
14+
val table2 = makeTable(input.weightedNormalizedMatrix)
15+
val table3 = makeTable(Matrix.makeColumnMatrix(input.ideal))
16+
val table4 = makeTable(Matrix.makeColumnMatrix(input.antiIdeal))
17+
val table5 = makeTable(Matrix.makeRowMatrix(input.scores))
18+
div.appendChild(document.createElement("h2")).textContent = "Normalized matrix"
19+
div.appendChild(table1)
20+
div.appendChild(document.createElement("h2")).textContent = "Weighted normalized matrix"
21+
div.appendChild(table2)
22+
div.appendChild(document.createElement("h2")).textContent = "Ideal"
23+
div.appendChild(table3)
24+
div.appendChild(document.createElement("h2")).textContent = "Anti-ideal"
25+
div.appendChild(table4)
26+
div.appendChild(document.createElement("h2")).textContent = "Scores"
27+
div.appendChild(table5)
28+
div
29+
1130
def makeTable(a: Mat): dom.HTMLTableElement =
1231
val table = document.createElement("table").asInstanceOf[dom.HTMLTableElement]
1332
a.foreach(row =>

src/main/scala/matrix.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,7 @@ object Matrix:
131131
def subtract(a: Mat, b: Mat): Mat =
132132
a.zip(b).map((rowa, rowb) => rowa.zip(rowb).map((x, y) => x - y))
133133

134+
def makeRowMatrix(v: Vec): Mat = v.map(x => Array(x))
135+
136+
def makeColumnMatrix(v: Vec): Mat = Array(v)
137+

style.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
text-align: center;
55
font-size: 16px;
66
font-weight: bold;
7+
font-family: 'Courier New', Courier, monospace;
78
color: black;
8-
background-color: white;
9+
background-color: bisque;
910
}
1011

1112
input[type="button"] {

0 commit comments

Comments
 (0)