Module:CircularVote: Difference between revisions

From OpenStreetMap Foundation
Jump to navigation Jump to search
Content deleted Content added
No edit summary
No edit summary
Line 9: Line 9:
table.sort(people)
table.sort(people)


local out = {}
local circles = {}
for _, initials in ipairs(people) do
for _, initials in ipairs(people) do
initials = mw.text.trim(initials)
initials = mw.text.trim(initials)
Line 17: Line 17:
local vote = (args[initials] or ""):lower()
local vote = (args[initials] or ""):lower()


-- Vote colors
local vote_color = ({
local vote_color = ({
yes = "green",
yes = "green",
Line 26: Line 27:
})[vote] or "gray"
})[vote] or "gray"


-- Vote symbols
local vote_symbol = ({
local vote_symbol = ({
yes = "✓",
yes = "✓",
Line 35: Line 37:
})[vote] or ""
})[vote] or ""


-- Symbol color
local symbol_color = vote_color == "yellow" and "black" or "white"
local symbol_color = (vote_color == "yellow") and "black" or "white"


table.insert(out, string.format([[
table.insert(circles, string.format([[
<div title="%s" style="position:relative; display:inline-flex; justify-content:center; align-items:center; width:4em; height:4em; border-radius:50%%; background:%s; color:white; font-weight:bold; font-size:0.75em; text-align:center; white-space:nowrap; overflow:hidden;">
<div title="%s" style="display:flex; align-items:center; justify-content:center; width:3em; height:3em; border-radius:50%%; background:%s; color:white; font-weight:bold; font-size:0.9em; position:relative; white-space:nowrap; overflow:hidden;">
%s
%s
<div style="position:absolute; bottom:0.1em; right:0.1em; width:1em; height:1em; border-radius:50%%; background:%s; border:2px solid white; display:flex; align-items:center; justify-content:center; font-size:0.75em; color:%s;">
<div style="position:absolute; bottom:0.15em; right:0.15em; width:1.1em; height:1.1em; border-radius:50%%; background:%s; border:2px solid white; display:flex; align-items:center; justify-content:center; font-size:0.75em; color:%s;">
%s
%s
</div>
</div>
Line 47: Line 50:
mw.text.encode(fullname),
mw.text.encode(fullname),
circle_color,
circle_color,
initials,
mw.text.encode(initials),
vote_color,
vote_color,
symbol_color,
symbol_color,
Line 53: Line 56:
end
end


-- Wrap all circles in a single flex container
return table.concat(out, "")
return string.format('<div style="display:flex; flex-wrap:wrap; gap:0.5em; align-items:center;">%s</div>', table.concat(circles))
end
end



Revision as of 13:53, 13 November 2025

Documentation for this module may be created at Module:CircularVote/doc

local p = {}

function p.show(frame)
    local args = frame.args
    local list = args.list or ""
    local default = args.defaultcolor or "lightgray"

    local people = mw.text.split(list, "%s*,%s*")
    table.sort(people)

    local circles = {}
    for _, initials in ipairs(people) do
        initials = mw.text.trim(initials)
        local fullname = args["name_" .. initials] or initials
        local circle_color = default

        local vote = (args[initials] or ""):lower()

        -- Vote colors
        local vote_color = ({
            yes = "green",
            no = "red",
            abstention = "yellow",
            abstain = "yellow",
            none = "gray",
            ["did not vote"] = "gray"
        })[vote] or "gray"

        -- Vote symbols
        local vote_symbol = ({
            yes = "✓",
            no = "✗",
            abstention = "–",
            abstain = "–",
            none = "",
            ["did not vote"] = ""
        })[vote] or ""

        -- Symbol color
        local symbol_color = (vote_color == "yellow") and "black" or "white"

        table.insert(circles, string.format([[
<div title="%s" style="display:flex; align-items:center; justify-content:center; width:3em; height:3em; border-radius:50%%; background:%s; color:white; font-weight:bold; font-size:0.9em; position:relative; white-space:nowrap; overflow:hidden;">
  %s
  <div style="position:absolute; bottom:0.15em; right:0.15em; width:1.1em; height:1.1em; border-radius:50%%; background:%s; border:2px solid white; display:flex; align-items:center; justify-content:center; font-size:0.75em; color:%s;">
    %s
  </div>
</div>
        ]],
        mw.text.encode(fullname),
        circle_color,
        mw.text.encode(initials),
        vote_color,
        symbol_color,
        vote_symbol))
    end

    -- Wrap all circles in a single flex container
    return string.format('<div style="display:flex; flex-wrap:wrap; gap:0.5em; align-items:center;">%s</div>', table.concat(circles))
end

return p