blob: f7e2700c6fca6a4fb793b328428a40a16110020a (
plain)
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
81
|
local stringx = require "pl.stringx"
local svg = {}
function svg.start_document (title)
return stringx.dedent[==[
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 663 95">
<title>%s</title>
<defs>
<style type="text/css"><![CDATA[
.label { font: 11px sans-serif; }
.cell {
width: 11px;
height: 11px;
rx: 2px;
}
.cell.level0 { fill: #ccc; }
.cell.level1 { fill: #9be9a8; }
.cell.level2 { fill: #40c463; }
.cell.level3 { fill: #30a14e; }
.cell.level4 { fill: #216e39; }
]]></style>
</defs>]==]:format(title) -- dedent appends newline
end
function svg.end_document ()
return "</svg>\n"
end
local row_offset = 0 -- Format(s) should be stateful and instantiable.
function svg.start_table ()
row_offset = 0
return [[]] .. "\n"
end
function svg.end_table ()
return ""
end
local cell_offset
function svg.start_row ()
local row = ([[<g transform="translate(0,%d)">]]):format(row_offset)
cell_offset = 28
row_offset = row_offset + 14
return row
end
function svg.end_row ()
return "</g>\n"
end
function svg.label (name)
return ([[<text y="10px" class="label">%s</text>]]):format(name)
end
function svg.spot ()
cell_offset = cell_offset + 12
return ""
end
function svg.cell (level)
local cell = ([[<rect class="cell level%d" x="%d"/>]]):format(level, cell_offset)
svg.spot() -- Increment cell_offset in one place in code.
return cell
end
return svg
|