-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathquad.go
78 lines (71 loc) · 1.89 KB
/
quad.go
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
package visual
import (
"fmt"
"io"
)
// Primitives for drawing hexary strings in graphviz dot format
var QuadIndexColors = []string{
"#FFFFFF", // white
"#FBF305", // yellow
"#F20884", // magenta
"#02ABEA", // cyan
}
var QuadFontColors = []string{
"#000000",
"#000000",
"#000000",
"#000000",
}
var quadIndices = []string{"0", "1", "2", "3"}
// QuadVertical produces a vertical line corresponding to quad digits in key (one byte - one digit)
// highlighted - number of digits that need to be highlighted (contain digits themselves)
// name - name of the compontent (to be connected to others)
func QuadVertical(w io.Writer, quad []byte, highlighted int, name string) {
fmt.Fprintf(w,
`
%s [label=<
<table border="0" color="#000000" cellborder="1" cellspacing="0">
`, name)
for i, h := range quad {
if i < highlighted {
fmt.Fprintf(w,
` <tr><td bgcolor="%s"><font color="%s">%s</font></td></tr>
`, QuadIndexColors[h], QuadFontColors[h], quadIndices[h])
} else {
fmt.Fprintf(w,
` <tr><td bgcolor="%s"></td></tr>
`, QuadIndexColors[h])
}
}
fmt.Fprintf(w,
`
</table>
>];
`)
}
// QuadHorizontal produces a horizontal line corresponding to quad digits in key (one byte - one digit)
// highlighted - whether digits need to be highlighted (contain digits themselves)
// name - name of the compontent (to be connected to others)
func QuadHorizontal(w io.Writer, quad []byte, highlighted bool, name string) {
fmt.Fprintf(w,
`
%s [label=<
<table border="0" color="#000000" cellborder="1" cellspacing="0"><tr>
`, name)
for _, h := range quad {
if highlighted {
fmt.Fprintf(w,
` <td bgcolor="%s" port="q%s"><font color="%s">%s</font></td></tr>
`, QuadIndexColors[h], quadIndices[h], QuadFontColors[h], quadIndices[h])
} else {
fmt.Fprintf(w,
` <td bgcolor="%s" port="q%s"></td>
`, QuadIndexColors[h], quadIndices[h])
}
}
fmt.Fprintf(w,
`
</tr></table>
>];
`)
}