Modul:Timeline
Script error: The function "nonexistent" does not exist.
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.maxYear) or 2015
local scale = tonumber(args.scale) or 65
local startX = 60
local rows = {
classic = { y = 60, color = "#bfc9ff" },
nano = { y = 100, color = "#c9f0b5" },
shuffle = { y = 140, color = "#ffd27f" },
touch = { y = 180, color = "#e0e0e0" }
}
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" />')
-- Godine
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" />')
for y = minYear, maxYear do
local x = yearToX(y, minYear, scale, startX)
table.insert(svg, string.format('<text x="%d" y="25">%d</text>', x, y))
end
table.insert(svg, '</g>')
-- Obrada modela
for key, row in pairs(rows) do
local i = 1
while args[key .. i .. "_start"] do
local start = tonumber(args[key .. i .. "_start"])
local stop = tonumber(args[key .. i .. "_end"])
local label = args[key .. i .. "_label"] or ""
local icon = args[key .. i .. "_icon"] or ""
local tip = args[key .. i .. "_tip"] or ""
local x1 = yearToX(start, minYear, scale, startX)
local x2 = yearToX(stop, minYear, scale, startX)
local width = x2 - x1
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, row.y - 5, width, row.color, esc(tip)
))
table.insert(svg, string.format(
'<text x="%d" y="%d">%s %s</text>',
x1 + 3, row.y + 5, icon, esc(label)
))
table.insert(svg, '</g>')
i = i + 1
end
end
table.insert(svg, '</svg>')
return table.concat(svg, "\n")
end
return p