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
 
local function assignBackgroundColor(value)
function p.determineColor(r)
    local color = ""
     if tonumber(r) <= 1 then
    -- Define your conditions and corresponding colors
         return "#afeeee"
     if value == 1 then
     elseif tonumber(r) <= 25 then
         color = "#afeeee" -- Light blue color
         return "#56e156"
     elseif value == 1/25 then
     elseif tonumber(r) <= 100 then
         color = "#56e156" -- Light green color
         return "#ffed4c"
     elseif value == 1/99.99 then
     elseif tonumber(r) <= 1000 then
         color = "#ffed4c" -- Yellow color
         return "#ff863c"
     elseif value == 1/999.99 then
     elseif tonumber(r) <= 9999999 then
         color = "#ff863c" -- Orange color
         return "#ff6262"
     elseif value == 1/9999999 then
         color = "#ff6262" -- Red color
     else
     else
         return "#ffffff"
         color = "#FFFFFF" -- Default color (white)
     end
     end
    return color
end
end


function p.determineCellStyle(r, n)
-- Define a function to create a table row with colored cells
    r = tonumber(r) or 0  -- Convert r to a number or default to 0 if nil
local function createColoredRow(data)
    mw.log("Value of r: " .. r) -- Output the value of r to the debug log
     local row = "{| class=\"wikitable\"\n"
 
     for _, value in ipairs(data) do
    -- Add other logging statements as needed
         local color = assignBackgroundColor(value)
 
         row = row .. "| style=\"background-color: " .. color .. ";\" | " .. value .. "\n"
     local color
     if n == 1 then
         color = p.determineColor(r)
    elseif tonumber(r) <= 30 then
         color = "#56e156"
    else
        color = "#afeeee"
     end
     end
     return string.format('style="background-color: %s;"', color)
     row = 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))
return p

Revision as of 16:52, 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

-- Test the script with your provided data
local testData = {1, 1/25, 1/99.99, 1/999.99, 1/9999999}
print(createColoredRow(testData))