Module:Progression rainbow: Difference between revisions

Content deleted Content added
clean
Override the default A-class color
 
(8 intermediate revisions by 6 users not shown)
Line 3:
 
]]
require('Module:No globalsstrict')
 
local p = {}
Line 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 23 ⟶ 22:
local remaining = total - sum
if remaining > 0 then
return tostringpercent(round(100 * remaining /, total)) .. '%'
else
return nil
Line 44 ⟶ 43:
return default
end
end
 
function p.main(frame)
return p._main(require('Module:Arguments').getArgs(frame))
end
 
Line 84 ⟶ 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 101 ⟶ 96:
total = tonumber(args[9]) or 100
end
local height = arg_or_default(args, 'height', nil)
local root = mw.html.create('ul')
root:addClass('progression-rainbow')
if height then
root:css('height', height)
end
 
-- Don't care which frame it is if all I want to do is expand templates
-- and extension tags
local current_frame = mw.getCurrentFrame()
for _, class in ipairs(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
-- the Stub-class color, so we pick a midpoint between Stub and C
if class.class == 'Start' then
root:newline() -- sprinkled through to make the HTML easier to read
root:tag('li')
:css('background', current_frame:expandTemplate{'#ffca66')
:css('color','inherit')
title = 'class/colour', args = { class.class }
:css('width', percentage)
})
:cssattr('widthtitle', string.format('%s %s', percentage, class.category))
:tag('span')
:addClass('sr-only')
:wikitext(string.format('%s %s', percentage, class.category))
:done()
:done()
-- The default A-class color is difficult to distinguish next to
-- the GA-class color, so we pick a midpoint between GA and FA
elseif class.class == 'A' then
root:newline() -- sprinkled through to make the HTML easier to read
root:tag('spanli')
: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 %s', percentage, class.category))
:done()
:done()
else
root:newline() -- sprinkled through to make the HTML easier to read
root:tag('li')
: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 129 ⟶ 159:
if remaining then
root:tag('li')
:addClass('remaining')
:css('width', remaining)
:attr('title', string.format('%s remaining', remaining))
:tag('span')
:addClasstag('sr-onlyspan')
:addClass('sr-only')
:wikitext(string.format('%s remaining', remaining))
:done()
:done()
:newline()
end
Line 144 ⟶ 175:
name = 'templatestyles', args = { src = 'Screen reader-only/styles.css'}
} .. '\n' .. tostring(root)
end
 
function p.main(frame)
return p._main(require('Module:Arguments').getArgs(frame))
end