Modul:TreeChart
Vzhled
TreeChart může být použit k vytvoření rodokmenů, kladogramů a jiných stromů.
Použití
Modul podle zadaného klíče seskládá čtverec spojení položek grafu. Pro každý vyplněný směr (po směru hodinových ručiček: A vzhůru, B vpravo, C dolů, D vlevo) zobrazí čáru. Pokud je za písmenem ještě vlnovka, zobrazí přerušovanou čáru, pokud P, zobrazí tečkovanou čáru. Používá se ve dvojici, první s označením 1 tvoří první řádek modulu, druhá s označením 2 tvoří druhý řádek modulu.
Modul byl specificky připraven pro šablonu Šablona:Rodokmen/step2. Použití modulu v šabloně vypadá následovně:
{{Rodokmen/step2
|row1 "on2"={{#invoke:TreeChart|treechart|A~BP|1}}|
|row2 "on2"={{#invoke:TreeChart|treechart|A~BP|2}}|
}}
⇓ VÝSTUP ŠABLONY ⇓
Chyba Lua na řádku 26: bad argument #1 to 'sub' (string expected, got nil).Chyba Lua na řádku 26: bad argument #1 to 'sub' (string expected, got nil).⇑ VÝSTUP ŠABLONY ⇑
local p = {}
function p.treechart (frame)
local pattern = frame.args[1]
local char = frame.args[2]
local dirs = {'A', 'B', 'C', 'D'}
local res = {}
local row1 = '|row1 "' .. char .. '"=<td colspan="2" style="$1$"><div style="width: 1em; height: 1em;"><span style="font: 1px/1px serif;"> </span></div></td><td colspan="2" style="$1$"><div style="width: 1em; height: 1em;"><span style="font: 1px/1px serif;"> </span></div></td>|'
local row2 = '|row2 "' .. char .. '"=<td colspan="2" style="$1$"><div style="width: 1em; height: 1em;"><span style="font: 1px/1px serif;"> </span></div></td><td colspan="2" style="$1$"><div style="width: 1em; height: 1em;"><span style="font: 1px/1px serif;"> </span></div></td>|'
local type = ''
for _, dir in pairs(dirs) do
match = string.match(pattern, dir .. '([^ABCD]*)')
if match then
table.insert(res, match[0])
table.insert(res, match[1])
table.insert(res, match[2])
table.insert(res, match)
if match[2] == '~' then
type = 'dashed'
elseif match[2] == 'P' then
type = 'dotted'
else
type = 'solid'
end
if string.sub(match[1], 1, 1) == 'A' then
row1 = string.gsub(row1, '\$1\$', 'border-right:1px ' .. type .. ' black$1$')
elseif string.sub(match[1], 1, 1) == 'B' then
row1 = string.gsub(row1, '\$1\$', 'border-bottom:1px ' .. type .. ' black$1$')
elseif string.sub(match[1], 1, 1) == 'C' then
row2 = string.gsub(row1, '\$1\$', 'border-left:1px ' .. type .. ' black$1$')
elseif string.sub(match[1], 1, 1) == 'D' then
row2 = string.gsub(row1, '\$1\$', 'border-top:1px ' .. type .. ' black$1$')
end
end
end
row1 = string.gsub(row1, '\$1\$', '')
row2 = string.gsub(row2, '\$1\$', '')
--table.insert(res, row1)
--table.insert(res, row2)
return table.concat(res)
end
return p