Module:Progression rainbow
Appearance
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| Editing of this module by new or unregistered users is currently disabled. See the protection policy and protection log for more details. If you cannot edit this module and you wish to make a change, you can submit an edit request, discuss changes on the talk page, request unprotection, log in, or create an account. |
| 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'} }
.. '\n' .. 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')
for i = 1,8 do
if classes[i][1] ~= 0 then
root:newline()
: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:newline()
if width_remaining(sum_classes, divisor) then
root:tag('td')
:addClass('remaining')
:css('width', width_remaining(sum_classes, divisor))
:done()
:newline()
end
return root
end
return p