Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Usage  





2 Functions  



2.1  makeMap  







3 Submodules  














Module:US elections imagemap






العربية
Tiếng Vit

 

Edit links
 









Module
Talk
 

















Read
View source
View history
 








Tools
   


Actions  



Read
View source
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 





Permanently protected module

From Wikipedia, the free encyclopedia
 


Usage

For general usage, use the wrapped template at {{US elections imagemap}}. This page is mainly documentation for Module maintainers.

Functions

makeMap

Generates the inner part of an imagemap. Needs to be wrapped with imagemap tags to work, this only generates state shapes and links. This is due to a limitation in Lua modules.

Parameters
Parameter Usage Example
link_template Template for links 2018 STATE gubernatorial election
cycle Election cycle Gov2[a]
extra_states Extra states to include[b] OR;WV[a]
extra_lines Extra raw lines to include[b] rect 702 391 725 423 [[2020–21 United States Senate special election in Georgia]]
state_overrides Set a custom link for the state, instead of following the template[b] AZ=2020 United States Senate special election in Arizona
excluded_states States to exclude. Overridden by extra_states[b] AK;HI
  1. ^ a b For valid values of |cycle= and |extra_states=, see Module:US elections imagemap/data.
  • ^ a b c d (; delimited)
  • Submodules

    -- 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
    

    Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:US_elections_imagemap&oldid=1046928521"

    Category: 
    Modules in beta
    Hidden category: 
    Wikipedia semi-protected modules
     



    This page was last edited on 28 September 2021, at 03:54 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki