Module:Dot chart/sandbox: Difference between revisions

Content deleted Content added
No edit summary
Don't add border:none to improve compatibility with skin dark mode CSS
 
(59 intermediate revisions by 2 users not shown)
Line 8:
--------------------------------------------------------------------------------
 
function p.dotsdata(frame) -- Returns all the data to makeof the dotsgraph
local args = getArgs(frame)
-- Dot related
Line 24:
-- X label related
local xLabels = {}
local labelNumxLCount = 0
-- Y label related
local yLabels = {}
local yLCount = 0
 
if yesno(args["yx"]) == true then
Line 31 ⟶ 33:
else
isx = true
end
if args["x labels"] then -- Create xLabels
for str in string.gmatch(args["x labels"], "([^,]+)") do
table.insert(xLabels[i] = ,str)
ixLCount = i xLCount+ 1
end
end
if args["y labels"] then -- Create yLabels
for str in string.gmatch(args["xy labels"], "([^,]+)") do
table.insert(yLabels,str)
yLCount = yLCount+1
end
end
Line 52 ⟶ 68:
while(cols>i) do
local xValue = ((100/cols*i)+(100/cols/210))*1.1
i=i+1
while(tonumber(args["dots"])>j) do
Line 114 ⟶ 130:
colorTable[num] = v
end
end
if args["x labels"] then -- Create xLabels
for str in string.gmatch(args["x labels"], "([^,]+)") do
xLabels[i] = str
i = i + 1
end
end
if args["y labels"] then -- Create yLabels
for str in string.gmatch(args["x labels"], "([^,]+)") do
yLabels[i] = str
i = i + 1
end
end
Line 148 ⟶ 150:
div
:css('position','absolute')
:css('bottom',table.concat({y*0.85+15,'%'}))
:css('left',table.concat({x*0.985+1015,'%'}))
:wikitext(tostring(InnerDiv))
table.insert(dotTable,tostring(div))
end
for _k,_v in pairs(lableTablexLabels) do
local div = mw.html.create('div')
div
:css('text-alignposition','centerabsolute')
:css('bottom','0%')
:css('left',table.concat({((100/xLCount*k-100/xLCount)*0.85+15)-4,'%'}))
:wikitext(labelDivv)
table.insert(dotTable,tostring(div))
end
for k,v in pairs(yLabels) do
local div = mw.html.create('div')
div
:css('position','absolute')
:css('bottom',table.concat({(((((100/yLCount*k-100/yLCount)-(100/yLCount/3))+5))+100/yLCount/2)*1.02,'%'}))
:css('left','0%')
:wikitext(v)
table.insert(dotTable,tostring(div))
end
return table.concat(dotTable)
end
Line 184 ⟶ 207:
 
function p.graph(frame) -- Returns a graph with the dots on it
if mw.ustring.match(p.dotsdata(frame),"<span") then -- Return error messages from p.dotsdata
return p.dotsdata(frame)
end
local args = getArgs(frame)
Line 215 ⟶ 238:
picture = mw.ustring.gsub(picture,'.-:','')
if p.dotsdata(frame) == "" then -- Don't make box if empty
return ""
end
if args["x labels"] then -- Create x labels
local labelNum = 0
local lableTable={}
local i=1
local j=1
local labelDiv = ""
 
for str in string.gmatch(args["x labels"], "([^,]+)") do
lableTable[i] = str
i = i + 1
end
for _,_ in pairs(lableTable) do
labelNum = labelNum+1
end
while(labelNum>=j) do
labelDiv = table.concat({labelDiv,'<div style="float:left;width:',100/labelNum,'%>',lableTable[j],'</div>'})
j = j+1
end
if labelDiv then
aft
:css('text-align','center')
:wikitext(labelDiv)
end
end
Line 260 ⟶ 255:
:css('position','relative')
:wikitext('[[File:',picture,'|',args["width"] or '240px',']]')
:wikitext(p.dotsdata(frame))
div -- Creates box
:css('width', args["width"] or '240px')
:css('display', 'inline-block')
:css('float', args["align"] or 'right')
:css('margin', args["margin"] or '2px')
:css('padding', args["padding"] or table.concat({size/2,'px'}))
:css('background',args["color"] or 'none')
:wikitext(tostring(top))
:wikitext(tostring(container))
:wikitext(legend(args))
:wikitext(args["bottom"])
if args["color"] then
div:css('background', args["color"] or 'none')
end
if yesno(args['border']) ~= false then -- Creates box border