Module:Storm categories
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This Lua module is used on many pages, so changes to it will be widely noticed. Please test any changes in the module's /sandbox or /testcases subpages. Please consider discussing changes on the talk page before implementing them. |
In order to conform to Wikipedia:Manual of Style/Accessibility#Color guidelines, do not use storm colors in conjunction with links. This is necessary to avoid problems related to lack of contrast. |
This module depends on the following other modules: |
This template is used to control a multitude of tropical cyclone-related templates:
- REDIRECT Template:Template link
This page is a redirect. The following categories are used to track and monitor this redirect:
|
Data is located in the following submodules:
- Module:Storm categories/categories for fully-detailed storm categories
- Module:Storm categories/colors for color-only IDs
- Module:Storm categories/icons for icon-only IDs
Usage
This module exports three functions for templates: p.color
, p.name
, p.sortkey
, and p.icon
. It also provides p._color
, p._name
, p._sortkey
, and p._icon
for use in other modules.
All input IDs are case-insensitive, and all non-alphanumeric characters are stripped.
Color
Provides the color of the given tropical cyclone category code. This comes in the format of their raw hexadecimal code. This function is available as a template at {{storm colour}}.
Code | Output |
---|---|
<span style="padding:4px;border:1px solid black;background-color:#{{#invoke:Storm categories|color|depression}}">depression</span>
|
<span style="padding:4px;border:1px solid black;background-color:#Lua error in package.lua at line 80: module 'Module:Storm categories/icons' not found.">depression |
Name
Provides the name of the given tropical cyclone category code. A optional basin argument can be provided as the second argument in order to slightly tweak the name of the category, if the given category definition supports it. This function is available as a template at {{storm name}}.
Code | Interpreted | Output | |
---|---|---|---|
ID | Basin | ||
{{#invoke:Storm categories|name|severe}}
|
severe | (default) | Lua error in package.lua at line 80: module 'Module:Storm categories/icons' not found. |
{{#invoke:Storm categories|name|spr - cYcL -s TorM}}
|
sprcyclstorm | (default) | Lua error in package.lua at line 80: module 'Module:Storm categories/icons' not found. |
{{#invoke:Storm categories|name|cat5}}
|
cat5 | (default) | Lua error in package.lua at line 80: module 'Module:Storm categories/icons' not found. |
{{#invoke:Storm categories|name|cat5|ATl}}
|
cat5 | ATl | Lua error in package.lua at line 80: module 'Module:Storm categories/icons' not found. |
{{#invoke:Storm categories|name|cat5|WPac}}
|
cat5 | WPac | Lua error in package.lua at line 80: module 'Module:Storm categories/icons' not found. |
Sortkey
The sortkey is a number that aids in sorting categories. Using the sortkey, it is possible to automatically sort a table of tropical cyclones given their category code. Due to the ambiguous nature of sortkeys, tables may be sorted incorrectly if values from other basins were used. For categories that span multiple basins, however, (e.g. depression
and storm
) they are given the lowest possible sortkeys in order to achieve maximum compatibility.
This sortkey is used in {{storm sortkey}} and {{Tropical cyclone season effects (cyclone)}}, a subtemplate of {{Tropical cyclone season effects}}.
The sortkey format is as follows. Note that not all values between the given ranges were used. The arrangement of these were determined by their positions in the {{Storm colour}} template.
Basin | Sortkey range |
---|---|
Global (unused) | 90000 to 99999 |
Atl/EPac/SAtl | 80000 to 89999 |
WPac | 60000 to 69999 |
Nio | 50000 to 59999 |
Aus/Fiji | 40000 to 49999 |
SWio | 30000 to 39999 |
Historical | 20000 to 29999 |
Global | 0 to 9999 |
A demonstration of a sortable table using these sortkeys can be found below. Note that it does not use categories outside of its own basin (in this case, the Atl/EPac/SAtl basin) and the global range.
Category | Sortkey | Code |
---|---|---|
cat3 | Error in Template:Nts: Fractions are not supported | {{#invoke:Storm categories|sortkey|cat3}}
|
cat1 | Error in Template:Nts: Fractions are not supported | {{#invoke:Storm categories|sortkey|cat1}}
|
cat5 | Error in Template:Nts: Fractions are not supported | {{#invoke:Storm categories|sortkey|cat5}}
|
cat4 | Error in Template:Nts: Fractions are not supported | {{#invoke:Storm categories|sortkey|cat4}}
|
depression | Error in Template:Nts: Fractions are not supported | {{#invoke:Storm categories|sortkey|depression}}
|
cat2 | Error in Template:Nts: Fractions are not supported | {{#invoke:Storm categories|sortkey|cat2}}
|
Sorting table which uses different basins
| ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Icon
Icons exist for some Storm categories for presentation purposes. This function is available as a template at {{storm icon}}. p.icon
will return wikitext of an image or formatted text.
Full list of available values
The following table is generated by invoking the demo
function of this module. Some IDs are only available as colors or icons because they existed as parameters on old non-module template implementations and cannot be feasibly aliased to a specific tropical cyclone category.
It will show any color errors, including colors which aren't compliant with the minimal Web Content Accessibility Guidelines 2.0 AA color standards (see MOS:COLOR for more information). Lua error in package.lua at line 80: module 'Module:Storm categories/icons' not found.
local categoryData = require("Module:Storm categories/categories") local colors = require("Module:Storm categories/colors").colors local icons = require("Module:Storm categories/icons").icons local cats = categoryData.cats local defaultCategory = categoryData.defaultCategory local p = {} function p.color(frame) return p._color(frame.args[1] or frame:getParent().args[1], false) end function p.name(frame) return p._name( frame.args[1] or frame:getParent().args[1], frame.args[2] or frame:getParent().args[2], false ) end function p.sortkey(frame) return p._sortkey(frame.args[1] or frame:getParent().args[1], false) end function p.icon(frame) return p._icon(frame.args[1] or frame:getParent().args[1], false) end function p.isEqual(frame) return p._isEqual( frame.args[1] or frame:getParent().args[1], frame.args[2] or frame:getParent().args[2] ) and "yes" or "" end function p._normalizeId(category, fallback) -- Normalize if normalizable, fall back to default if not. return (category ~= nil and string.len(category) ~= 0) and string.gsub(string.lower(category), "[^%w]", "") or fallback end function p._color(category, nilIfMissing) -- This looks confusing, but it's actually nested ternaries (for nil checks) local color = p._normalizeId(category, defaultCategory) return colors[color] or ((cats[color] or ( nilIfMissing and { color = nil } or cats[defaultCategory] )).color) end function p._name(category, basin, nilIfMissing) local name_def = (cats[ p._normalizeId(category, defaultCategory) ] or (nilIfMissing and { name = nil } or cats[defaultCategory])).name return type(name_def) == "table" and ( name_def[string.lower(basin or "default")] or name_def["default"] or (not nilIfMissing and error("No default name for basin-based category name.") or nil) ) or name_def end function p._sortkey(category, nilIfMissing) -- This looks confusing, but it's actually nested ternaries (for nil checks) return (cats[ p._normalizeId(category, defaultCategory) ] or (nilIfMissing and { sortkey = nil } or cats[defaultCategory])).sortkey end function p._icon(category, nilIfMissing) -- This looks confusing, but it's actually nested ternaries (for nil checks) local icon = p._normalizeId(category, defaultCategory) return icons[icon] or (cats[icon] ~= nil and ( cats[icon].icon or cats["tropicalcyclone"].icon ) or (not nilIfMissing and cats[defaultCategory].icon) or nil) end function p._isEqual(category1, category2) -- Checks if two IDs are equal. -- An {{#ifeq}} check does not consider aliases. This function compares two -- IDs in a way that considers category aliases. This works because alias -- assignments are references to the actual table containing the category -- info found in the main category table. -- -- `false` will be returned if at least one of the categories are nil or -- if the category is not defined. local _category1 = p._normalizeId(category1) local _category2 = p._normalizeId(category2) return (_category1 == _category2 and _category1 ~= nil) or cats[ _category1 ] == cats[ _category2 ] and -- `false` if categories are undefined and not equal. cats[ _category1 ] ~= nil end function p.demo(frame) return require("Module:Storm categories/demo").demo(frame) end return p