Module:BrewerColors and Module:BrewerColors/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
require('strict') |
No edit summary |
||
Line 1: | Line 1: | ||
require('strict') |
|||
local p = {} |
local p = {} |
||
local CFCM = require "Module:ComplForColorModules" |
local CFCM = require "Module:ComplForColorModules/sandbox" |
||
local TNTT = require "Module:TNTTools" |
local TNTT = require "Module:TNTTools" |
||
local ARG = require "Module:Arguments" |
local ARG = require "Module:Arguments" |
||
Line 15: | Line 14: | ||
local RS_ColorNameInvalid = 'ColorNameInvalid' |
local RS_ColorNameInvalid = 'ColorNameInvalid' |
||
local function I18nStr(S, ...) |
local function I18nStr (S, ...) |
||
return TNTT.GetMsgP(I18n, S, {...}) |
return TNTT.GetMsgP (I18n, S, {...}) |
||
end |
end |
||
Line 358: | Line 357: | ||
function p.GetColors(ColorName, IsInv, N, CallError) |
function p.GetColors(ColorName, IsInv, N, CallError) |
||
local ColorFound = {} |
local ColorFound = {} |
||
function GetC(ColorSet) |
|||
if (N < 3) or (N > (table.getn(ColorSet)+2)) then |
if (N < 3) or (N > (table.getn(ColorSet)+2)) then |
||
if CallError then |
if CallError then |
||
error(I18nStr(RS_ColorNumInvalid,tostring(N)), 0) |
error (I18nStr(RS_ColorNumInvalid,tostring(N)), 0) |
||
end |
end |
||
elseif IsInv then |
elseif IsInv then |
||
for i |
for i=table.getn(ColorSet[N-2]), 1, -1 do |
||
table.insert(ColorFound, '#'..ColorSet[N-2][i]) |
table.insert (ColorFound, '#'..ColorSet[N-2][i]) |
||
end |
end |
||
else |
else |
||
for i |
for i=1, table.getn(ColorSet[N-2]) do |
||
table.insert(ColorFound, '#'..ColorSet[N-2][i]) |
table.insert (ColorFound, '#'..ColorSet[N-2][i]) |
||
end |
end |
||
end |
end |
||
end |
end |
||
local ColorNameL = string.lower(ColorName) |
local ColorNameL = string.lower (ColorName) |
||
if ColorNameL == 'ylgn' then GetC(ColorYlGn) |
if ColorNameL == 'ylgn' then GetC(ColorYlGn) |
||
elseif ColorNameL == 'ylgnbu' then GetC(ColorYlGnBu) |
elseif ColorNameL == 'ylgnbu' then GetC(ColorYlGnBu) |
||
Line 409: | Line 408: | ||
elseif ColorNameL == 'set2' then GetC(ColorSet2) |
elseif ColorNameL == 'set2' then GetC(ColorSet2) |
||
elseif ColorNameL == 'set3' then GetC(ColorSet3) |
elseif ColorNameL == 'set3' then GetC(ColorSet3) |
||
else |
|||
if CallError then |
|||
error(I18nStr(RS_ColorNameInvalid,ColorName), 0) |
error (I18nStr (RS_ColorNameInvalid,ColorName), 0) |
||
end |
|||
end |
end |
||
return ColorFound |
return ColorFound |
||
Line 419: | Line 420: | ||
removeBlanks = false |
removeBlanks = false |
||
}) |
}) |
||
local ColorName, IsInv = CFCM.ColorNameInv(args) |
local ColorName, IsInv = CFCM.ColorNameInv (args) |
||
local N = tonumber(args[2]) |
local N = tonumber(args[2]) |
||
local WriteColor = args[3] or '' |
local WriteColor = args[3] or '' |
||
local ColorFound = {} |
local ColorFound = {} |
||
ColorFound = p.GetColors(ColorName, IsInv, N, true) |
ColorFound = p.GetColors (ColorName, IsInv, N, true) |
||
local boxes = {} |
local boxes = {} |
||
for i |
for i=1, table.getn(ColorFound) do |
||
table.insert(boxes, CFCM.Box(ColorFound[i],WriteColor)) |
table.insert(boxes, CFCM.Box(ColorFound[i],WriteColor)) |
||
end |
end |
||
Line 435: | Line 436: | ||
removeBlanks = false |
removeBlanks = false |
||
}) |
}) |
||
local |
local Nargs = require("Module:TableTools").length(args) |
||
local ColorName, IsInv = CFCM.ColorNameInv (args) |
|||
local N = tonumber(args[2]) |
local N = tonumber(args[2]) |
||
local ColWidth = args[3] |
local ColWidth = args[3] |
||
Line 442: | Line 444: | ||
local NLabels = 0 |
local NLabels = 0 |
||
local IsTemplate = true |
local IsTemplate = true |
||
ColorFound = p.GetColors(ColorName, IsInv, N, true) |
ColorFound = p.GetColors (ColorName, IsInv, N, true) |
||
Labels, NLabels, OutlineColor = CFCM.GetLabels (args, Nargs, N, 4) |
|||
return CFCM.LegendText(ColorFound, Labels, NLabels, ColWidth, IsTemplate, OutlineColor) |
return CFCM.LegendText (ColorFound, Labels, NLabels, ColWidth, IsTemplate, OutlineColor) |
||
end |
end |
||