Module:BrewerColors explained

local p =

local CFCM = require "Module:ComplForColorModules"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

'ylgn' then GetC(ColorYlGn) elseif ColorNameL

'ylgnbu' then GetC(ColorYlGnBu) elseif ColorNameL

'gnbu' then GetC(ColorGnBu) elseif ColorNameL

'bugn' then GetC(ColorBuGn) elseif ColorNameL

'pubugn' then GetC(ColorPuBuGn) elseif ColorNameL

'pubu' then GetC(ColorPuBu) elseif ColorNameL

'bupu' then GetC(ColorBuPu) elseif ColorNameL

'rdpu' then GetC(ColorRdPu) elseif ColorNameL

'purd' then GetC(ColorPuRd) elseif ColorNameL

'orrd' then GetC(ColorOrRd) elseif ColorNameL

'ylorrd' then GetC(ColorYlOrRd) elseif ColorNameL

'ylorbr' then GetC(ColorYlOrBr) elseif ColorNameL

'purples' then GetC(ColorPurples) elseif ColorNameL

'blues' then GetC(ColorBlues) elseif ColorNameL

'greens' then GetC(ColorGreens) elseif ColorNameL

'oranges' then GetC(ColorOranges) elseif ColorNameL

'reds' then GetC(ColorReds) elseif ColorNameL

'greys' then GetC(ColorGreys) elseif ColorNameL

'puor' then GetC(ColorPuOr) elseif ColorNameL

'brbg' then GetC(ColorBrBG) elseif ColorNameL

'prgn' then GetC(ColorPRGn) elseif ColorNameL

'piyg' then GetC(ColorPiYG) elseif ColorNameL

'rdbu' then GetC(ColorRdBu) elseif ColorNameL

'rdgy' then GetC(ColorRdGy) elseif ColorNameL

'rdylbu' then GetC(ColorRdYlBu) elseif ColorNameL

'spectral' then GetC(ColorSpectral) elseif ColorNameL

'rdylgn' then GetC(ColorRdYlGn) elseif ColorNameL

'accent' then GetC(ColorAccent) elseif ColorNameL

'dark2' then GetC(ColorDark2) elseif ColorNameL

'paired' then GetC(ColorPaired) elseif ColorNameL

'pastel1' then GetC(ColorPastel1) elseif ColorNameL

'pastel2' then GetC(ColorPastel2) elseif ColorNameL

'set1' then GetC(ColorSet1) elseif ColorNameL

'set2' then GetC(ColorSet2) elseif ColorNameL

'set3' then GetC(ColorSet3) elseif CallError then error(I18nStr(RS_ColorNameInvalid,ColorName), 0) end return ColorFoundend

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 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, N, 4) return CFCM.LegendText(ColorFound, Labels, NLabels, ColWidth, IsTemplate, OutlineColor)end

return p