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
 
(65 intermediate revisions by 2 users not shown)
Line 3:
local yesno = require('Module:Yesno')
 
--------------------------------------------------------------------------------
----- C R E A T E T A B L E S ----------
---------- P . D O T S ---------------------------------------------------------
----- Returns the xTable and yTable-----
---------- Returns all the dots (with absolute postions) -----------------------
--------------------------------------------------------------------------------
 
local function createTablesp.data(argsframe) -- Returns the data of the graph
local args = getArgs(frame)
-- Dot related
local yTable = {}
local xTable = {}
Line 12 ⟶ 16:
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
Line 38 ⟶ 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 69 ⟶ 99:
return table.concat({'<span style="font-size:100%" class="error">The amount of x values (',xCount,') is more then the number y values (',yCount,')</span>'})
end
return {xTable,yTable}
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({'<div>[[File:Location dot ',color or 'red','.svg|8x8px]] (',color,') = ',v,'</div>'})
table.insert(Table,v)
aValue = true
end
end
if aValue == true then
return table.concat(Table)
else
return ""
end
end
 
-------------------------------------------------------------
------------------------ P . D O T S ------------------------
------- Returns all the dots (with absolute postions) -------
-------------------------------------------------------------
 
function p.dots(frame) -- Returns all the data to make the dots
local args = getArgs(frame)
local dotTable = {}
local colorTable = {}
local x;
local num;
local colorTime;
if mw.ustring.match(tostring(createTables(args)),"<span") then -- Return error messages from p.dots
return tostring(createTables(args))
end
local xTable = createTables(args)[1]
local yTable = createTables(args)[2]
if args["color-even"] then -- Creates the colorTable if color-even is set
Line 165 ⟶ 150:
div
:css('position','absolute')
:css('bottom',table.concat({y*0.85+15,'%'}))
:css('rightleft',table.concat({100-x*0.985+15,'%'}))
: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({((100/xLCount*k-100/xLCount)*0.85+15)-4,'%'}))
: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({(((((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
 
---------- L E G E N D ---------------------------------------------------------
---------- Makes the legendTable -----------------------------------P . G R A P H ------------
 
------- Returns all the dots in div tags---
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({'<div>[[File:Location dot ',color or 'red','.svg|8x8px]] (',color,') = ',v,'</div>'})
table.insert(Table,v)
aValue = true
end
end
if aValue == true then
return table.concat(Table)
else
return ""
end
end
 
--------------------------------------------------------------------------------
---------- 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.dotsdata(frame),"<span") then -- Return error messages from p.dotsdata
return p.dotsdata(frame)
end
local args = getArgs(frame)
Line 186 ⟶ 214:
local div = mw.html.create('div')
local center = mw.html.create('div')
local aft = mw.html.create('div')
local container = mw.html.create('div')
local top = mw.html.create('div')
Line 211 ⟶ 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 256 ⟶ 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(tostring(aft))
:wikitext(legend(args))
:wikitext(args["bottom"])
if args["color"] then
div:css('background', args["color"])
end
if yesno(args['border']) ~= false then -- Creates box border