-- this code came from User:Martijn Hoekstra; I'm curious how he handled the task. -- (for my version see Module:Plotter|bar -- Wnt)
local p=local better= -- functions to make or snarf to put in some libraryfunction better.concat(sometable,ignore,delimiter,delimiter2,delimiter3,level) -- This one's mine - Wnt local output="" delimiter=delimiter or ",";delimiter2=delimiter2 or "" if not(ignore) then ignore= end -- ignore specifies types not to report if not(next(sometable)) then return "" end local notfirst;local display for i,j in pairs(sometable) do if not(ignore[type(j)]) then if notfirst then display=delimiter end if type(j)
function p.main local testdata = return better.concat(testdata,nil,",","",2)..bar_chart("1000px", "1000px", testdata, nil, nil)end
function bar_chart(height, width, data, xlabels, ylabels) local maxy = maxr(data) local paired = --where is a map function when you need one? for k, s in pairs(data) do for i, d in pairs(s[2]) do if paired[k]
%s<\/div>',datapoint(v, "label", maxy)) end return better.concat(paired)..string.format('
%s<\/div>', height, width, content)end
function transpose(matrix) local trans = for i, r in pairs(matrix) do -- ? for each yseries pull out the [x] part for j, v in pairs(r) do -- for each x, if trans[j]
--borks on circular reference: pass seen tables along to fixfunction maxr(mytable) local max = 0 for k,v in pairs(mytable) do if type(v)
"table" then max = math.max(maxr(v), max) end end return maxend
--data: one datapoint of n datasets: data = function datapoint(data, label, maxy) --fix with margins instead? My css fu is weak. local result = '
' for k,v in pairs(data) do result = result .. '\n' .. bar(v[2], maxy, v[1]) end return result .. string.format('<\/div>\n
%s<\/div>', label)end
function bar(value, maxvalue, color) return string.format('
<\/div>', color, math.ceil(value/maxvalue *100))end
return p