Modul:Timeline: razlika između inačica

Izvor: Hrvatska internetska enciklopedija
Prijeđi na navigaciju Prijeđi na pretraživanje
Stvorena nova stranica sa sadržajem: »local p = {} -- Pretvara godinu u X koordinatu local function yearToX(year, minYear, scale, startX) return startX + (year - minYear) * scale end -- Escape za SVG local function esc(s) return s:gsub("&","&"):gsub("<","<"):gsub(">",">") end -- Glavna funkcija function p.ipod(frame) local args = frame:getParent().args -- Konfiguracija local minYear = tonumber(args.minYear) or 2001 local maxYear = tonumber(args.max...«.
 
Nema sažetka uređivanja
 
Nisu prikazane 2 međuinačice
Redak 1: Redak 1:
local p = {}
local p = {}


-- Pretvara godinu u X koordinatu
local function esc(s)
    if not s then return "" end
    return s:gsub("&","&amp;"):gsub("<","&lt;"):gsub(">","&gt;")
end
 
local function yearToX(year, minYear, scale, startX)
local function yearToX(year, minYear, scale, startX)
     return startX + (year - minYear) * scale
     return startX + (year - minYear) * scale
end
end


-- Escape za SVG
local function yearToY(year, minYear, scale, startY)
local function esc(s)
     return startY + (year - minYear) * scale
     return s:gsub("&","&amp;"):gsub("<","&lt;"):gsub(">","&gt;")
end
end


-- Glavna funkcija
function p.render(frame)
function p.ipod(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args


     -- Konfiguracija
     -- osnovne postavke
     local minYear = tonumber(args.minYear) or 2001
     local minYear = tonumber(args.minYear) or 2000
     local maxYear = tonumber(args.maxYear) or 2015
     local maxYear = tonumber(args.maxYear) or 2030
     local scale  = tonumber(args.scale) or 65
     local scale  = tonumber(args.scale)   or 60
     local startX  = 60
     local orientation = (args.orientation or "horizontal"):lower()


     local rows = {
     local startMain = 60
        classic = { y = 60,  color = "#bfc9ff" },
    local padding   = 80
        nano    = { y = 100, color = "#c9f0b5" },
        shuffle = { y = 140, color = "#ffd27f" },
        touch   = { y = 180, color = "#e0e0e0" }
    }


     local svg = {}
     local svg = {}
    table.insert(svg, '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 260">')


     -- Pozadina
     ---------------------------------------------------------
     table.insert(svg, '<rect x="0" y="0" width="1000" height="260" fill="white" />')
     -- VERTIKALNI TIMELINE
    ---------------------------------------------------------
    if orientation == "vertical" then
        local height = startMain + (maxYear - minYear) * scale + padding
        if height < 300 then height = 300 end
 
        table.insert(svg, string.format(
            '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 %d">',
            height
        ))
        table.insert(svg, '<rect x="0" y="0" width="100%" height="100%" fill="white" />')
 
        -- vremenska os
        table.insert(svg, '<g font-family="sans-serif" font-size="10" fill="#555">')
        local yEnd = yearToY(maxYear, minYear, scale, startMain)
        table.insert(svg, string.format(
            '<line x1="80" y1="%d" x2="80" y2="%d" stroke="#aaa" />',
            startMain, yEnd
        ))


     -- Godine
        for y = minYear, maxYear do
            local yy = yearToY(y, minYear, scale, startMain)
            table.insert(svg, string.format('<text x="50" y="%d">%d</text>', yy + 4, y))
        end
        table.insert(svg, '</g>')
 
        -- redovi
        local rowIndex = 1
        while args["row" .. rowIndex .. "_label"] do
            local label = args["row" .. rowIndex .. "_label"]
            local x    = tonumber(args["row" .. rowIndex .. "_x"]) or (120 + (rowIndex - 1) * 120)
 
            table.insert(svg, string.format(
                '<text x="%d" y="40" font-family="sans-serif" font-size="11" fill="#333">%s</text>',
                x, esc(label)
            ))
 
            local blockIndex = 1
            while args[string.format("row%d_block%d_start", rowIndex, blockIndex)] do
                local start = tonumber(args[string.format("row%d_block%d_start", rowIndex, blockIndex)])
                local stop  = tonumber(args[string.format("row%d_block%d_end",  rowIndex, blockIndex)]) or maxYear
                local text  = args[string.format("row%d_block%d_label", rowIndex, blockIndex)] or ""
                local tip  = args[string.format("row%d_block%d_tip",  rowIndex, blockIndex)]
                local icon  = args[string.format("row%d_block%d_icon",  rowIndex, blockIndex)] or ""
                local col  = args[string.format("row%d_block%d_color", rowIndex, blockIndex)] or "#cccccc"
 
                if not tip or tip == "" then
                    tip = string.format("%s (%s–%s)", text, tostring(start), tostring(stop))
                end
 
                local y1 = yearToY(start, minYear, scale, startMain)
                local y2 = yearToY(stop,  minYear, scale, startMain)
                local h  = y2 - y1
                if h < 6 then h = 6 end
 
                table.insert(svg, '<g font-family="sans-serif" font-size="9" fill="#000">')
                table.insert(svg, string.format(
                    '<rect x="%d" y="%d" width="90" height="%d" fill="%s"><title>%s</title></rect>',
                    x - 10, y1, h, esc(col), esc(tip)
                ))
 
                local labelText = icon ~= "" and (icon .. " " .. esc(text)) or esc(text)
 
                table.insert(svg, string.format(
                    '<text x="%d" y="%d" transform="rotate(90 %d %d)">%s</text>',
                    x + 5, y1 + h/2, x + 5, y1 + h/2, labelText
                ))
                table.insert(svg, '</g>')
 
                blockIndex = blockIndex + 1
            end
 
            rowIndex = rowIndex + 1
        end
 
        table.insert(svg, '</svg>')
        return table.concat(svg, "\n")
    end
 
    ---------------------------------------------------------
    -- HORIZONTALNI TIMELINE
    ---------------------------------------------------------
    local width = startMain + (maxYear - minYear) * scale + padding
    if width < 400 then width = 400 end
 
    table.insert(svg, string.format(
        '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %d 300">',
        width
    ))
    table.insert(svg, '<rect x="0" y="0" width="100%" height="100%" fill="white" />')
 
     -- vremenska os
     table.insert(svg, '<g font-family="sans-serif" font-size="10" fill="#555">')
     table.insert(svg, '<g font-family="sans-serif" font-size="10" fill="#555">')
     table.insert(svg, '<line x1="60" y1="30" x2="980" y2="30" stroke="#aaa" />')
    local xEnd = yearToX(maxYear, minYear, scale, startMain)
     table.insert(svg, string.format(
        '<line x1="%d" y1="30" x2="%d" y2="30" stroke="#aaa" />',
        startMain, xEnd
    ))


     for y = minYear, maxYear do
     for y = minYear, maxYear do
         local x = yearToX(y, minYear, scale, startX)
         local xx = yearToX(y, minYear, scale, startMain)
         table.insert(svg, string.format('<text x="%d" y="25">%d</text>', x, y))
         table.insert(svg, string.format('<text x="%d" y="25">%d</text>', xx, y))
     end
     end
     table.insert(svg, '</g>')
     table.insert(svg, '</g>')


     -- Obrada modela
     -- redovi
     for key, row in pairs(rows) do
     local rowIndex = 1
         local i = 1
    while args["row" .. rowIndex .. "_label"] do
         while args[key .. i .. "_start"] do
         local label = args["row" .. rowIndex .. "_label"]
             local start = tonumber(args[key .. i .. "_start"])
         local y    = tonumber(args["row" .. rowIndex .. "_y"]) or (50 + rowIndex * 40)
             local stop  = tonumber(args[key .. i .. "_end"])
 
             local label = args[key .. i .. "_label"] or ""
        table.insert(svg, string.format(
             local icon  = args[key .. i .. "_icon"] or ""
            '<text x="10" y="%d" font-family="sans-serif" font-size="11" fill="#333">%s</text>',
             local tip   = args[key .. i .. "_tip"] or ""
            y, esc(label)
        ))
 
        local blockIndex = 1
        while args[string.format("row%d_block%d_start", rowIndex, blockIndex)] do
             local start = tonumber(args[string.format("row%d_block%d_start", rowIndex, blockIndex)])
             local stop  = tonumber(args[string.format("row%d_block%d_end",  rowIndex, blockIndex)]) or maxYear
             local text  = args[string.format("row%d_block%d_label", rowIndex, blockIndex)] or ""
            local tip  = args[string.format("row%d_block%d_tip",  rowIndex, blockIndex)]
             local icon  = args[string.format("row%d_block%d_icon",  rowIndex, blockIndex)] or ""
             local col   = args[string.format("row%d_block%d_color", rowIndex, blockIndex)] or "#cccccc"
 
            if not tip or tip == "" then
                tip = string.format("%s (%s–%s)", text, tostring(start), tostring(stop))
            end


             local x1 = yearToX(start, minYear, scale, startX)
             local x1 = yearToX(start, minYear, scale, startMain)
             local x2 = yearToX(stop,  minYear, scale, startX)
             local x2 = yearToX(stop,  minYear, scale, startMain)
             local width = x2 - x1
             local = x2 - x1
            if w < 6 then w = 6 end


             table.insert(svg, '<g font-family="sans-serif" font-size="9" fill="#000">')
             table.insert(svg, '<g font-family="sans-serif" font-size="9" fill="#000">')
             table.insert(svg, string.format(
             table.insert(svg, string.format(
                 '<rect x="%d" y="%d" width="%d" height="14" fill="%s"><title>%s</title></rect>',
                 '<rect x="%d" y="%d" width="%d" height="14" fill="%s"><title>%s</title></rect>',
                 x1, row.y - 5, width, row.color, esc(tip)
                 x1, y - 10, w, esc(col), esc(tip)
             ))
             ))
            local labelText = icon ~= "" and (icon .. " " .. esc(text)) or esc(text)
             table.insert(svg, string.format(
             table.insert(svg, string.format(
                 '<text x="%d" y="%d">%s %s</text>',
                 '<text x="%d" y="%d">%s</text>',
                 x1 + 3, row.y + 5, icon, esc(label)
                 x1 + 3, y, labelText
             ))
             ))
             table.insert(svg, '</g>')
             table.insert(svg, '</g>')


             i = i + 1
             blockIndex = blockIndex + 1
         end
         end
        rowIndex = rowIndex + 1
     end
     end



Posljednja izmjena od 12. siječanj 2026. u 13:02

Script error: The function "nonexistent" does not exist.

local p = {}

local function esc(s)
    if not s then return "" end
    return s:gsub("&","&amp;"):gsub("<","&lt;"):gsub(">","&gt;")
end

local function yearToX(year, minYear, scale, startX)
    return startX + (year - minYear) * scale
end

local function yearToY(year, minYear, scale, startY)
    return startY + (year - minYear) * scale
end

function p.render(frame)
    local args = frame:getParent().args

    -- osnovne postavke
    local minYear = tonumber(args.minYear) or 2000
    local maxYear = tonumber(args.maxYear) or 2030
    local scale   = tonumber(args.scale)   or 60
    local orientation = (args.orientation or "horizontal"):lower()

    local startMain = 60
    local padding   = 80

    local svg = {}

    ---------------------------------------------------------
    -- VERTIKALNI TIMELINE
    ---------------------------------------------------------
    if orientation == "vertical" then
        local height = startMain + (maxYear - minYear) * scale + padding
        if height < 300 then height = 300 end

        table.insert(svg, string.format(
            '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 %d">',
            height
        ))
        table.insert(svg, '<rect x="0" y="0" width="100%" height="100%" fill="white" />')

        -- vremenska os
        table.insert(svg, '<g font-family="sans-serif" font-size="10" fill="#555">')
        local yEnd = yearToY(maxYear, minYear, scale, startMain)
        table.insert(svg, string.format(
            '<line x1="80" y1="%d" x2="80" y2="%d" stroke="#aaa" />',
            startMain, yEnd
        ))

        for y = minYear, maxYear do
            local yy = yearToY(y, minYear, scale, startMain)
            table.insert(svg, string.format('<text x="50" y="%d">%d</text>', yy + 4, y))
        end
        table.insert(svg, '</g>')

        -- redovi
        local rowIndex = 1
        while args["row" .. rowIndex .. "_label"] do
            local label = args["row" .. rowIndex .. "_label"]
            local x     = tonumber(args["row" .. rowIndex .. "_x"]) or (120 + (rowIndex - 1) * 120)

            table.insert(svg, string.format(
                '<text x="%d" y="40" font-family="sans-serif" font-size="11" fill="#333">%s</text>',
                x, esc(label)
            ))

            local blockIndex = 1
            while args[string.format("row%d_block%d_start", rowIndex, blockIndex)] do
                local start = tonumber(args[string.format("row%d_block%d_start", rowIndex, blockIndex)])
                local stop  = tonumber(args[string.format("row%d_block%d_end",   rowIndex, blockIndex)]) or maxYear
                local text  = args[string.format("row%d_block%d_label", rowIndex, blockIndex)] or ""
                local tip   = args[string.format("row%d_block%d_tip",   rowIndex, blockIndex)]
                local icon  = args[string.format("row%d_block%d_icon",  rowIndex, blockIndex)] or ""
                local col   = args[string.format("row%d_block%d_color", rowIndex, blockIndex)] or "#cccccc"

                if not tip or tip == "" then
                    tip = string.format("%s (%s–%s)", text, tostring(start), tostring(stop))
                end

                local y1 = yearToY(start, minYear, scale, startMain)
                local y2 = yearToY(stop,  minYear, scale, startMain)
                local h  = y2 - y1
                if h < 6 then h = 6 end

                table.insert(svg, '<g font-family="sans-serif" font-size="9" fill="#000">')
                table.insert(svg, string.format(
                    '<rect x="%d" y="%d" width="90" height="%d" fill="%s"><title>%s</title></rect>',
                    x - 10, y1, h, esc(col), esc(tip)
                ))

                local labelText = icon ~= "" and (icon .. " " .. esc(text)) or esc(text)

                table.insert(svg, string.format(
                    '<text x="%d" y="%d" transform="rotate(90 %d %d)">%s</text>',
                    x + 5, y1 + h/2, x + 5, y1 + h/2, labelText
                ))
                table.insert(svg, '</g>')

                blockIndex = blockIndex + 1
            end

            rowIndex = rowIndex + 1
        end

        table.insert(svg, '</svg>')
        return table.concat(svg, "\n")
    end

    ---------------------------------------------------------
    -- HORIZONTALNI TIMELINE
    ---------------------------------------------------------
    local width = startMain + (maxYear - minYear) * scale + padding
    if width < 400 then width = 400 end

    table.insert(svg, string.format(
        '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %d 300">',
        width
    ))
    table.insert(svg, '<rect x="0" y="0" width="100%" height="100%" fill="white" />')

    -- vremenska os
    table.insert(svg, '<g font-family="sans-serif" font-size="10" fill="#555">')
    local xEnd = yearToX(maxYear, minYear, scale, startMain)
    table.insert(svg, string.format(
        '<line x1="%d" y1="30" x2="%d" y2="30" stroke="#aaa" />',
        startMain, xEnd
    ))

    for y = minYear, maxYear do
        local xx = yearToX(y, minYear, scale, startMain)
        table.insert(svg, string.format('<text x="%d" y="25">%d</text>', xx, y))
    end
    table.insert(svg, '</g>')

    -- redovi
    local rowIndex = 1
    while args["row" .. rowIndex .. "_label"] do
        local label = args["row" .. rowIndex .. "_label"]
        local y     = tonumber(args["row" .. rowIndex .. "_y"]) or (50 + rowIndex * 40)

        table.insert(svg, string.format(
            '<text x="10" y="%d" font-family="sans-serif" font-size="11" fill="#333">%s</text>',
            y, esc(label)
        ))

        local blockIndex = 1
        while args[string.format("row%d_block%d_start", rowIndex, blockIndex)] do
            local start = tonumber(args[string.format("row%d_block%d_start", rowIndex, blockIndex)])
            local stop  = tonumber(args[string.format("row%d_block%d_end",   rowIndex, blockIndex)]) or maxYear
            local text  = args[string.format("row%d_block%d_label", rowIndex, blockIndex)] or ""
            local tip   = args[string.format("row%d_block%d_tip",   rowIndex, blockIndex)]
            local icon  = args[string.format("row%d_block%d_icon",  rowIndex, blockIndex)] or ""
            local col   = args[string.format("row%d_block%d_color", rowIndex, blockIndex)] or "#cccccc"

            if not tip or tip == "" then
                tip = string.format("%s (%s–%s)", text, tostring(start), tostring(stop))
            end

            local x1 = yearToX(start, minYear, scale, startMain)
            local x2 = yearToX(stop,  minYear, scale, startMain)
            local w  = x2 - x1
            if w < 6 then w = 6 end

            table.insert(svg, '<g font-family="sans-serif" font-size="9" fill="#000">')
            table.insert(svg, string.format(
                '<rect x="%d" y="%d" width="%d" height="14" fill="%s"><title>%s</title></rect>',
                x1, y - 10, w, esc(col), esc(tip)
            ))

            local labelText = icon ~= "" and (icon .. " " .. esc(text)) or esc(text)

            table.insert(svg, string.format(
                '<text x="%d" y="%d">%s</text>',
                x1 + 3, y, labelText
            ))
            table.insert(svg, '</g>')

            blockIndex = blockIndex + 1
        end

        rowIndex = rowIndex + 1
    end

    table.insert(svg, '</svg>')
    return table.concat(svg, "\n")
end

return p