Module:DropsLineTest: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
No edit summary
Line 29: Line 29:
     return row
     return row
end
end
-- Test the script with your provided data
local testData = {1, 1/25, 1/99.99, 1/999.99, 1/9999999}
print(createColoredRow(testData))

Revision as of 16:54, 5 May 2024

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

-- 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
local function createColoredRow(data)
    local row = "{| class=\"wikitable\"\n"
    for _, value in ipairs(data) do
        local color = assignBackgroundColor(value)
        row = row .. "| style=\"background-color: " .. color .. ";\" | " .. value .. "\n"
    end
    row = row .. "|}"
    return row
end