gchart.lua

changeset 1
f930ba6a8923
parent 0
757c17d808a8
child 2
107b9d00e4d4
equal deleted inserted replaced
0:757c17d808a8 1:f930ba6a8923
106 if self.title then 106 if self.title then
107 return "chtt="..urlencode(tostring(self.title):gsub("\n", "|")); 107 return "chtt="..urlencode(tostring(self.title):gsub("\n", "|"));
108 end 108 end
109 end 109 end
110 110
111 ---- Legend ----
112 function chart:set_legend(entries)
113 self.legend = entries;
114 end
115
116 function writers:legend()
117 if self.legend then
118 return "chdl="..table.concat(self.legend, "|");
119 end
120 end
121
122 ---- Legend position ----
123 local position_map = {
124 vertical = { bottom = "b", top = "t", left = "l", right = "r" };
125 horizontal = { bottom = "b", top = "t" };
126 };
127
128 function chart:set_legend_position(position, layout)
129 self.legend_position = positionmap[layout or "vertical"][position or "right"] or position;
130 end
131
132 function writers:legend_position()
133 if self.legend_position then
134 return "chdlp="..self.legend_position;
135 end
136 end
111 ---- Axes display ---- 137 ---- Axes display ----
112 local axismap = { bottom = "x", left = "y", top = "t", right = "r" }; 138 local axismap = { bottom = "x", left = "y", top = "t", right = "r" };
113 function chart:add_axis(which, options) 139 function chart:add_axis(which, options)
114 table.insert(self.axes, { type = axismap[which], options = options }); 140 table.insert(self.axes, { type = axismap[which], options = options });
115 end 141 end
162 table.insert(result, "chxp="..urlencode(table.concat(positions, ","))); 188 table.insert(result, "chxp="..urlencode(table.concat(positions, ",")));
163 end 189 end
164 if next(styles) then 190 if next(styles) then
165 table.insert(result, "chxs="..urlencode(table.concat(styles, "|"))); 191 table.insert(result, "chxs="..urlencode(table.concat(styles, "|")));
166 end 192 end
167 if next(ticklengths) 193 if next(ticklengths) then
168 table.insert(result, "chxtc="..urlencode(table.concat(ticklengths, "|"))); 194 table.insert(result, "chxtc="..urlencode(table.concat(ticklengths, "|")));
169 end 195 end
170 196
171 return table.concat(result, "&"); 197 return table.concat(result, "&");
172 end 198 end

mercurial