Jump to content
Wikipedia The Free Encyclopedia

Module:ComplForColorModules

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]

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.

The above documentation is transcluded from Module:ComplForColorModules/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.

 localp={}

 localTNTT=require"Module:TNTTools"

 localI18n='ComplForColorModules'

 --local MoreOneNoData = "Found 2 legends of \"Value not assigned\" or \"Data not available\""
 --local FoundNLegendsExpectedN = "Found 1ドル legends, expected 2ドル"
 --local Color = "Color"
 --local Legend = "legend"

 localfunctionI18nStr(S,...)
 returnTNTT.GetMsgP(I18n,S,{...})
 end

 functionp.ColorNameInvFromS0(S)
 localIsInv=false
 localColorName=''
 localParams={}
 ifS~=''then
 forwinS:gmatch("([^_]+)")do
 table.insert(Params,w)
 end
 ColorName=Params[1]
 end
 localPN=table.getn(Params)
 if(PN==2)and(Params[2]=='i')then
 IsInv=true
 end
 returnColorName,IsInv,Params
 end

 functionp.ColorNameInv(args)
 localColorName,IsInv,Params=p.ColorNameInvFromS0(args[1])
 returnColorName,IsInv
 end

 functionp.GetLabels(Args,N,Pos)
 localLabels={}
 localindex=Pos
 whileArgs[index]do
 Labels[#Labels+1]=Args[index]
 index=index+1
 end
 localNLabels=#Labels
 localOutlineColor=Args['outline']or''
 if(NLabels~=0)and(NLabels~=N)then
 localStartUnknown=(string.sub(Labels[1],1,2)=="--")
 localEndUnknown=(string.sub(Labels[NLabels],1,2)=="--")
 ifStartUnknownandEndUnknownthen
 error(I18nStr('MoreOneNoData'))
 elseifStartUnknownorEndUnknownthen
 N=N+1
 end
 if(NLabels~=0)and(NLabels~=N)then
 error(I18nStr('FoundNLegendsExpectedN',tostring(NLabels),tostring(N)))
 end
 end
 returnLabels,NLabels,OutlineColor
 end

 localfunctionSColor(Color)
 ifstring.sub(Color,1,1)=='#'then--the usual
 returnstring.sub(Color,2,100)
 else
 returnColor
 end
 end

 functionp.Box(Color,WriteColor)
 ifWriteColor=='-'then
 WriteColor=Color
 elseifWriteColor=='a'then
 WriteColor=Color..'ff'--Alpha channel
 end
 localTheBox='<span style="background-color:'..Color..'; border:1px solid gray;" title="'..TNTT.GetStrP(I18n,'Color')..': '..SColor(Color)..'">&nbsp;&nbsp;&nbsp;</span>'
 ifWriteColor~=''then
 TheBox=TheBox..'&nbsp;'..WriteColor..' &nbsp;'
 end
 returnTheBox
 end

 functionp.TextWithTooltip(Text,Tooltip)
 ifTooltip~=''then
 return'<span title="'..Tooltip..'">'..Text..'</span>'
 else
 returnText
 end
 end

 functionp.LegendColor(Color,Text,Tooltip)
 ifText==''then
 Text=SColor(Color)
 end
 return'<li style="list-style-type: none; list-style-image: none;"><span style="border:1px solid gray; background:'..Color..'; margin-right:0.3em; vertical-align: middle; webkit-print-color-adjust:exact; color-adjust:exact; display:inline-block; width:1.05em; height:1em;"></span>'..p.TextWithTooltip(Text,Tooltip)..'</li>'
 end

 localfunctionLegendCode(Color,Text,OutlineColor)
 localSOutlineColor=''
 ifOutlineColor~=''then
 SOutlineColor='|outline='..OutlineColor
 end
 return'{{'..TNTT.GetStrP(I18n,'Legend')..'|'..Color..'|'..Text..SOutlineColor..'}}'
 end

 functionp.LegendText(AColors,Labels,NLabels,ColWidth,IsTemplate,OutlineColor)
 ifColWidththen
 ColWidth=mw.text.trim(ColWidth)
 if#ColWidth==0then
 ColWidth=nil
 end
 end
 localShow,Codes={},{}
 localText=''
 localWithLabels=NLabels>0
 ifWithLabelsthen
 localGray='#b3b3b3'-- A 40% gray
 ifstring.sub(Labels[1],1,2)=='--'then
 table.insert(AColors,1,Gray)
 Labels[1]=string.sub(Labels[1],3,1000)
 elseifstring.sub(Labels[NLabels],1,2)=='--'then
 table.insert(AColors,Gray)
 Labels[NLabels]=string.sub(Labels[NLabels],3,1000)
 end
 end
 fori=1,table.getn(AColors)do
 ifWithLabelsthenText=Labels[i]end
 table.insert(Show,p.LegendColor(AColors[i],Text,''))
 end
 localSShow=table.concat(Show,"\n")
 ifColWidththen
 localframe=mw.getCurrentFrame()
 SShow=frame:expandTemplate{title="div col",args={colwidth=ColWidth}}..SShow
 SShow=SShow..frame:expandTemplate{title="div col end"}
 end
 fori=1,table.getn(AColors)do
 ifWithLabelsthenText=Labels[i]end
 table.insert(Codes,' '..LegendCode(AColors[i],Text,OutlineColor))
 end
 localSCodes='<pre>\n'
 ifColWidththen
 SCodes=SCodes..require("Module:Template invocation").invocation("div col",{colwidth=ColWidth}).."\n"
 end
 SCodes=SCodes..table.concat(Codes,"\n")
 ifColWidthand#ColWidth~=0then
 SCodes=SCodes.."\n{{div col end}}"
 end
 SCodes=SCodes.."\n</pre>"
 returnSShow..'\n'..SCodes
 end

 returnp

AltStyle によって変換されたページ (->オリジナル) /