Module:BrewerColors and Module:BrewerColors/sandbox: Difference between pages
(Difference between pages)
imported>Lemondoge m Minor simplifications and formatting improvements |
imported>Pppery No edit summary |
||
Line 1: | Line 1: | ||
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 14: | 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 360: | Line 360: | ||
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 = table.getn(ColorSet[N-2]), 1, -1 do | 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 = 1, table.getn(ColorSet[N-2]) do | 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 408: | 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) | |||
end | |||
end | end | ||
return ColorFound | return ColorFound | ||
Line 418: | 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 = 1, table.getn(ColorFound) do | 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 434: | Line 436: | ||
removeBlanks = false | removeBlanks = false | ||
}) | }) | ||
local ColorName, IsInv = CFCM.ColorNameInv(args) | 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 441: | 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, N, 4) | 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 | ||
return p | return p |