Module:Hockey team color
From EverybodyWiki Bios & Wiki
| Alpha | This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
This module is currently only used by
- {{NHL team color}}
Usage
{{#invoke:Hockey team color|color}}in any variation of the color templates.
{{#invoke:Hockey team color|function_name}}As a general rule for how the module functions.
Updating team colors
See Module:Hockey team color/data.
Test table
| Team | 1 | 2 | 3 | 4 | 5 | Contrast | |
|---|---|---|---|---|---|---|---|
| 1/2 | 4/3 | ||||||
| Anaheim Ducks | 21 | 1.03 | |||||
| Arizona Coyotes | X | 8.83 | 16.45 | ||||
| Boston Bruins | X | X | 21 | ||||
| Buffalo Sabres | X | 14.94 | 1.24 | ||||
| Calgary Flames | X | 4.65 | 12.68 | ||||
| Carolina Hurricanes | X | 6.34 | 6.18 | ||||
| Chicago Blackhawks | X | X | 4.65 | ||||
| Colorado Avalanche | 10.06 | 2.77 | |||||
| Columbus Blue Jackets | X | 16.05 | 2.61 | ||||
| Dallas Stars | X | 6.22 | 8.84 | ||||
| Detroit Red Wings | X | 4.65 | 4.65 | ||||
| Edmonton Oilers | X | X | 10.52 | ||||
| Florida Panthers | X | 5.88 | 6.02 | ||||
| Los Angeles Kings | X | X | 21 | ||||
| Minnesota Wild | 5.99 | 5.18 | |||||
| Montreal Canadiens | X | X | 5.99 | ||||
| Nashville Predators | X | X | 1.73 | ||||
| New Jersey Devils | X | X | 4.65 | ||||
| New York Islanders | X | X | 7.84 | ||||
| New York Rangers | X | X | 6.66 | ||||
| Ottawa Senators | X | 4.65 | 8.83 | ||||
| Philadelphia Flyers | X | X | 2.74 | ||||
| Pittsburgh Penguins | X | X | 21 | ||||
| San Jose Sharks | X | 5.19 | 8.85 | ||||
| St. Louis Blues | X | 7.82 | 7.84 | ||||
| Tampa Bay Lightning | X | X | 10.72 | ||||
| Toronto Maple Leafs | X | 11.47 | 11.47 | ||||
| Vancouver Canucks | X | X | 10.55 | ||||
| Vegas Golden Knights | X | 10.8 | 4.62 | ||||
| Washington Capitals | X | X | 4.65 | ||||
| Winnipeg Jets | 16.54 | 2.95 | |||||
| Free agent | X | X | X | 15.31 | |||
| Retired | X | X | X | 15.31 | |||
The numeric columns are the calculated contrast ratio for the first/second and the fourth/third colors. Anything lower than 3 is very poor contrast and should be changed in the data module. For more information, see Template:Color contrast ratio.
--
-- This module implements (or will be implemented)
-- {{NHL color}}
--
local p = {}
local data_module = "Module:Hockey team color/data"
local function stripwhitespace(text)
return text:match("^%s*(.-)%s*$")
end
local function get_colors(team, unknown)
team = stripwhitespace(team or '')
unknown = unknown or {"DCDCDC", "FFFFFF", "000000", "000000"}
local use_default = {
[""] = 1,
["retired"] = 1,
["free agent"] = 1,
}
local colors = nil
if ( team and use_default[team:lower()] ) then
colors = {"DCDCDC", "FFFFFF", "DCDCDC", "000000"}
else
local all_colors = mw.loadData(data_module)
colors = all_colors[team]
if ( colors and type(colors) == 'string' ) then
colors = all_colors[colors]
end
end
return colors or unknown
end
local function team_color(team, num)
local colors = get_colors(team, nil)
num = tonumber(num:match('[1-4]') or '0')
if ( num ) then
return colors[num]
else
return ''
end
end
function p.color(frame)
local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
return team_color(args[1] or '', args[2] or '')
end
return p
