Module:ChartColors
Appearance
From Wikipedia, the free encyclopedia
Used by {{ChartColors }}.
To translate or review the translation of the module to your language, edit carefully Data:I18n/ChartColors.tab.
Function ShowColors
[edit ]| Code | Result |
|---|---|
{{#invoke:ChartColors|ShowColors|Categ20|5}} |
|
{{ChartColors|Categ20|9}} |
|
{{#invoke:ChartColors|ShowColors|Categ20|3|-}} |
#1f77b4 #ff7f0e #2ca02c |
{{#invoke:ChartColors|ShowColors|Categ20|3|a}} |
#1f77b4ff #ff7f0eff #2ca02cff |
{{#invoke:ChartColors|ShowColors|Plotter|5}} |
|
{{#invoke:ChartColors|Plotter|20}} |
Function Legends
[edit ]{{#invoke:ChartColors|Legends|Categ20|5|2}}
produces:
{{div col|colwidth=2}}
{{legend|#1f77b4|}}
{{legend|#ff7f0e|}}
{{legend|#2ca02c|}}
{{legend|#d62728|}}
{{legend|#9467bd|}}
{{div col end}}
{{#invoke:ChartColors|Legends|Categ20|3|1|One|Two|Three}}
produces:
{{div col|colwidth=1}}
{{legend|#1f77b4|One}}
{{legend|#ff7f0e|Two}}
{{legend|#2ca02c|Three}}
{{div col end}}
The above documentation is transcluded from Module:ChartColors/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
require('strict') localp={} localARG=require"Module:Arguments" localCFCM=require"Module:ComplForColorModules" localTNTT=require"Module:TNTTools" --local SD = require "Module:SimpleDebug" localI18n='ChartColors' localfunctionI18nStr(S,...) returnTNTT.GetMsgP(I18n,S,{...}) end --local RS_ColorNameInvalid = 'El nom del color (%s) no és vàlid (ha de ser Categ20 o Plotter)' --local RS_ColorNumInvalid = 'El nombre de colors hauria d’estar entre 1 i %d (ara és %d)' --local RS_StartNumInvalid = 'El número del primer color hauria d’estar entre 1 i %d (ara és %d)' localcategory20={ '#1f77b4','#aec7e8','#ff7f0e','#ffbb78','#2ca02c','#98df8a','#d62728','#ff9896','#9467bd','#c5b0d5', '#8c564b','#c49c94','#e377c2','#f7b6d2','#7f7f7f','#c7c7c7','#bcbd22','#dbdb8d','#17becf','#9edae5', } localplotter={--from Module:Plotter/DefaultColors 'red','blue','green','yellow','fuchsia','aqua','brown','orange','purple','sienna', '#F0A3FF','#191919','#005C31','honeydew','#808080','khaki','lime','navy','pink','#426600', '#5EF1F2','turquoise','#E0FF66','violet','#FFFF80','#FF5005', } functionp.GetColors(ColorName,IsInv,StartN,N,CallError) localSelColors={} localColorNameL=string.lower(ColorName) localPalet0={} ifColorNameL=='categ20'then Palet0=category20 elseifColorNameL=='plotter'then Palet0=plotter elseifCallErrorthen error(I18nStr('ColorNameInvalid',ColorName)) end localMaxN=table.getn(Palet0) if(N<0)or(N>MaxN)then error(I18nStr('ColorNumInvalid',tostring(MaxN),tostring(N))) else localPalet={} ifIsInvthen fori=MaxN,1,-1do table.insert(Palet,Palet0[i]) end else Palet=Palet0 end ifStartN>MaxNthen error(I18nStr('StartNumInvalid',tostring(MaxN),tostring(StartN))) end localStep=1 localNEnd=N if(ColorNameL=='categ20')and(N<=10)then Step=2 ifStartN==1then NEnd=N*2 end end ifStartN==1then fori=1,NEnd,Stepdo table.insert(SelColors,Palet[i]) end else localCount=0 fori=StartN,MaxN,Stepdo table.insert(SelColors,Palet[i]) Count=Count+1 ifCount==NEndthen break end end ifCount<NEndthen fori=1,MaxN,Stepdo table.insert(SelColors,Palet[i]) Count=Count+1 ifCount==NEndthen break end end end end returnSelColors end end--GetColors functionp.ColorNameInvStartFromS(S) localStartN=1 localParamsA={} localColorName,IsInv ColorName,IsInv,ParamsA=CFCM.ColorNameInvFromS0(S) localPN=table.getn(ParamsA) ifPN>1then ifParamsA[2]=='i'then IsInv=true else StartN=tonumber(ParamsA[2]) end ifPN==3then StartN=tonumber(ParamsA[3]) end end returnColorName,IsInv,StartN end--ColorNameInvStartFromS localfunctionColorNameInv(args) localS=args[1]or'' localColorName,IsInv,ParamsA=CFCM.ColorNameInvFromS0(S) localStartN=1 ColorName,IsInv,StartN=p.ColorNameInvStartFromS(S) returnColorName,IsInv,StartN end--ColorNameInv functionp.ShowColors(frame) localargs=ARG.getArgs(frame,{ removeBlanks=false }); localColorName,IsInv,StartN=ColorNameInv(args) localN=tonumber(args[2]) localWriteColor=args[3]or"" localColorFound={} ColorFound=p.GetColors(ColorName,IsInv,StartN,N,true) localboxes={} fori=1,table.getn(ColorFound)do table.insert(boxes,CFCM.Box(ColorFound[i],WriteColor)) end returntable.concat(boxes," ") end--ShowColors functionp.Legends(frame) localargs=ARG.getArgs(frame,{ removeBlanks=false }) localNargs=require("Module:TableTools").length(args) localColorName,IsInv,StartN=ColorNameInv(args) localN=tonumber(args[2]) localColWidth=args[3] localColorFound={} localLabels={} localNLabels=0 localOutlineColor localIsTemplate=true ColorFound=p.GetColors(ColorName,IsInv,StartN,N,true) Labels,NLabels,OutlineColor=CFCM.GetLabels(args,N,4) returnCFCM.LegendText(ColorFound,Labels,NLabels,ColWidth,IsTemplate,OutlineColor) end returnp