local p =
local CFCM = require "Module:ComplForColorModules/sandbox"local TNTT = require "Module:TNTTools"local ARG = require "Module:Arguments"local I18n = 'BrewerColors'
--local RS_ColorNumInvalid = 'ColorNumInvalid'local RS_ColorNameInvalid = 'ColorNameInvalid'
local function I18nStr (S, ...) return TNTT.GetMsgP (I18n, S,)end
-- This product includes ColorName specifications and designs developed by Cynthia Brewer (http://colorbrewer.org/).local ColorYlGn = local ColorYlGnBu = local ColorGnBu = local ColorBuGn = local ColorPuBuGn = local ColorPuBu = local ColorBuPu = local ColorRdPu = local ColorPuRd = local ColorOrRd = local ColorYlOrRd = local ColorYlOrBr = local ColorPurples = local ColorBlues = local ColorGreens = local ColorOranges = local ColorReds = local ColorGreys = local ColorPuOr = local ColorBrBG = local ColorPRGn = local ColorPiYG = local ColorRdBu = local ColorRdGy = local ColorRdYlBu = local ColorSpectral = local ColorRdYlGn = local ColorAccent = local ColorDark2 = local ColorPaired = local ColorPastel1 = local ColorPastel2 = local ColorSet1 = local ColorSet2 = local ColorSet3 =
function p.GetColors(ColorName, IsInv, N, CallError) local ColorFound = function GetC(ColorSet) if (N < 3) or (N > (table.getn(ColorSet)+2)) then if CallError then error (I18nStr(RS_ColorNumInvalid,tostring(N)), 0) end elseif IsInv then for i=table.getn(ColorSet[N-2]), 1, -1 do table.insert (ColorFound, '#'..ColorSet[N-2][i]) end else for i=1, table.getn(ColorSet[N-2]) do table.insert (ColorFound, '#'..ColorSet[N-2][i]) end end end local ColorNameL = string.lower (ColorName) if ColorNameL
'ylgnbu' then GetC(ColorYlGnBu) elseif ColorNameL
'bugn' then GetC(ColorBuGn) elseif ColorNameL
'pubu' then GetC(ColorPuBu) elseif ColorNameL
'rdpu' then GetC(ColorRdPu) elseif ColorNameL
'orrd' then GetC(ColorOrRd) elseif ColorNameL
'ylorbr' then GetC(ColorYlOrBr) elseif ColorNameL
'blues' then GetC(ColorBlues) elseif ColorNameL
'oranges' then GetC(ColorOranges) elseif ColorNameL
'greys' then GetC(ColorGreys) elseif ColorNameL
'brbg' then GetC(ColorBrBG) elseif ColorNameL
'piyg' then GetC(ColorPiYG) elseif ColorNameL
'rdgy' then GetC(ColorRdGy) elseif ColorNameL
'spectral' then GetC(ColorSpectral) elseif ColorNameL
'accent' then GetC(ColorAccent) elseif ColorNameL
'paired' then GetC(ColorPaired) elseif ColorNameL
'pastel2' then GetC(ColorPastel2) elseif ColorNameL
'set2' then GetC(ColorSet2) elseif ColorNameL
function p.ShowColors(frame) local args = ARG.getArgs(frame,) local ColorName, IsInv = CFCM.ColorNameInv (args) local N = tonumber(args[2]) local WriteColor = args[3] or local ColorFound = ColorFound = p.GetColors (ColorName, IsInv, N, true) local boxes = for i=1, table.getn(ColorFound) do table.insert(boxes, CFCM.Box(ColorFound[i],WriteColor)) end return table.concat(boxes, " ")end
function p.Legends(frame) local args = ARG.getArgs(frame,) local Nargs = require("Module:TableTools").length(args) local ColorName, IsInv = CFCM.ColorNameInv (args) local N = tonumber(args[2]) local ColWidth = args[3] local ColorFound = local Labels = local NLabels = 0 local IsTemplate = 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)end
return p