Module:DropsLineTest: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local | -- Define a function to assign background color based on input numerical value | ||
local function assignBackgroundColor(value) | |||
function | local color = "" | ||
if | -- Define your conditions and corresponding colors | ||
if value == 1 then | |||
elseif | color = "#afeeee" -- Light blue color | ||
elseif value == 1/25 then | |||
elseif | color = "#56e156" -- Light green color | ||
elseif value == 1/99.99 then | |||
elseif | color = "#ffed4c" -- Yellow color | ||
elseif value == 1/999.99 then | |||
elseif | color = "#ff863c" -- Orange color | ||
elseif value == 1/9999999 then | |||
color = "#ff6262" -- Red color | |||
else | else | ||
color = "#FFFFFF" -- Default color (white) | |||
end | end | ||
return color | |||
end | 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" | |||
local | |||
color = | |||
end | end | ||
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)) | |||
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))