Module:Political choropleth legend
Appearance
| This module is rated as pre-alpha. It is incomplete and may or may not be in active development. Do not use it in article namespace pages. A module remains in pre-alpha until its developer, or another editor who adopts it if it is abandoned for some time, considers the basic structure complete. |
| This module depends on the following other modules: |
Usage
[edit]This module implements the {{Political choropleth legend}} template. Please see the template page for usage instructions.
Updating the module
[edit]The political parties contained in this article are stored under /data and originate from the color schemes in WP:USALEGEND and Wikipedia:WikiProject Elections and Referendums/USA legend colors/proposals. All ranges matching the format "50-60" will be rendered as "50–60%" while "90" will be rendered as ">90%". As an example:
["Yes"] = {
["50-60"] = "#B6C8D9",
["60-70"] = "#7D9CBB",
["70-80"] = "#47729E",
["80-90"] = "#28497C",
["90"] = "#2B2457"
}
50–60%
60–70%
70–80%
>90%
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