Module:Progression rainbow
Appearance
![]() | 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 module depends on the following other modules: |
![]() | This module uses TemplateStyles: |
This module implements Template:Progression rainbow.
Usage
{{#invoke:Progression rainbow|main}}
--[[
This implements {{progression rainbow/manual}}
Next up, {{progression rainbow}} fully?
]]
require ('Module:No globals')
local getArgs = require ('Module:Arguments').getArgs
local p = {}
-- rounding to first decimal, from http://lua-users.org/wiki/SimpleRound
local function round(num)
return math.floor(num * 10 + 0.5) / 10
end
local function width_classes(param, divisor)
-- implementation of rounding to first decimal in
-- http://lua-users.org/wiki/SimpleRound
return tostring(round(100 * param / divisor)) .. '%'
end
local function width_remaining(sum, divisor)
sum = sum - divisor
if sum ~= 0 then -- find this a bit specious
return tostring(round(-100 * sum / divisor)) .. '%'
else
return nil
end
end
function p.main(frame)
local args = getArgs(frame)
local main_frame = frame
return frame:extensionTag{ name = 'templatestyles',
args = { src = 'Progression rainbow/styles.css'} }
.. tostring(p._main(args, main_frame))
-- pretty sure that this call to extensionTag should be in _main
end
-- we should implement this more accessibly,
-- like providing the values for blind people and then hiding with CSS
-- HTML <meter> could implement this? not sure
function p._main(args, main_frame)
local divisor = args['9'] or 100
local classes = {
{0, 'List'},
{0, 'Stub'},
{0, 'Start'},
{0, 'C'},
{0, 'B'},
{0, 'GA'},
{0, 'A'},
{0, 'FA'}
}
-- set the value from arguments in classes, first column
local sum_classes = 0
for i = 1, 8 do
if args[i] then
classes[i][1] = tonumber(args[i])
sum_classes = sum_classes + classes[i][1]
end
end
local root = mw.html.create('table')
root:addClass('progression-rainbow')
:attr('role', 'presentation')
:tag('tr')
:newline()
for i = 1,8 do
if classes[i][1] ~= 0 then
root:tag('td')
:css('background', main_frame:expandTemplate{
title = 'class/colour', args = { classes[i][2] }})
:css('width', width_classes(classes[i][1], divisor))
:done()
end
end
root:tag('td')
:css('width', width_remaining(sum_classes, divisor))
:newline()
return root
end
return p