Modul:Timeline
Script error: The function "nonexistent" does not exist.
local p = {}
local function esc(s)
if not s then return "" end
return s:gsub("&","&"):gsub("<","<"):gsub(">",">")
end
local function yearToX(year, minYear, scale, startX)
return startX + (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 startX = 60
local padding = 80
local width = startX + (maxYear - minYear) * scale + padding
if width < 400 then width = 400 end
-- SVG početak
local svg = {}
table.insert(svg, string.format(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %d 300">',
width
))
-- pozadina
table.insert(svg, '<rect x="0" y="0" width="100%" height="300" fill="white" />')
-- vremenska os
table.insert(svg, '<g font-family="sans-serif" font-size="10" fill="#555">')
local xEnd = yearToX(maxYear, minYear, scale, startX)
table.insert(svg, string.format(
'<line x1="%d" y1="30" x2="%d" y2="30" stroke="#aaa" />',
startX, xEnd
))
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>')
-- crtanje redova
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)
local color = args["row" .. rowIndex .. "_color"] or "#cccccc"
-- label reda
table.insert(svg, string.format(
'<text x="10" y="%d" font-family="sans-serif" font-size="11" fill="#333">%s</text>',
y, esc(label)
))
-- blokovi u redu
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)] or ""
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 color
local x1 = yearToX(start, minYear, scale, startX)
local x2 = yearToX(stop, minYear, scale, startX)
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