# HG changeset patch # User Matthew Wild # Date 1245818049 -3600 # Node ID f930ba6a89230e55b218fa2003a39223a04abf96 # Parent 757c17d808a8d6d200866f8115bf0ede35fdcf0a Support for legends, and legend positioning diff -r 757c17d808a8 -r f930ba6a8923 gchart.lua --- a/gchart.lua Wed Jun 24 05:22:24 2009 +0100 +++ b/gchart.lua Wed Jun 24 05:34:09 2009 +0100 @@ -108,6 +108,32 @@ end end +---- Legend ---- +function chart:set_legend(entries) + self.legend = entries; +end + +function writers:legend() + if self.legend then + return "chdl="..table.concat(self.legend, "|"); + end +end + +---- Legend position ---- +local position_map = { + vertical = { bottom = "b", top = "t", left = "l", right = "r" }; + horizontal = { bottom = "b", top = "t" }; + }; + +function chart:set_legend_position(position, layout) + self.legend_position = positionmap[layout or "vertical"][position or "right"] or position; +end + +function writers:legend_position() + if self.legend_position then + return "chdlp="..self.legend_position; + end +end ---- Axes display ---- local axismap = { bottom = "x", left = "y", top = "t", right = "r" }; function chart:add_axis(which, options) @@ -164,7 +190,7 @@ if next(styles) then table.insert(result, "chxs="..urlencode(table.concat(styles, "|"))); end - if next(ticklengths) + if next(ticklengths) then table.insert(result, "chxtc="..urlencode(table.concat(ticklengths, "|"))); end