Aller au contenu

Module:Plotter

Une page de Wikipédia, l'encyclopédie libre.
Ceci est une version archivée de cette page, en date du 22 février 2013 à 07:42 et modifiée en dernier par Wnt (discuter | contributions) (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.). Elle peut contenir des erreurs, des inexactitudes ou des contenus vandalisés non présents dans la version actuelle.
(diff) ← Version précédente | Version actuelle (diff) | Version suivante → (diff)

 Documentation[créer] [purger]
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