-
Notifications
You must be signed in to change notification settings - Fork 156
/
debug.js
80 lines (73 loc) · 2.66 KB
/
debug.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
71
72
73
74
75
76
77
78
79
80
/*Copyright 2021 Kirk McDonald
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/
import { spec } from "./factory.js"
function renderMatrix(d, A, m) {
let table = d.append("table")
.attr("border", 1)
let header = table.append("tr")
header.append("th")
for (let item of m.items) {
let th = header.append("th")
th.append(() => new Text("s"))
th.append(() => item.icon.make(32))
.classed("item-icon", true)
}
for (let t of m.targets) {
let th = header.append("th")
th.append(() => t.item.icon.make(32))
th.append(() => new Text("\u21d0"))
th.append(() => t.recipe.icon.make(32))
}
header.append("th")
.text("tax")
for (let recipe of m.recipes) {
header.append("th")
.append(() => recipe.icon.make(32))
.classed("item-icon", true)
}
header.append("th")
.text("answer")
header.append("th")
.text("C")
for (let r = 0; r < A.rows; r++) {
let row = table.append("tr")
let label = row.append("td")
if (r < m.recipes.length) {
label.append(() => m.recipes[r].icon.make(32))
.classed("item-icon", true)
} else if (r === A.rows - 2) {
label.append(() => new Text("tax"))
} else {
label.append(() => new Text("answer"))
}
for (let c = 0; c < A.cols; c++) {
let x = A.index(r, c)
row.append("td")
.classed("right-align", true)
.append("tt")
.text(x.toString())
}
}
}
export function renderDebug() {
let debugTab = d3.select("#debug_tab")
let lastTableau = d3.select("#debug_tableau")
lastTableau.selectChildren().remove()
let lastSolution = d3.select("#debug_solution")
lastSolution.selectChildren().remove()
if (spec.lastTableau === null) {
d3.select("#debug_message").text("No tableau required.")
} else {
d3.select("#debug_message").text("Displaying previous tableau.")
renderMatrix(lastTableau, spec.lastTableau, spec.lastMetadata)
renderMatrix(lastSolution, spec.lastSolution, spec.lastMetadata)
}
}