模組:Progression rainbow
外观
local list = {
{'列表级内容', '#aa88ff'},
{'小作品级内容', '#ff6666'},
{'初级内容', '#ffaa66'},
{'丙级内容', '#ffff66'},
{'乙级内容', '#b2ff66'},
{'优良级内容', '#66ff66'},
{'甲级内容', '#66ffff'},
{'特色级内容', '6699ff'},
{'未评级内容', '#e2e2e2'},
}
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function core( this, total, index )
local td = mw.html.create( 'td' )
local lang = mw.getLanguage( 'zh' )
local fthis = lang:formatNum( this )
local percent = tostring( math.floor( this / total * 10000) / 100 ) .. '%'
td
:css( 'background', list[index[2]] )
:attr( 'width', percent )
:attr( 'title', list[index[1]] .. ':' .. fthis .. '(' .. percent .. ')' )
return tostring( td )
end
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
args[10] = args[10] or 100
local temp = ''
local sum = 0
for i = 1, 9 do
if not ( args == nil or args == 0 ) then
temp = temp .. core( args[i], args[10], i )
sum = sum + args[i]
end
end
if sum < args[10] then
temp = temp .. core( args[10] - sum, sum, 10 )
end
local tr = mw.html.create( 'tr' )
tr
:wikitext( temp )
local frame = mw.html.create( 'table' )
frame
:css( 'border', '1px solid grey')
:css( 'height', '10px' )
:css( 'width', '100%' )
:attr( 'cellspacing', '1' )
:wikitext( tostring( tr ) )
return tostring( frame )
end
return p