Module:Dot chart/sandbox explained

local p = local getArgs = require("Module:Arguments").getArgslocal yesno = require('Module:Yesno')

------------------------------------------------------------------------------------------ P . D O T S ------------------------------------------------------------------- Returns all the dots (with absolute postions) -------------------------------------------------------------------------------------------------------

function p.data(frame) -- Returns the data of the graph local args = getArgs(frame) -- Dot related local yTable = local xTable = local xCount = 0 local yCount = 0 local isx; local dotTable = local x; -- Color related local colorTable = local num; local colorTime; -- X label related local xLabels = local xLCount = 0 -- Y label related local yLabels = local yLCount = 0

if yesno(args["yx"])

true then isx = false else isx = true end if args["x labels"] then -- Create xLabels for str in string.gmatch(args["x labels"], "([^,]+)") do table.insert(xLabels,str) xLCount = xLCount+1 end end if args["y labels"] then -- Create yLabels for str in string.gmatch(args["y labels"], "([^,]+)") do table.insert(yLabels,str) yLCount = yLCount+1 end end if args["dots"] then -- Creates xTable from dots local i = 0 local j = 0 for k,v in pairs(args) do if string.match(k,"%d+") and not string.match(k,"color%-") then table.insert(yTable,v) yCount = yCount+1 end end local cols = yCount / tonumber(args["dots"]) if cols ~= math.floor(cols) then return table.concat end while(cols>i) do local xValue = ((100/cols*i)+(100/cols/10))*1.1 i=i+1 while(tonumber(args["dots"])>j) do j=j+1 table.insert(xTable,xValue) xCount = xCount + 1 end j=0 end else -- Divides args into the yTable and the xTable for k,v in pairs(args) do if string.match(k,"%d+") and not string.match(k,"color%-") then if isx

false then table.insert(yTable,v) yCount = yCount + 1 isx = true elseif not args["dots"] then table.insert(xTable,v) xCount = xCount + 1 isx = false end end end end if xCount < yCount then return table.concat elseif xCount > yCount then return table.concat end if args["color-even"] then -- Creates the colorTable if color-even is set colorTime = false for k,v in pairs(yTable) do if colorTime

true then colorTable[k] = args["color-even"] colorTime = false else colorTime = true end end end if args["color-odd"] then -- Creates the colorTable if color-odd is set colorTime = true for k,v in pairs(yTable) do if colorTime

true then colorTable[k] = args["color-odd"] colorTime = false else colorTime = true end end end for k,v in pairs(args) do -- Adds values to the colorTable if color-# is set if k

mw.ustring.match(k,"color%-%d+") then num = mw.ustring.gsub(k,"color%-","") num = tonumber(num) colorTable[num] = v end end for k,y in pairs(yTable) do -- Creates the dotTable local InnerDiv = mw.html.create('div') local div = mw.html.create('div') local size; if args["size"] then size = tonumber(mw.ustring.match(args["size"],"(%d+)")) else size = 8 end x = xTable[k] InnerDiv :css('position','absolute') :css('top',table.concat) :css('left',table.concat) :css('line-height','0') :wikitext('') div :css('position','absolute') :css('bottom',table.concat) :css('left',table.concat) :wikitext(tostring(InnerDiv)) table.insert(dotTable,tostring(div)) end for k,v in pairs(xLabels) do local div = mw.html.create('div') div :css('position','absolute') :css('bottom','0%') :css('left',table.concat) :wikitext(v) 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) :css('left','0%') :wikitext(v) table.insert(dotTable,tostring(div)) end return table.concat(dotTable)end

---------- L E G E N D ------------------------------------------------------------------- Makes the legendTable -----------------------------------------------

local function legend(args) local color; local aValue; local Table = for k,v in pairs(args) do -- Adds values to the table if k

mw.ustring.match(k,"legend%-%a+") then color = mw.ustring.gsub(k,"legend%-","") v = table.concat table.insert(Table,v) aValue = true end end if aValue

true then return table.concat(Table) else return "" endend

------------------------------------------------------------------------------------------ P . G R A P H ----------------------------------------------------------------- Returns all the dots in div tags---------------------------------------------------------------------------------------------------------------------

function p.graph(frame) -- Returns a graph with the dots on it if mw.ustring.match(p.data(frame),"