Khác biệt giữa bản sửa đổi của “Mô đun:Sandbox/Ioe2015/voteCount”

Nội dung được xóa Nội dung được thêm vào
Không có tóm lược sửa đổi
Không có tóm lược sửa đổi
Dòng 1:
local getArgs = require('Module:Arguments').getArgs
local TableTools = require('Module:TableTools')
local ColorContract = require("Module:Color contrast")
 
local p = {} -- Defines a variable p as an empty table, but *not* nil.
Hàng 205 ⟶ 206:
 
function p.getCountTable(templates)
function incTableVal(t, key)
local ret = {
if t[key] ~= nil then
total = 0,
keep t[key] = 0,t[key] + 1
else
delete = 0,
agree t[key] = 0,1
end
disagree = 0,
}end
local ret = {}
for _, template in pairs(templates) do
if p.isKeepVote(template) then
incTableVal(ret.keep, = ret."keep + 1")
elseif p.isDeleteVote(template) then
incTableVal(ret.delete, = ret."delete + 1")
elseif p.isAgreeVote(template) then
incTableVal(ret.agree, = ret."agree + 1")
elseif p.isDisagreeVote(template) then
incTableVal(ret.disagree, = ret."disagree + 1")
end
end
local total = 0,
ret.total = ret.keep + ret.delete + ret.agree + ret.disagree
for k, v in pairs(countsret) do
return ret
itotal = itotal + 1v
end
return ret, total
end
 
Hàng 238 ⟶ 244:
 
function p._display(args)
local container = mw.html.create("div"):css({
float = "right",
["text-align"] = "center",
width = "70px",
height = "20px",
})
 
local templates = p.getVotingTemplates(p.getPage(args[1]))
local counts = p--mw.getCountTablelog(tprint(templates))
local counts, total = countsp.totalgetCountTable(templates)
 
local containerlen = mwTableTools.html.createsize("div"counts)
local icolorMap = 0{
keep = "blue",
local newCounts = {}
delete = 0"orange",
for k, v in pairs(counts) do
agree = "green",
if v ~= 0 and k ~= "total" then
newCounts[v]disagree = k"red",
}
end
end
counts = newCounts
local i = 0
--for count, type in TableTools.sparseIpairs(counts) do
for counttype, typecount in pairs(counts) do
container:tag("span"):css({
i = i + 1
if i float == 1 then"left",
width = mw.ustring.format("%.2f%%", count / total * 100),
mw.log("first")
height = "100%",
else
["background-color"] = colorMap[type],
mw.log(count)
color = ColorContract._greatercontrast(
end
{colorMap[type], "white", "black"}
)
}):wikitext(count):done()
end
 
return tprinttostring(countscontainer:allDone())
end