diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | activity/formats/svg.lua | 81 |
2 files changed, 82 insertions, 0 deletions
@@ -1 +1,2 @@ *.html +*.svg diff --git a/activity/formats/svg.lua b/activity/formats/svg.lua new file mode 100644 index 0000000..ab3ab69 --- /dev/null +++ b/activity/formats/svg.lua @@ -0,0 +1,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 = 28 + + +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) + cell_offset = cell_offset + 12 + return cell +end + + +return svg |