require('strict')local p = local getArgs = require('Module:Arguments').getArgslocal errorCategory = ''local getColor = require('Module:Political party').fetchlocal dimx = 175local dimr = 50local dimc = 40local limite = 2000local bgcolor = "#fff"
-- Error handler using xpcall, format the errorlocal function errhandler(msg) local cat = mw.title.getCurrentTitle.namespace
-- create a single array from stringlocal function agg(a,...) local args = for _, s in ipairs(args) do table.insert(a, s) endend
-- get the party color from Module:Party color-- a = party; b = optional colorlocal function color(a,b) local c = '#CCC' if (b) then c = b else c = getColor end if string.sub(c,1,5)
-- create circleslocal function values(n) local totals=
local dots = 0 local benches = 1 local jj,rr,aa
-- searches for the amount of benches needed to show all the dots while (n > totals[benches]) do benches = benches + 1 end local dd = dimr/benches -- distance between the arches dimc = 0.7*dimr/benches -- size of the circles local list = -- list of dots -- calculate angle and radius of each dot for rg=0,benches-2 do rr = dimx - dd*(2*rg+1) -- radius jj = math.floor((n/totals[benches])*math.pi/(2*math.asin(dd/rr)))+1 --n° dots if (jj
1) then dots = dots + 1 list[dots] = else for ps=0,jj-1 do aa=ps/(jj-1) dots = dots + 1 list[dots] = end end -- order dots per increasing angle from the center table.sort(list, function(a,b) return ((a[1]
b[1] and a[2]
-- create the parliamentary archfunction p._parliament(args) local ss = local ss2 = local data = local num = 1 local totalDots = 0 local cap = args.caption or local show = tonumber(args.show) or 0
while (args['n'..num]) do if (tonumber(args['n'..num])) then data[num] = totalDots = totalDots + data[num].n num = num+1 else error(string.format('Invalid value for n%d', num),2) end end num = num - 1 if (totalDots>limite) then error('Number of dots superior to the limit') elseif (totalDots<1) then error('No dots are indicated') end local dots = values(totalDots) local width = 2*dimx local height = dimx+dimc local scale = 1.0 if (args['background']) then bgcolor = args['background'] end if (args['width'] and tonumber(args['width'])) then width = tonumber(args['width']) scale = width/(2*dimx) height = (dimx+dimc)*scale elseif (args['height'] and tonumber(args['height'])) then height = tonumber(args['height']) scale = height/(dimx+dimc) width = 2*dimx*scale elseif (totalDots<29) then width = 280 scale = width/(2*dimx) height = (dimx+dimc)*scale elseif (totalDots<101) then width = 300 scale = width/(2*dimx) height = (dimx+dimc)*scale elseif (totalDots<281) then width = 350 scale = width/(2*dimx) height = (dimx+dimc)*scale end -- TEMPORARY FIX WHILE THE GRAPH EXTENSION IS DISABLED -- local seats_diagram = require('Module:Seats_diagram') args.width = width if true then return tostring(seats_diagram._parliament(args)) end --------------------------------------------------------- local graph = local ee = 0 local values for i=1,num do values = for j=1,data[i].n do ee = ee + 1 values[j] = end graph['data'][i] = graph['marks'][i] = if (data[i].b ~= "-") then local bl = data[i].b if string.sub(bl,1,5)
%s
',cap)) end if show1 then for i=1,num do agg(ss2,string.format('
%s', data[i].c, data[i].n)) end agg(ss,'') agg(ss,table.concat(ss2," · ")) agg(ss,'
') elseif show') agg(ss,table.concat(ss2,"
")) agg(ss,'
function p.parliament(frame) return select(2, xpcall(function return p._parliament(getArgs(frame,)) end, errhandler))end
return p