Module:ComplForColorModules
Appearance
This module is used by Module:BrewerColors and Module:ChartColors.
To translate or review the translation of the module to your language, edit carefully Data:I18n/ComplForColorModules.tab.
function p.LegendText (AColors, Labels, NLabels, ColWidth, IsTemplate, OutlineColor)
ColWidth = mw.text.trim(ColWidth)
if ColWidth and #ColWidth == 0 then
ColWidth = nil
end
function NoDataFound (i)
if string.sub(Labels[i],1,2) == '--' then
return true
else
return false
end
end
local Show, Codes = {}, {}
local Text = ''
local WithLabels = NLabels > 0
if WithLabels then
function DelBegin (i)
Labels[i] = string.sub(Labels[i], 3, 1000)
end
local Gray = '#b3b3b3' -- A 40% gray
if NoDataFound(1) then
table.insert(AColors, 1, Gray)
DelBegin(1)
elseif NoDataFound(NLabels) then
table.insert(AColors, Gray)
DelBegin(NLabels)
end
end
for i=1, table.getn(AColors) do
if WithLabels then Text = Labels[i] end
table.insert(Show, p.LegendColor(AColors[i],Text,''))
end
SShow = table.concat(Show,"\n")
if ColWidth then
local frame = mw.getCurrentFrame()
SShow = frame:expandTemplate{title="div col",args={colwidth=ColWidth}} .. SShow
SShow = SShow .. frame:expandTemplate{title="div col end"}
end
for i=1, table.getn(AColors) do
if WithLabels then Text = Labels[i] end
table.insert(Codes, ' '..LegendCode(AColors[i],Text,OutlineColor))
end
local SCodes = '<pre>\n'
if ColWidth then
SCodes = SCodes .. require("Module:Template invocation").invocation("div col",{colwidth=ColWidth}) .. "\n"
end
SCodes = SCodes .. table.concat(Codes,"\n")
if ColWidth and #ColWidth ~= 0 then
SCodes = SCodes .. "\n{{div col end}}"
end
SCodes = SCodes .. "\n</pre>"
return SShow..'\n'..SCodes
end
return p