Support for legends, and legend positioning

Wed, 24 Jun 2009 05:34:09 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 24 Jun 2009 05:34:09 +0100
changeset 1
f930ba6a8923
parent 0
757c17d808a8
child 2
107b9d00e4d4

Support for legends, and legend positioning

gchart.lua file | annotate | diff | comparison | revisions
--- 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
 	

mercurial