Jump to content

Module:Wnt/Templates/Plotter

Unchecked
From Wikipedia

Documentation for this module may be created at Module:Wnt/Templates/Plotter/doc

local p={}

function p.main(frame)
    local args=frame.args
    local icon=args.icon
    local iconradius=args.iconradius or 10
    local lineicon=args.lineicon or "•"
    local lineiconradius=args.lineiconradius or 5
    local linefix=iconradius-lineiconradius
    local plotsizex = frame.args.plotsizex or 100
    local plotsizey = frame.args.plotsizey or 100
    local plotstep = frame.args.plotstep or 10
    local output = [[<div style="position:relative;border-style:solid;border-color: #0077ff;width:]] .. plotsizex+(2*iconradius) .. [[px;height:]] .. plotsizey+(2*iconradius) .. [[px;">]]
    if args[2] ~= nil then
        local x=args[1]+0
        local y=args[2]+0
        local xmin = x
        local xmax = x
        local ymin = y
        local ymax = y
        local index = 3
        while args[index+1] ~= nil do
           local x=args[index]+0
           local y=args[index+1]+0
           if (x < xmin) then xmin = x end
           if (x > xmax) then xmax = x end
           if (y < ymin) then ymin = y end
           if (y > ymax) then ymax = y end
           index = index + 2
        end
        local lastx=0
        local lasty=0
        if args[2] ~= nil then
            local x=args[1]+0
            local y=args[2]+0
            local plotx=math.floor(plotsizex*(x-xmin)/(xmax-xmin))
            local ploty=math.floor((plotsizey-plotsizey*(y-ymin)/(ymax-ymin)))
            output = output .. [[<span style="position:absolute;left:]] .. plotx .. [[px; top:]] .. ploty .. [[px;">]] .. icon .. "</span>"
            lastx = plotx
            lasty = ploty
        end
        index = 3
        while args[index+1] ~= nil do
            local x=args[index]+0
            local y=args[index+1]+0
            local plotx=math.floor(plotsizex*(x-xmin)/(xmax-xmin))
            local ploty=math.floor((plotsizey-plotsizey*(y-ymin)/(ymax-ymin)))
            if plotstep+0 ~= 0 then
               local delx=plotx-lastx
               local dely=ploty-lasty
               plotdist=math.sqrt(delx*delx+dely*dely)
               plotparm=plotdist-iconradius-plotstep/2
               while plotparm>iconradius+lineiconradius+plotstep/2 do
                  output = output .. [[<span style="position:absolute;left:]] .. lastx+linefix+math.floor(delx*(plotparm/plotdist)) .. [[px; top:]] .. lasty+linefix+math.floor(dely*(plotparm/plotdist)) .. [[px;">]] .. lineicon .. "</span>"
                  plotparm = plotparm - plotstep
               end
               lastx = plotx
               lasty = ploty
            end
            output = output .. [[<span style="position:absolute;left:]] .. plotx .. [[px; top:]] .. ploty .. [[px;">]] .. icon .. "</span>"
            index = index + 2
        end
    else output = "error"
    end
    output = output .. "</div>"
    return output
end
return p