Module:Progression rainbow: Difference between revisions

Content deleted Content added
from sandbox
Override the default A-class color
 
(10 intermediate revisions by 6 users not shown)
Line 3:
 
]]
require('Module:No globalsstrict')
 
local getArgs = require('Module:Arguments').getArgs
local p = {}
 
Line 13 ⟶ 12:
end
 
local function class_percentpercent(param, total)
-- These suck for i18n because the % is forced to the right without spacing,
-- both in a required context (CSS) and unrequired (to-be-displayed text).
-- I.e., there should be a separate version of this or a function parameter
-- which takes a boolean. :(
return tostring(round(100 * param / total)) .. '%'
end
Line 24 ⟶ 22:
local remaining = total - sum
if remaining > 0 then
return tostringpercent(round(100 * remaining /, total)) .. '%'
else
return nil
Line 47 ⟶ 45:
end
 
function p.main_main(frameargs)
local args = getArgs(frame)
return p._main(args, frame)
end
 
function p._main(args, frame)
-- frame needs to be available for extensionTag and expandTemplate
 
local classes = {
Line 87 ⟶ 79:
else
for i, class in ipairs(classes) do
-- 'or class.count' to keep us safe from anil non-numeric value in args.arg
class.count = tonumber(args[i]) or class.count
sum_classes = sum_classes + class.count
Line 105 ⟶ 97:
end
local rootheight = mw.html.createarg_or_default(args, 'tableheight', nil)
local root = mw.html.create('ul')
root:addClass('progression-rainbow')
if height then
:attr('role', 'presentation')
root:css('height', height)
end
 
local current_frame = mw.getCurrentFrame()
for _, class in pairsipairs(classes) do
if class.count ~= 0 then
local percentage = class_percentpercent(class.count, total)
-- The default Start-class color is difficult to distinguish next to
root:newline() -- sprinkled through to make the HTML easier to read
-- the Stub-class color, so we pick a midpoint between Stub and C
if class.class == 'Start' then
-- I don't understand why we don't need to create a 'tr'. When
root:newline() -- sprinkled through to make the HTML easier to read
-- added deliberately, we get a <tr class='empty'></tr> hanging
root:tag('tdli')
-- out. Possibly a consequence of Remex instead of HTML Tidy
:css('background', '#ffca66')
-- or maybe mw.html is just smarter than me.
:css('color','inherit')
:tag('td')
:css('backgroundwidth', frame:expandTemplate{percentage)
:attr('title', =string.format('%s 'class/colour%s', args = {percentage, class.class }category))
} :tag('span')
:cssaddClass('widthsr-only', percentage)
:wikitext(string.format('%s %s', percentage, class.category))
:tag('span')
:done()
-- wikitext accessibly-hidden by CSS
:done()
:wikitext(string.format('%s %s', percentage, class.category))
-- The default A-class color is difficult to distinguish next to
:done()
-- the GA-class color, so we pick a midpoint between GA and FA
:done()
elseif class.class == 'A' then
root:newline() -- sprinkled through to make the HTML easier to read
root:tag('li')
:css('background', '#64e2ff')
:css('color','inherit')
:css('width', percentage)
:attr('title', string.format('%s %s', percentage, class.category))
:tag('span')
:addClass('sr-only')
:wikitext(string.format('%s remaining%s', remainingpercentage, class.category))
:done()
:done()
else
root:newline() -- sprinkled through to make the HTML easier to read
root:tag('spanli')
:css('background', current_frame:expandTemplate{
title = 'class/colour', args = { class.class }
})
:css('color','inherit')
:css('width', percentage)
:attr('title', string.format('%s %s', percentage, class.category))
:tag('span')
:addClass('sr-only')
:wikitext(string.format('%s %s', percentage, class.category))
:done()
:done()
end
end
end
Line 134 ⟶ 158:
local remaining = percent_remaining(sum_classes, total)
if remaining then
root:tag('tdli')
:addClass('remaining')
:css('width', remaining)
:attr('title', string.format('%s remaining', remaining))
:tag('span')
:tag('span')
:wikitext(string.format('%s remaining', remaining))
:doneaddClass('sr-only')
:wikitext(string.format('%s remaining', remaining))
:done()
:done()
:done()
:newline()
end
root:allDone()
return framecurrent_frame:extensionTag{
name = 'templatestyles',
name = 'templatestyles', args = { src = 'Module:Progression rainbow/styles.css'}
} .. current_frame:extensionTag{
name = 'templatestyles', args = { src = 'Screen reader-only/styles.css'}
} .. '\n' .. tostring(root)
end
 
function p._mainmain(args, frame)
local getArgs = return p._main(require('Module:Arguments').getArgs(frame))
end