Edge Rewrite
// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a27b291cfea6d04f

Jump to content

Module:Political choropleth legend

From Wikipedia, the free encyclopedia

local p = {}
local data = mw.loadData('Module:Political choropleth legend/data')

local function create_error(error_message) --- from [[Module:Political party]]
	return string.format('<strong class="error">%s</strong>', error_message)
end

function p._create_legend(frame, args)
	if not args[1] then
		return create_error("parameter 1 should be a party name")
	end
	local party_name = args[1]
	local party_data = data[party_name]
	if not party_data then
		return create_error("unknown political party " .. party_name)
	end
	local legend_template = args["template"] or "legend"
	
	local output = ""
	
	for i, range in ipairs(args) do
		if i > 1 then
			local range_color = party_data[range]
			if not range_color then
				return create_error("missing range" .. range .. "for political party " .. party_name)
			end
			
			if range == "90" then range = ">90" end -- replace this with a translation table if it gets any more complicated
			range = range:gsub("-", "–") .. "%"
			
			output = output .. frame:expandTemplate{ title = legend_template, args = { range_color, range } }
		end
	end
	
	return output
end

function p.create_legend(frame)
	-- Initialise and populate variables
	local args = require("Module:Arguments").getArgs(frame, {wrappers = "Template:Political choropleth legend"})
	
	return p._create_legend(frame, args)
end

return p