Jump to content

Module:ComplForColorModules

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pppery (talk | contribs) at 20:03, 12 November 2019 (Please stop attempting to overturn consensus established at TfD). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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