Module:Dot plot
Examples
{{#invoke:dot plot|plot|align=left|10|20|10|60|50|40|50|60|90|10|90|20}}
{{#invoke:dot plot|plot|align=left|0|100|100|0|0|0|100|100}}
{{#invoke:dot plot|plot|yx=yes|align=left|10|20|10|60|50|40|50|60|90|10|90|20}}
{{#invoke:dot plot|plot|align=left|cols=3|dots=2|90|10|80|20|70|30}}
{{#invoke:dot plot|plot|square=yes|align=left|cols=3|dots=2|90|10|80|20|70|30}}
{{#invoke:dot plot|plot|align=right|40|10|60|10|40|20|60|20|40|30|60|30|color-1=blue|color-3=blue|color-5=blue}}
{{#invoke:dot plot|plot|align=left|40|10|60|10|40|20|60|20|40|30|60|30|color-even=blue}}
{{#invoke:dot plot|plot|align=center|40|10|60|10|40|20|60|20|40|30|60|30|color-odd=blue}}
{{#invoke:dot plot|plot|border=no|align=left|10|20|10|60|50|40|50|60|90|10|90|20|color-1=blue|color-3=blue|color-5=blue}}
{{#invoke:dot plot|plot|color=green|align=left|10|20|10|60|50|40|50|60|90|10|90|20|color-1=blue|color-3=blue|color-5=blue}}
local p = {}
local dot = require("Module:Location map").mark
local container = require("Module:Location map/multi").container
local getArgs = require("Module:Arguments").getArgs
local yesno = require('Module:Yesno')
function p.dots(frame) -- Returns all the data to make the dots
local args = getArgs(frame)
local dotTable = {}
local yTable = {}
local xTable = {}
local colorTable = {}
local dotArgs = {}
local isx;
local xCount = 0
local yCount = 0
local x;
local point;
local color;
local num;
local colorTime;
if yesno(args["yx"]) == true then
isx = false
else
isx = true
end
if args["cols"] and args["dots"] then
local i = 0
local j = 0
while(tonumber(args["cols"])>i) do
local xValue = 100/args["cols"]*i
i=i+1
while(tonumber(args["dots"])>j) do
j=j+1
table.insert(xTable,xValue)
xCount = xCount + 1
end
j=0
end
end
for k,v in pairs(args) do -- Divides args into the yTable and the xTable
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["cols"] and not args["dots"] then
table.insert(xTable,v)
xCount = xCount + 1
isx = false
else
table.insert(yTable,v)
yCount = yCount + 1
isx = false
end
end
end
if args["cols"] and not args["dots"] then
return '<span style="font-size:100%" class="error">cols is specified but dots is not</span>'
elseif args["dots"] and not args["cols"] then
return '<span style="font-size:100%" class="error">dots is specified but cols is not</span>'
end
if xCount < yCount then
return '<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 '<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
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 subst = 0
x = xTable[k]
dotArgs["lat_deg"] = y*1.8-90
dotArgs["lon_deg"] = x*3.6-180
if dotArgs["lat_deg"] == 90 then dotArgs["lat_deg"] = 89.999 end
if dotArgs["lon_deg"] == 180 then dotArgs["lon_deg"] = 179.999 end
if colorTable[k] then
color = table.concat({"Location dot ",colorTable[k],".svg"})
else
color = "Location dot red.svg"
end
dotArgs["mark"] = color
while(tonumber(y) > -1) do
point = tostring(dot(dotArgs))
table.insert(dotTable,point)
y = y -5
dotArgs["lat_deg"] = y*1.8-90
end
end
return table.concat(dotTable)
end
function p.plot(frame) -- Returns a graph with the dots on it
if mw.ustring.match(p.dots(frame),"<span") then return p.dots(frame) end -- Return error messages from p.dot
local args = getArgs(frame)
local containerArgs = {}
local div = mw.html.create('div')
local center = mw.html.create('div')
containerArgs["places"] = p.dots(frame)
if yesno(args["square"]) == true then
containerArgs["AlternativeMap"] = "Transparent.png"
else
containerArgs["AlternativeMap"] = "Blank.png"
end
containerArgs["caption"] = " "
if p.dots(frame) == "" then -- Don't make box if empty
return ""
end
div -- Creates box
:css('display','inline-block')
:css('float',args["align"] or 'right')
:css('margin','2px')
:css('padding','5px')
:css('background',args["color"] or 'none')
:wikitext(container(containerArgs))
if yesno(args['border']) ~= false then -- Creates box border
div
:css('border-style','solid')
:css('border-color','black')
:css('border-width','3px')
end
if args['align'] == 'center' then -- Centers output if needed
center
:addClass('center')
:css('width','auto')
:css('margin-left','auto')
:css('margin-right','auto')
:wikitext(tostring(div))
return center
else
return div
end
end
return p


