Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Humanipedia
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Module:US elections imagemap
Module
Discussion
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
-- 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; do NOT change to mw.loadData as that breaks excluded-states local stateshapes = data.stateshapes local cycles = data.cycles local statenames = data.statenames local p = {} function p.makeMap(frame) 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 local extralines = utils.split(frame.args.extra_lines or "", ";") -- extra raw lines to add local excludedstates = utils.split(frame.args.excluded_states or "", ";") -- states to EXCLUDE for _, excludedstate in ipairs(excludedstates) do for k, state in ipairs(states) do if state == excludedstate then table.remove(states, k) -- remove the state from the table. this doesn't remove it if it's included in extra_states end end end local stateoverrides = utils.split(frame.args.state_overrides or "", ";") -- state overrides for links (for example, linking to a recall election) local overrides = {} -- overrides should be an array of STATE="Override" for _, override in ipairs(stateoverrides) do local overridear = utils.split(override,"=") overrides[overridear[1]] = " [[" .. overridear[2] .. "]]\r\n\r\n" -- format the same as normal links end 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 _, line in ipairs(extralines) do -- for each extra line. these have to come before normal lines to override them (otherwise, special elections for example don't work) imagemap = imagemap .. line .. "\r\n\r\n" -- append the extra line end for _, state in ipairs(extrastates) do -- for each extrastate - do first, in case of conflicts (like special elections, see above) statename = statenames[state] or error (state) -- if a state isn't in the list for some reason, this will tell which one local link = overrides[state] or string.gsub(linktemplate, "STATE", statenames[state]) -- check for individual state override, if not, swap the state name into the link template imagemap = imagemap .. stateshapes[state] .. link -- add the link (which already contains the needed newline) end 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 = overrides[state] or string.gsub(linktemplate, "STATE", statenames[state]) -- check for individual state override, if not, swap the state name into the link template imagemap = imagemap .. stateshapes[state] .. link -- add the link (which already contains the needed newline) end return imagemap end return p
Summary:
Please note that all contributions to Humanipedia may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Humanipedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Efn
(
edit
)
Template:Error
(
edit
)
Template:Lua sidebar
(
edit
)
Template:Main other
(
edit
)
Template:Module other
(
edit
)
Template:Module rating
(
edit
)
Template:Notelist
(
edit
)
Template:Ombox
(
edit
)
Template:Para
(
edit
)
Template:Pp
(
edit
)
Template:Protection padlock
(
edit
)
Template:Reflist
(
edit
)
Template:Reflist/styles.css
(
edit
)
Template:Sidebar
(
edit
)
Template:T
(
edit
)
Template:Template link
(
edit
)
Template:Tl
(
edit
)
Module:Check for unknown parameters
(
edit
)
Module:Error
(
edit
)
Module:File link
(
edit
)
Module:Message box
(
edit
)
Module:Protection banner
(
edit
)
Module:US elections imagemap/doc
(
edit
)