Module:Dot chart/sandbox: Difference between revisions

Content deleted Content added
No edit summary
Tag: Reverted
Don't add border:none to improve compatibility with skin dark mode CSS
 
(One intermediate revision by the same user not shown)
Line 1:
local p = {}
local getArgs = require('"Module:Arguments'").getArgs
local yesno = require('Module:Yesno')
 
--------------------------------------------------------------------------------
-- Returns all the dots (with absolute postions)
---------- 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)
Line 25 ⟶ 29:
local yLCount = 0
 
if yesno(args['"yx'"]) == true then
isx = false
else
Line 31 ⟶ 35:
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({'<span style="font-size:100%" class="error">The amount of y parameters (' .. ,yCount .. ,') ÷ parameter dots (' .. ,args['"dots'"] .. ,') is not a integer (' .. ,cols .. ,')</span>'})
end
while (cols > i) do
local xValue = i ((100/ cols*i)+(100/cols - 1/10)) * 1001.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
Line 91 ⟶ 95:
if xCount < yCount then
return table.concat({'<span style="font-size:100%"" class="error">The amount of x values (' .. ,xCount .. ,') is less then the number y values (' .. ,yCount .. ,')</span>'})
elseif xCount > yCount then
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
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
Line 108 ⟶ 112:
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
Line 120 ⟶ 124:
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
Line 128 ⟶ 132:
end
for k, y in pairs(yTable) do -- CreateCreates the dotTable
local innerDivInnerDiv = 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
innerDiv
:css('position', 'absolute')
:css('top', table.concat({'-' .. ,size / 2 .. ,'px'}))
:css('left', table.concat({'-' .. ,size / 2 .. ,'px'}))
:css('line-height', '0')
:wikitext('[[File:Location dot ', colorTable[k] or 'red', '.svg|', size, 'x', size, 'px]]')
div
:css('position', 'absolute')
:css('bottom', y table.concat({y*0. 85+15,'%'}))
:css('left', x table.concat({x*0. 85+15,'%'}))
:wikitext(tostring(innerDivInnerDiv))
table.insert(dotTable, tostring(div))
end
for k, v in pairs(xLabels) do
local innerDiv = mw.html.create('div')
local div = mw.html.create('div')
innerDiv
:css('position', 'relative')
:css('left', '-50%')
:wikitext(v)
div
:css('position', 'absolute')
:css('bottom', '0%')
:css('left', table.concat({((100/xLCount*k - 1) 100/ (xLCount - 1) * 100 0.. 85+15)-4,'%'}))
:wikitext(tostring(innerDiv)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 - 1) 100/ (yLCount )- 1(100/yLCount/3) * )+5))+100 /yLCount/2)*1.. 02,'%'}))
:css('left', '0%')
:wikitext(v)
table.insert(dotTable, tostring(div))
end
Line 180 ⟶ 179:
end
 
---------- L E G E N D ---------------------------------------------------------
-- Create the legendTable
---------- Makes the legendTable -----------------------------------------------
 
local function legend(args)
local color;
local aValue;
local legendTableTable = {}
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(legendTableTable, v)
aValue = true
end
end
if aValue == true then
return table.concat(legendTableTable)
else
return ''""
end
end
 
--------------------------------------------------------------------------------
-- Get all the dots in a div tag
---------- 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), '"<span'") then -- Return error messages from p.data
return p.data(frame)
end
local args = getArgs(frame)
local picture = '"Blank.png'"
local div = mw.html.create('div')
local center = mw.html.create('div')
Line 212 ⟶ 217:
local top = mw.html.create('div')
local size;
if args['"size'"] then
size = tonumber(mw.ustring.match(args['"size'"], '"(%d+)'"))
else
size = 8
end
if args['"width'"] then
if args['"width'"] == mw.ustring.match(args['"width'"], '"(%d+)'") then
args['"width'"] = table.concat({args['"width'"] .. ,'px'})
end
end
 
if args['"picture'"] then -- Set local picture
picture = args['"picture'"]
elseif yesno(args['"square'"]) == true then
picture = '"Transparent.png'"
end
picture = mw.ustring.gsub(picture, '|.+', '')
picture = mw.ustring.gsub(picture, '.-:', '')
if p.data(frame) == ''"" then -- Don't make box if empty
return ''""
end
if args['"top'"] then
top -- Create top text
:css('font-weight', 'bold')
:css('text-decoration', 'underline')
:css('text-align', 'center')
:wikitext(args['"top'"])
end
args['padding'] = args['padding'] or '10px'
if not args['top'] and size/2 > 10 then
args['padding'] = size/2
end
container -- Creates container
:css('width', args['"width'"] or '240px')
:css('float', 'right')
:css('position', 'relative')
:wikitext('[[File:', picture, '|', args['"width'"] or '240px', ']]')
:wikitext(p.data(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
div
:css('border-style', 'solid')
:css('border-color', 'black')
:css('border-width', '3px')
end
Line 279 ⟶ 281:
center
:addClass('center')
:css('width', 'auto')
:css('margin-left', 'auto')
:css('margin-right', 'auto')
:wikitext(tostring(div))
return center