Module:DropsLineTest: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
local p = {}
-- Define a function to assign background color based on input numerical value
-- Define a function to assign background color based on input numerical value
local function assignBackgroundColor(value)
local function assignBackgroundColor(value)
Line 20: Line 22:


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

Revision as of 16:58, 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 .. "| style=\"background-color: " .. color .. ";\" | " .. value .. "\n"
    end
    return row
end

return p