From f203f127a8e7b35bd8351b813cd3448e6bf9fd6e Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 9 Feb 2024 14:04:01 +0100 Subject: Added SVG output format --- .gitignore | 1 + activity/formats/svg.lua | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 activity/formats/svg.lua diff --git a/.gitignore b/.gitignore index 2d19fc7..583185c 100644 --- a/.gitignore +++ b/.gitignore @@ -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[==[ + + + %s + + + ]==]:format(title) -- dedent appends newline +end + + +function svg.end_document () + return "\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 = ([[]]):format(row_offset) + cell_offset = 28 + row_offset = row_offset + 14 + return row +end + + +function svg.end_row () + return "\n" +end + + +function svg.label (name) + return ([[%s]]):format(name) +end + + +function svg.spot () + cell_offset = cell_offset + 12 + return "" +end + + +function svg.cell (level) + local cell = ([[]]):format(level, cell_offset) + cell_offset = cell_offset + 12 + return cell +end + + +return svg -- cgit v1.1