Jump to content

Module:Seats diagram

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Julio974fr (talk | contribs) at 17:08, 19 September 2023 (first draft (incomplete ofc)). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

require('strict')
local p = {}
local getArgs = require('Module:Arguments').getArgs
local errorCategory = '[[Category:Compilation error of the Seats diagram template]]'
local getColor = require('Module:Political party').fetch

local function generateDiagram(root, args)
	return root
end

local function parliamentFloat(root, args)
	local width = args.width or 15 -- 1em roughly equals 15px
	local mainDiv = root:tag('div')
	
	mainDiv:addClass('thumb')
	mainDiv:addClass('t'..args['float'])
	
	local divThumbinner = mainDiv:tag('div')
	divThumbinner:addClass('thumbinner')
	divThumbinner:css('width', tostring(18*width)..'px')
	divThumbinner:css('padding-right', '5px !important')
	
	if args['title'] then
		local divTitle = divThumbinner:tag('div')
		divTitle:addClass('thumbdescription')
		divTitle:css('font-weight', 'bold')
		divTitle:css('text-align', 'center')
		divTitle:css('font-size', '100%')
		divTitle:wikitext(args['title'])
	end
	
	local divThumbimage = divThumbinner:tag('div')
	divThumbimage:addClass('thumbimage')
	divThumbimage:addClass('diagram')
	divThumbimage:addClass('noprint')
	divThumbimage:css('width', tostring(16*width)..'px')
	divThumbimage:css('height', tostring(8*width)..'px')
	divThumbimage:css('padding', tostring(width)..'px')
	divThumbimage:css('overflow', 'hidden')
	divThumbimage:css('background', 'white')
	
	generateDiagram(divThumbimage, args)
	
	local divThumbdescription = divThumbinner:tag('div')
	if args.image_legend then
		divThumbdescription:wikitext(image_legend)
	else
		-- @todo Generate legend
	end
	
	return root
end

local function parliamentNonFloat(root, args)
	local width = args.width or 15 -- 1em roughly equals 15px
	local mainDiv = root:tag('div')
	
	local divCentered = mainDiv:tag('div')
	divCentered:addClass('centered')
	divCentered:addClass('diagram')
	divCentered:addClass('noprint')
	divCentered:css('width', tostring(16*width)..'px')
	divCentered:css('height', tostring(8*width)..'px')
	divCentered:css('padding', tostring(width)..'px')
	divCentered:css('overflow', 'hidden')
	divCentered:css('background', 'white')
	
	divCentered:css('text-align', 'center')
	
	generateDiagram(divCentered, args)
	
	return root
end

function p._parliament(args)
	local root = mw.html.create('div')
	
	if args['float'] then
		return parliamentFloat(root, args)
	else
		return parliamentNonFloat(root, args)
	end
end

function p.parliament(frame)
	return p._parliament(getArgs(frame))
end

return p