Difference between revisions of "Module:ComplForColorModules"
Jump to navigation
Jump to search
blackwiki>Jmarchn m |
blackwiki>Pppery (Please stop attempting to overturn consensus established at TfD) |
||
| Line 1: | Line 1: | ||
| − | |||
| − | + | function p.LegendText (AColors, Labels, NLabels, ColWidth, IsTemplate, OutlineColor) | |
| − | + | ColWidth = mw.text.trim(ColWidth) | |
| − | + | if ColWidth and #ColWidth == 0 then | |
| − | + | ColWidth = nil | |
| − | + | end | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | function p. | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | if | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | end | ||
| − | |||
| − | |||
| − | |||
| − | |||
function NoDataFound (i) | function NoDataFound (i) | ||
if string.sub(Labels[i],1,2) == '--' then | if string.sub(Labels[i],1,2) == '--' then | ||
| Line 139: | Line 32: | ||
table.insert(Show, p.LegendColor(AColors[i],Text,'')) | table.insert(Show, p.LegendColor(AColors[i],Text,'')) | ||
end | 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 | for i=1, table.getn(AColors) do | ||
if WithLabels then Text = Labels[i] end | if WithLabels then Text = Labels[i] end | ||
table.insert(Codes, ' '..LegendCode(AColors[i],Text,OutlineColor)) | table.insert(Codes, ' '..LegendCode(AColors[i],Text,OutlineColor)) | ||
end | end | ||
| − | local SCodes = | + | 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 | return SShow..'\n'..SCodes | ||
end | end | ||
return p | return p | ||
Revision as of 20:03, 12 November 2019
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