Module:Sandbox/Frietjes/political graph: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(46 intermediate revisions by the same user not shown)
Line 2:
local p = {}
 
local function p.chartisnotempty(frame, argss)
return s and s:match( '^%s*(.-)%s*$' ) ~= ''
local chartfun = require('Module:Graph').chart
end
 
function p._chart_args(args)
local pfetch = require('Module:Political party')._fetch
local tframe = {}
tframe.args = {}
local colors = mw.text.split(args['colors'] or '', '%s*[,]%s*')
local trackingtargs = ''{}
for k,v in pairs(args) do
if k:find('^y[%d]+Party$') then
local digit = mw.ustringstring.match(k, '[%d]+')
-- local color = isnotempty(colors[tonumber(digit)]) and colors[tonumber(digit)] or pfetch({v, 'color'})
local pname = isnotempty(args['y' .. tonumber(digit .. 'Title']) and args['y' .. digit .. 'Title'] or pfetch({v, 'abbrev'})
tframe.argstargs['y' .. tonumber(digit) .. 'Title'] = tostring(pname)
-- colors[tonumber(digit)] = color
tracking = tracking .. '<br>' .. pname
-- colors[tonumber(digit)] = color
tframe.args[k] = v
else
tframe.argstargs[k] = v
end
end
-- tframe.args.targs['colors'] = mw.ustringstring.gsub(table.concat(colors, ', '), '&#35;', '#')
 
return chartfun(tframe)
return targs
end
 
function p.debug(frame)
returnlocal args = p.chart_chart_args(frame, frame:getParent().args)
local res = '<pre>\n{{Graph:Chart\n'
for k,v in pairs(args) do
res = res .. '| ' .. k .. ' = ' .. v .. '\n'
end
res = res .. '}}\n</pre>'
return res
end
 
function p.main(frame)
return mw.getCurrentFrame():expandTemplate{
title = 'Graph:Chart',
args = p._chart_args(frame:getParent().args)
}
end
 
function p.chartWrappermainlua(frame)
local chartfungraphchart = require('Module:Graph:Chart').chart
return p.chart(frame, frame:getParent().args)
frame.args = p._chart_args(frame:getParent().args)
return graphchart[''](frame)
end