Module:Sandbox/Frietjes/political graph

This is an old revision of this page, as edited by Frietjes (talk | contribs) at 23:42, 26 February 2023. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- this module implements [[Template:Political graph]]
local p = {}

function p.chart(frame, args)
	local chartfun = require('Module:Graph').chart
	local pfetch = require('Module:Political party')._fetch
	local tframe = {}
	tframe.args = {}
	local colors = mw.text.split(args['colors'] or '', '%s*[,]%s*')
	local tracking = ''
	for k,v in pairs(args) do
		if k:find('^y[%d]+Party$') then
			local digit = mw.ustring.match(k, '[%d]+')
		--	local color = colors[tonumber(digit)] or pfetch({v, 'color'})
			local pname = args['y' .. digit .. 'Title'] or pfetch({v, 'abbrev'})
			tframe.args['y' .. digit .. 'Title'] = tostring(pname)
			tracking = tracking .. '<br>' .. pname
		--	colors[tonumber(digit)] = color
			tframe.args[k] = v
		else
			tframe.args[k] = v
		end
	end
	-- tframe.args.colors = mw.ustring.gsub(table.concat(colors, ', '), '&#35;', '#')
	return chartfun(tframe)
end

function p.chartWrapper(frame)
	return p.chart(frame, frame:getParent().args)
end

return p