Module:DropsLineTest: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
No edit summary
Line 31: Line 31:
     for _, value in ipairs(data) do
     for _, value in ipairs(data) do
         local color = assignBackgroundColor(tonumber(value))
         local color = assignBackgroundColor(tonumber(value))
         row = row .. "| style=\"background-color: " .. color .. ";\" | " .. value .. "\n"
         row = row .. "" .. color .. ";\" | " .. value .. "\n"
     end
     end
     return row
     return row

Revision as of 17:03, 5 May 2024

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

local p = {}

-- Define a function to assign background color based on input numerical value
local function assignBackgroundColor(value)
    local color = ""
    -- Define your conditions and corresponding colors
    if value == 1 then
        color = "#afeeee" -- Light blue color
    elseif value == 1/25 then
        color = "#56e156" -- Light green color
    elseif value == 1/99.99 then
        color = "#ffed4c" -- Yellow color
    elseif value == 1/999.99 then
        color = "#ff863c" -- Orange color
    elseif value == 1/9999999 then
        color = "#ff6262" -- Red color
    else
        color = "#FFFFFF" -- Default color (white)
    end
    return color
end

-- Define a function to create a table row with colored cells
function p.createColoredRow(frame)
    local args = frame.args
    local data = {}
    for k, v in pairs(args) do
        table.insert(data, v)
    end
    local row = ""
    for _, value in ipairs(data) do
        local color = assignBackgroundColor(tonumber(value))
        row = row .. "" .. color .. ";\" | " .. value .. "\n"
    end
    return row
end

return p