Module:Storm categories
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | 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 approximately 5,600 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. 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: {{storm colour}}, {{storm name}}, and {{storm icon}}. It acts as a centralized location for storm categories to avoid discrepancies between templates, allowing for the same ID to be used across all related templates.
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>
|
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) | Severe tropical storm |
{{#invoke:Storm categories|name|spr - cYcL -s TorM}}
|
sprcyclstorm | (default) | Super cyclonic storm |
{{#invoke:Storm categories|name|cat5}}
|
cat5 | (default) | Category 5-equivalent tropical cyclone |
{{#invoke:Storm categories|name|cat5|ATl}}
|
cat5 | ATl | Category 5 hurricane |
{{#invoke:Storm categories|name|cat5|WPac}}
|
cat5 | WPac | Category 5-equivalent super typhoon |
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 {{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 | 80,006 | {{#invoke:Storm categories|sortkey|cat3}}
|
cat1 | 80,002 | {{#invoke:Storm categories|sortkey|cat1}}
|
cat5 | 80,020 | {{#invoke:Storm categories|sortkey|cat5}}
|
cat4 | 80,008 | {{#invoke:Storm categories|sortkey|cat4}}
|
depression | 90 | {{#invoke:Storm categories|sortkey|depression}}
|
cat2 | 80,004 | {{#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).
ID | Name | Color | Sortkey | |||
---|---|---|---|---|---|---|
Basin | Name | Basin | Sortkey | |||
cat2 | default | Category 2-equivalent tropical cyclone | #ffe775 | Atl/EPac/SAtl | 80004 | |
atl | Category 2 hurricane | |||||
epac | Category 2 hurricane | |||||
wpac | Category 2-equivalent typhoon | |||||
satl | Category 2 hurricane | |||||
storm | Tropical storm | #00faf4 | Global | 100 | ||
shem5 | Severe tropical cyclone | #ff6060 | Historical | 20010 | ||
moddepression | Moderate tropical depression | #5ebaff | Global | 95 | ||
severe | Severe tropical storm | #ccffff | Global | 120 | ||
severets | Severe tropical storm | #ccffff | Global | 120 | ||
ss | Subtropical storm | #00faf4 | Global | 65 | ||
sty | Category 4 super typhoon | #ff6060 | Atl/EPac/SAtl | 80015 | ||
cat4 | default | Category 4-equivalent tropical cyclone | #ff8f20 | Atl/EPac/SAtl | 80008 | |
atl | Category 4 hurricane | |||||
epac | Category 4 hurricane | |||||
wpac | Category 4-equivalent typhoon | |||||
satl | Category 4 hurricane | |||||
aus2 | Category 2 tropical cyclone | #ccffff | Aus/Fiji | 40008 | ||
fiji5 | Category 5 severe tropical cyclone | #ff6060 | Aus/Fiji | 40015 | ||
low | Tropical low | #5ebaff | Aus/Fiji | 40002 | ||
swiodisturbance | Tropical disturbance | #80ccff | Global | 80 | ||
posttropical | Post-tropical depression | #cccccc | Global | 70 | ||
tc | Tropical cyclone | #ffffcc | SWIO | 30006 | ||
cs | Cyclonic storm | #00faf4 | NIO | 50006 | ||
supertyphoon | Category 4 super typhoon | #ff6060 | Atl/EPac/SAtl | 80015 | ||
subtropical | Subtropical storm | #00faf4 | Global | 65 | ||
vsvrcyclstorm | Very severe cyclonic storm | #ffffcc | NIO | 50010 | ||
potentialtropicalcyclone | Potential tropical cyclone | #80ccff | Global | 25 | ||
aus5 | Category 5 severe tropical cyclone | #ff6060 | Aus/Fiji | 40015 | ||
nioland | Land depression | #80ccff | NIO | 50000 | ||
potential | Potential tropical cyclone | #80ccff | Global | 25 | ||
landdepression | Land depression | #80ccff | NIO | 50000 | ||
vitc | Very intense tropical cyclone | #ff6060 | SWIO | 30010 | ||
esvrcyclstorm | Extremely severe cyclonic storm | #ffc140 | NIO | 50015 | ||
niocyclone | Cyclonic storm | #00faf4 | NIO | 50006 | ||
remnant | Post-tropical depression | #cccccc | Global | 70 | ||
fiji4 | Category 4 severe tropical cyclone | #ffc140 | Aus/Fiji | 40013 | ||
sucs | Super cyclonic storm | #ff6060 | NIO | 50020 | ||
subtropicalcyclone | Subtropical cyclone | #00faf4 | Global | 70 | ||
spdepression | Tropical depression | #5ebaff | Global | 90 | ||
aus4 | Category 4 severe tropical cyclone | #ffc140 | Aus/Fiji | 40013 | ||
ty | Typhoon | #fdaf9a | WPAC | 60010 | ||
fiji3 | Category 3 severe tropical cyclone | #ffffcc | Aus/Fiji | 40010 | ||
cat5 | default | Category 5-equivalent tropical cyclone | #ff6060 | Atl/EPac/SAtl | 80020 | |
atl | Category 5 hurricane | |||||
epac | Category 5 hurricane | |||||
wpac | Category 5-equivalent super typhoon | |||||
satl | Category 5 hurricane | |||||
shdepression | Tropical depression | #5ebaff | Global | 90 | ||
shem3 | Tropical cyclone | #ffffcc | SWIO | 30006 | ||
sub | Moderate tropical storm | #00faf4 | SWIO | 30004 | ||
disturbance | Tropical disturbance | #80ccff | Global | 80 | ||
mts | Moderate tropical storm | #00faf4 | SWIO | 30004 | ||
di | Tropical disturbance | #80ccff | Global | 80 | ||
strong | Severe tropical storm | #ccffff | Global | 120 | ||
tl | Tropical low | #5ebaff | Aus/Fiji | 40002 | ||
fiji1 | Category 1 tropical cyclone | #00faf4 | Aus/Fiji | 40006 | ||
subdisturbance | Subtropical disturbance | #80ccff | Global | 55 | ||
fiji2 | Category 2 tropical cyclone | #ccffff | Aus/Fiji | 40008 | ||
ld | Land depression | #80ccff | NIO | 50000 | ||
shemdepression | Tropical depression | #5ebaff | Global | 90 | ||
shemtc | Tropical cyclone | #ffffcc | SWIO | 30006 | ||
land | Land depression | #80ccff | NIO | 50000 | ||
dd | Deep depression | #5ebaff | NIO | 50002 | ||
styphoon | Supertyphoon | #ff6060 | WPAC | 60050 | ||
nwpsevere | Severe tropical storm | #ccffff | Global | 120 | ||
swiodepression | Tropical depression | #5ebaff | Global | 90 | ||
depression | Tropical depression | #5ebaff | Global | 90 | ||
vintense | Very intense tropical cyclone | #ff6060 | SWIO | 30010 | ||
scs | Severe cyclonic storm | #ccffff | NIO | 50008 | ||
shem4 | Tropical cyclone | #ffc140 | Historical | 20008 | ||
escs | Extremely severe cyclonic storm | #ffc140 | NIO | 50015 | ||
swiotc | Tropical cyclone | #ffffcc | SWIO | 30006 | ||
shem1 | Tropical cyclone | #00faf4 | Historical | 20008 | ||
sprcyclstorm | Super cyclonic storm | #ff6060 | NIO | 50020 | ||
post | Post-tropical depression | #cccccc | Global | 70 | ||
typhoon | Typhoon | #fdaf9a | WPAC | 60010 | ||
niodepression | Depression | #80ccff | NIO | 50001 | ||
subdepression | Subtropical depression | #5ebaff | Global | 60 | ||
intense | Intense tropical cyclone | #ffc140 | SWIO | 30008 | ||
aus1 | Category 1 tropical cyclone | #00faf4 | Aus/Fiji | 40006 | ||
nwpstorm | Tropical storm | #00faf4 | Global | 100 | ||
sts | Severe tropical storm | #ccffff | Global | 120 | ||
et | Extratropical cyclone | #cccccc | Global | 50 | ||
monsoondepression | Monsoon depression | #5ebaff | Global | 30 | ||
swsubdep | Subtropical depression | #5ebaff | Global | 60 | ||
sublow | Subtropical low | #5ebaff | Aus/Fiji | 40000 | ||
nwpdepression | Tropical depression | #5ebaff | Global | 90 | ||
mstorm | Moderate tropical storm | #00faf4 | SWIO | 30004 | ||
cyclstorm | Cyclonic storm | #00faf4 | NIO | 50006 | ||
itc | Intense tropical cyclone | #ffc140 | SWIO | 30008 | ||
d | Tropical depression | #5ebaff | Global | 90 | ||
svrcyclstorm | Severe cyclonic storm | #ccffff | NIO | 50008 | ||
zodw | Zone of disturbed weather | #80ccff | SWIO | 30000 | ||
deepdepression | Deep depression | #5ebaff | NIO | 50002 | ||
pt | Potential tropical cyclone | #80ccff | Global | 25 | ||
vstyphoon | Very strong typhoon | #fe887d | WPAC | 60020 | ||
td | Tropical depression | #5ebaff | Global | 90 | ||
swiosts | Severe tropical storm | #ccffff | Global | 120 | ||
cat1 | default | Category 1-equivalent tropical cyclone | #ffffcc | Atl/EPac/SAtl | 80002 | |
atl | Category 1 hurricane | |||||
epac | Category 1 hurricane | |||||
wpac | Category 1-equivalent typhoon | |||||
satl | Category 1 hurricane | |||||
md | Monsoon depression | #5ebaff | Global | 30 | ||
ts | Tropical storm | #00faf4 | Global | 100 | ||
shemsvrtc | Severe tropical cyclone | #ffe775 | Historical | 20020 | ||
rl | Post-tropical depression | #cccccc | Global | 70 | ||
shem2 | Tropical cyclone | #ccffff | Historical | 20008 | ||
cat3 | default | Category 3-equivalent tropical cyclone | #ffc140 | Atl/EPac/SAtl | 80006 | |
atl | Category 3 hurricane | |||||
epac | Category 3 hurricane | |||||
wpac | Category 3-equivalent typhoon | |||||
satl | Category 3 hurricane | |||||
mtstorm | Moderate tropical storm | #00faf4 | Global | 105 | ||
vscs | Very severe cyclonic storm | #ffffcc | NIO | 50010 | ||
extratropical | Extratropical cyclone | #cccccc | Global | 50 | ||
tropicalcyclone | Tropical cyclone | #ffffcc | SWIO | 30006 | ||
sd | Subtropical depression | #5ebaff | Global | 60 | ||
aus3 | Category 3 severe tropical cyclone | #ffffcc | Aus/Fiji | 40010 | ||
vityphoon | Violent typhoon | #ff6060 | WPAC | 60030 | ||
unknown | Unknown strength tropical cyclone | #c0c0c0 | Global | 0 | ||
severedep | Severe tropical depression | #5ebaff | Global | 120 | ||
remnantlow | Post-tropical depression | #cccccc | Global | 70 |
local p = {}
-- Define categories
-- All sortkeys have been guessed. They may be changed by common sense
-- or consensus at [[Wikipedia talk:WikiProject Tropical cyclones]]
local cats = {
severe = {
color = "ccffff",
name = "Severe tropical storm",
sortkey = 120
},
mtstorm = {
color = "00faf4", -- {{storm colour}} did not support. Value guessed.
name = "Moderate tropical storm",
sortkey = 105
},
storm = {
color = "00faf4",
name = "Tropical storm",
sortkey = 100
},
severedep = {
color = "5ebaff", -- {{storm colour}} did not support. Value guessed.
name = "Severe tropical depression",
sortkey = 120
},
moddepression = {
color = "5ebaff", -- {{storm colour}} did not support. Value guessed.
name = "Moderate tropical depression",
sortkey = 95
},
depression = {
color = "5ebaff",
name = "Tropical depression",
sortkey = 90
},
disturbance = {
color = "80ccff",
name = "Tropical disturbance",
sortkey = 80
},
subtropicalcyclone = {
color = "00faf4",
name = "Subtropical cyclone",
sortkey = 70
},
subtropical = {
color = "00faf4",
name = "Subtropical storm",
sortkey = 65
},
subdepression = {
color = "5ebaff",
name = "Subtropical depression",
sortkey = 60
},
subdisturbance = {
color = "80ccff",
name = "Subtropical disturbance",
sortkey = 55
},
extratropical = {
color = "cccccc",
name = "Extratropical cyclone",
sortkey = 50
},
monsoondepression = {
color = "5ebaff",
name = "Monsoon depression",
sortkey = 30
},
potential = {
color = "80ccff",
name = "Potential tropical cyclone",
sortkey = 25
},
posttropical = {
color = "cccccc",
name = "Post-tropical depression",
sortkey = 70
},
remnant = {
color = "cccccc",
name = "Post-tropical depression",
sortkey = 70
},
unknown = {
color = "c0c0c0",
name = "Unknown strength tropical cyclone",
sortkey = 0
},
cat5 = {
color = "ff6060",
name = {
atl = "Category 5 hurricane",
epac = "Category 5 hurricane",
satl = "Category 5 hurricane",
wpac = "Category 5-equivalent super typhoon",
default = "Category 5-equivalent tropical cyclone"
},
sortkey = 80020
},
cat4 = {
color = "ff8f20",
name = {
atl = "Category 4 hurricane",
epac = "Category 4 hurricane",
satl = "Category 4 hurricane",
wpac = "Category 4-equivalent typhoon",
default = "Category 4-equivalent tropical cyclone"
},
sortkey = 80008
},
cat3 = {
color = "ffc140",
name = {
atl = "Category 3 hurricane",
epac = "Category 3 hurricane",
satl = "Category 3 hurricane",
wpac = "Category 3-equivalent typhoon",
default = "Category 3-equivalent tropical cyclone"
},
sortkey = 80006
},
cat2 = {
color = "ffe775",
name = {
atl = "Category 2 hurricane",
epac = "Category 2 hurricane",
satl = "Category 2 hurricane",
wpac = "Category 2-equivalent typhoon",
default = "Category 2-equivalent tropical cyclone"
},
sortkey = 80004
},
cat1 = {
color = "ffffcc",
name = {
atl = "Category 1 hurricane",
epac = "Category 1 hurricane",
satl = "Category 1 hurricane",
wpac = "Category 1-equivalent typhoon",
default = "Category 1-equivalent tropical cyclone"
},
sortkey = 80002
},
supertyphoon = {
color = "ff6060",
name = "Category 4 super typhoon",
sortkey = 80015
},
typhoon = {
color = "fdaf9a",
name = "Typhoon",
sortkey = 60010
},
vstyphoon = {
color = "fe887d",
name = "Very strong typhoon",
sortkey = 60020
},
vityphoon = {
color = "ff6060",
name = "Violent typhoon",
sortkey = 60030
},
-- PAGASA
styphoon = {
color = "ff6060",
name = "Supertyphoon",
sortkey = 60050
},
sprcyclstorm = {
color = "ff6060",
name = "Super cyclonic storm",
sortkey = 50020
},
esvrcyclstorm = {
color = "ffc140",
name = "Extremely severe cyclonic storm",
sortkey = 50015
},
vsvrcyclstorm = {
color = "ffffcc",
name = "Very severe cyclonic storm",
sortkey = 50010
},
svrcyclstorm = {
color = "ccffff",
name = "Severe cyclonic storm",
sortkey = 50008
},
niocyclone = {
color = "00faf4",
name = "Cyclonic storm",
sortkey = 50006
},
deepdepression = {
color = "5ebaff",
name = "Deep depression",
sortkey = 50002
},
niodepression = {
color = "80ccff",
name = "Depression",
sortkey = 50001
},
nioland = {
color = "80ccff",
name = "Land depression",
sortkey = 50000
},
aus5 = {
color = "ff6060",
name = "Category 5 severe tropical cyclone",
sortkey = 40015
},
aus4 = {
color = "ffc140",
name = "Category 4 severe tropical cyclone",
sortkey = 40013
},
aus3 = {
color = "ffffcc",
name = "Category 3 severe tropical cyclone",
sortkey = 40010
},
aus2 = {
color = "ccffff",
name = "Category 2 tropical cyclone",
sortkey = 40008
},
aus1 = {
color = "00faf4",
name = "Category 1 tropical cyclone",
sortkey = 40006
},
low = {
color = "5ebaff",
name = "Tropical low",
sortkey = 40002
},
sublow = {
color = "5ebaff",
name = "Subtropical low",
sortkey = 40000
},
vintense = {
color = "ff6060",
name = "Very intense tropical cyclone",
sortkey = 30010
},
intense = {
color = "ffc140",
name = "Intense tropical cyclone",
sortkey = 30008
},
tropicalcyclone = {
color = "ffffcc",
name = "Tropical cyclone",
sortkey = 30006
},
mstorm = {
color = "00faf4",
name = "Moderate tropical storm",
sortkey = 30004
},
zodw = {
color = "80ccff",
name = "Zone of disturbed weather",
sortkey = 30000
},
shemsvrtc = {
color = "ffe775",
name = "Severe tropical cyclone",
sortkey = 20020
},
shem5 = {
color = "ff6060",
name = "Severe tropical cyclone",
sortkey = 20010
},
shem4 = {
color = "ffc140",
name = "Tropical cyclone",
sortkey = 20008
},
shem2 = {
color = "ccffff",
name = "Tropical cyclone",
sortkey = 20008
},
shem1 = {
color = "00faf4",
name = "Tropical cyclone",
sortkey = 20008
}
}
-- Default
local defaultCategory = "unknown"
-- Define aliases
-- All non-alphanumeric characters are already stripped, and the string is
-- already set to lowercase, so additional aliases for those are no longer
-- required.
cats["sty"] = cats["supertyphoon"]
cats["nwpsevere"] = cats["severe"]
cats["strong"] = cats["severe"]
cats["swiosts"] = cats["severe"]
cats["sts"] = cats["severe"]
cats["severets"] = cats["severe"]
cats["ty"] = cats["typhoon"]
cats["td"] = cats["depression"]
cats["ts"] = cats["storm"]
cats["nwpstorm"] = cats["storm"]
cats["d"] = cats["depression"]
cats["spdepression"] = cats["depression"]
cats["shdepression"] = cats["depression"]
cats["shemdepression"] = cats["depression"]
cats["swiodepression"] = cats["depression"]
cats["spdepression"] = cats["depression"]
cats["nwpdepression"] = cats["depression"]
cats["swsubdep"] = cats["subdepression"]
cats["sd"] = cats["subdepression"]
cats["ss"] = cats["subtropical"]
cats["et"] = cats["extratropical"]
cats["md"] = cats["monsoondepression"]
cats["pt"] = cats["potential"]
cats["potentialtropicalcyclone"] = cats["potential"]
cats["potentialtropicalcyclone"] = cats["potential"]
cats["post"] = cats["remnant"]
cats["remnantlow"] = cats["remnant"]
cats["rl"] = cats["remnant"]
cats["sucs"] = cats["sprcyclstorm"]
cats["escs"] = cats["esvrcyclstorm"]
cats["vscs"] = cats["vsvrcyclstorm"]
cats["scs"] = cats["svrcyclstorm"]
cats["cs"] = cats["niocyclone"]
cats["dd"] = cats["deepdepression"]
cats["cyclstorm"] = cats["niocyclone"]
cats["landdepression"] = cats["nioland"]
cats["land"] = cats["nioland"]
cats["ld"] = cats["nioland"]
cats["fiji5"] = cats["aus5"]
cats["fiji4"] = cats["aus4"]
cats["fiji3"] = cats["aus3"]
cats["fiji2"] = cats["aus2"]
cats["fiji1"] = cats["aus1"]
cats["tl"] = cats["low"]
cats["di"] = cats["disturbance"]
cats["swiodisturbance"] = cats["disturbance"]
cats["mts"] = cats["mstorm"]
cats["sub"] = cats["mstorm"]
cats["vitc"] = cats["vintense"]
cats["itc"] = cats["intense"]
cats["tc"] = cats["tropicalcyclone"]
cats["swiotc"] = cats["tropicalcyclone"]
cats["shem3"] = cats["tropicalcyclone"]
cats["shemtc"] = cats["tropicalcyclone"]
-- Ambiguous color names. This is because {[storm colour}} itself is extremely
-- ambiguous. This is also used to override the output of some codes.
local colors = {
-- Basin colors
["5"] = cats["cat5"].color,
["4"] = cats["cat4"].color,
["3"] = cats["cat3"].color,
["2"] = cats["cat2"].color,
["1"] = cats["cat1"].color,
-- Enhanced Fujita scale
["ef5"] = cats["cat5"].color,
["ef4"] = cats["cat4"].color,
["ef3"] = cats["cat3"].color,
["ef2"] = cats["cat2"].color,
["ef1"] = cats["cat1"].color,
["ef0"] = cats["ts"].color,
-- Depression
["d"] = "80ccff",
-- FMS scale
["a5"] = cats["aus5"].color,
["a4"] = cats["aus4"].color,
["a3"] = cats["aus3"].color,
["a2"] = cats["aus2"].color,
["a1"] = cats["aus1"].color
}
function p.color(frame)
return p._color(frame.args[1] or frame:getParent().args[1])
end
function p.name(frame)
return p._name(
frame.args[1] or frame:getParent().args[1],
frame.args[2] or frame:getParent().args[2]
)
end
function p.sortkey(frame)
return p._sortkey(frame.args[1] or frame:getParent().args[1])
end
function p._color(colorCode)
-- This looks confusing, but it's actually nested ternaries (for nil checks)
local color = (colorCode ~= nil and string.len(colorCode) ~= 0) and
string.gsub(string.lower(colorCode), "[^%w]", "")
or defaultCategory;
return colors[color] or ((cats[color] or cats[defaultCategory]).color)
end
function p._name(category, basin)
local name_def = (cats[
(category ~= nil and string.len(category) ~= 0) and
string.gsub(string.lower(category), "[^%w]", "")
or defaultCategory
] or cats[defaultCategory]).name
return type(name_def) == "table" and
(
name_def[string.lower(basin or "default")]
or name_def["default"]
or error("No default name for basin-based category name.")
)
or name_def
end
function p._sortkey(category)
-- This looks confusing, but it's actually nested ternaries (for nil checks)
return (cats[
(category ~= nil and string.len(category) ~= 0) and
string.gsub(string.lower(category), "[^%w]", "")
or defaultCategory
] or cats[defaultCategory]).sortkey
end
function count(_table)
local n = 0
for _ in pairs(_table) do
n = n + 1
end
return n
end
function p.demo(frame)
local out = mw.html.create("table")
:addClass("wikitable")
:addClass("sortable")
:attr("style", "width: 100%")
out:node(
mw.html.create("tr")
:node(mw.html.create("th"):wikitext("ID")
:attr("rowspan", "2"))
:node(mw.html.create("th"):wikitext("Name")
:attr("colspan", "2"))
:node(mw.html.create("th"):wikitext("Color")
:attr("rowspan", "2")
:attr("colspan", "2"))
:node(mw.html.create("th"):wikitext("Sortkey")
:attr("colspan", "2"))
):node(
mw.html.create("tr")
:node(mw.html.create("th"):wikitext("Basin"))
:node(mw.html.create("th"):wikitext("Name"))
:node(mw.html.create("th"):wikitext("Basin"))
:node(mw.html.create("th"):wikitext("Sortkey")
:attr("data-sort-type", "number"))
)
for name, cat in pairs(cats) do
local rows = { mw.html.create("tr") }
local row = rows[1]
local id = mw.html.create("td")
:wikitext(name)
local colorPreview = mw.html.create("td")
:attr("style", "background-color: #" .. cat["color"] .. "; padding: 0; width: 1.8em")
local color = mw.html.create("td")
:wikitext("#" .. cat["color"])
local sortkeyCategory = mw.html.create("td")
:attr("data-sort-value", cat["sortkey"])
local sortkey = mw.html.create("td")
:attr("data-sort-value", cat["sortkey"])
:wikitext(cat["sortkey"])
if cat["sortkey"] < 0 then
sortkeyCategory:wikitext("Invalid")
elseif cat["sortkey"] < 20000 then
sortkeyCategory:wikitext("Global")
elseif cat["sortkey"] < 30000 then
sortkeyCategory:wikitext("Historical")
elseif cat["sortkey"] < 40000 then
sortkeyCategory:wikitext("SWIO")
elseif cat["sortkey"] < 50000 then
sortkeyCategory:wikitext("Aus/Fiji")
elseif cat["sortkey"] < 60000 then
sortkeyCategory:wikitext("NIO")
elseif cat["sortkey"] < 80000 then
sortkeyCategory:wikitext("WPAC")
elseif cat["sortkey"] < 90000 then
sortkeyCategory:wikitext("Atl/EPac/SAtl")
elseif cat["sortkey"] < 100000 then
sortkeyCategory:attr("style", "color: gray")
sortkeyCategory:wikitext("''Global''")
else
sortkeyCategory:wikitext("Invalid")
end
if type(cat["name"]) == "string" then
local name = mw.html.create("td")
:attr("colspan", "2")
:wikitext(cat["name"])
row:node(id)
row:node(name)
else
local nameTableLength = count(cat["name"])
id:attr("rowspan", nameTableLength)
colorPreview:attr("rowspan", nameTableLength)
color:attr("rowspan", nameTableLength)
sortkeyCategory:attr("rowspan", nameTableLength)
sortkey:attr("rowspan", nameTableLength)
row:node(id)
local firstDone = false
for key, basinName in pairs(cat["name"]) do
if firstDone then
local nameRow = mw.html.create("tr")
nameRow
:node(mw.html.create("td"):wikitext(key))
:node(mw.html.create("td"):wikitext(basinName))
table.insert(rows, nameRow)
else
firstDone = true
row
:node(mw.html.create("td"):wikitext(key))
:node(mw.html.create("td"):wikitext(basinName))
end
end
end
row:node(colorPreview)
row:node(color)
row:node(sortkeyCategory)
row:node(sortkey)
for _, _row in pairs(rows) do
out:node(_row)
end
end
return tostring(out)
end
p.cats = cats
return p