Jump to content

Module:Plotter

विकिपीडिया से
en>Wnt (Very basic module to plot arbitrary X-Y numeric data. Not very useful yet because I haven't worked out a way to label the axes, but at this very early stage in adoption might as well demonstrate.) के द्वारा 05:42, 22 फरवरी 2013 के बदलाव
(अंतर) ← पुरान बदलाव | हाल के संसोधन (अंतर) | नया बदलाव → (अंतर)
local p={}

function p.main(frame)
    local args=frame.args
    local icon=args.icon
    local iconradius=args.iconradius or 0
    local plotsizex = frame.args.plotsize or 100
    local plotsizey = frame.args.plotsizey or 100
    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
        index = 1
        while args[index+1] ~= nil do
            local x=args[index]+0
            local y=args[index+1]+0
            output = output .. [[<span style="position:absolute;left:]] .. math.floor(plotsizex*(x-xmin)/(xmax-xmin)) .. [[px; top:]] .. math.floor((plotsizey-plotsizey*(y-ymin)/(ymax-ymin))) .. [[px;">]] .. icon .. "</span>"
            index = index + 2
        end
    else output = "error"
    end
    output = output .. "</div>"
    return output
end
return p