-- the goal of this module is to standardize creating imagemaps for yearly Senate and Gubernatorial elections in the United States.
local utils = require("Module:US elections imagemap/utils") -- utilities such as a string splitting function
local data = require("Module:US elections imagemap/data") -- data such as shapes of states
local stateshapes = data.stateshapes
local cycles = data.cycles
local statenames = data.statenames
local p = {}
function p.makeMap(frame) -- limitations: currently no way to add custom shapes, or to add custom states to cycles, or to add custom links not following the general template
local states = cycles[frame.args.cycle] or error("error: invalid/no cycle specified") -- require to specify a cycle
local extrastates = utils.split(frame.args.extra_states or "", ";") -- extra states to add
states = utils.listmerge(states, extrastates)
local extralines = utils.split(frame.args.extra_lines or "", ";") -- extra raw lines to add
local linktemplatearg = frame.args.link_template or error("error: no link template specified") -- require a link template
local linktemplate = " [[" .. linktemplatearg .. "]]\r\n\r\n" -- make it a wikilink, also the space is necessary to separate from the shape data
local imagemap = "\r\n\r\n" -- start the imagemap
for _, state in ipairs(states) do -- for each state
statename = statenames[state] or error (state) -- if a state isn't in the list for some reason, this will tell which one
local link = string.gsub(linktemplate, "STATE", statenames[state]) -- swap the state name into the link template
imagemap = imagemap .. stateshapes[state] .. link -- add the link (which already contains the needed newline)
end
for _, line in ipairs(extralines) do -- for each extra line
--local linetoadd = utils.split(line, ",")[0] .. " [[" .. utils.split(line, ",")[1] .. "]]" -- first we split the line by "," and linkify the second half
return utils.split(line, ",")[0]
--imagemap = imagemap .. line .. "\r\n\r\n" -- append the extra line
end
return imagemap
end
return p