diff options
author | Aki <please@ignore.pl> | 2024-02-09 14:04:01 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2024-02-09 14:29:16 +0100 |
commit | f203f127a8e7b35bd8351b813cd3448e6bf9fd6e (patch) | |
tree | 7a6400daefd8d189a225289bd37312dc5a71387e | |
parent | 81c794b42e6356f51c74e879e8d6e911f63c1499 (diff) | |
download | activity-f203f127a8e7b35bd8351b813cd3448e6bf9fd6e.zip activity-f203f127a8e7b35bd8351b813cd3448e6bf9fd6e.tar.gz activity-f203f127a8e7b35bd8351b813cd3448e6bf9fd6e.tar.bz2 |
Added SVG output format
-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 |