Please note that some information on this wiki is still based on the demo version.
If you notice any errors, feel free to correct them.

Module:TreeChart

From Super Fantasy Kingdom Official Wiki

Displays a tree chart. If the chart should go upwards use up=true and enter the nodes in reverse order. Each node level is indicated by a dash at the start of the entry.

{{TreeChart
|up=true
|[[Combat]]
|-[[Stats]]
|--{{stat|dm|Damage}}
|--{{stat|sh|Shield}}
|--{{stat|cr|Critical Chance}}
|-[[Units]]
|--{{ItemLink|Deathpriest}}
|[[Characters]]
|-{{ItemLink|Merchant}}
|-{{ItemLink|Witch}}
}}

local p = {}

function p.treeChart(f)
	return p.create(f:getParent().args)
end

function p.create(args)	
	if args[1] == nil then
		return ''
	end
		
	local list = {}
	-- node content level is indicated by dashes before the content
	local currentLevel = 0
	for _,node in ipairs(args) do
		-- separate level indicator and content
		local nodeLevel, nodeContent = string.match(node, '^%s*(%-*)%s*(.-)%s*$')
		nodeLevel = string.len(nodeLevel)
		if nodeLevel > currentLevel then
			-- only one level up is allowed per entry
			table.insert(list, '<ul>')
		elseif nodeLevel < currentLevel then
			for i = currentLevel, nodeLevel + 1, -1 do
				table.insert(list, '</li></ul>')
			end
		elseif #list ~= 0 then
			table.insert(list, '</li>')
		end
			
		table.insert(list, p.createNode(nodeContent))
		currentLevel = nodeLevel
	end
	
	if 0 < currentLevel then
		for i = currentLevel , 1, -1 do
			table.insert(list, '</li></ul>')
		end
	end
		
	local classes = {}
	if p.parameterTrue(args.up) then
		table.insert(classes, 'treeup')
	end
	
	-- center is default, use left if not centered
	if not p.parameterTrue(args.center) then
		table.insert(classes, 'left')
	end
		
	return '<ul class="tree '..table.concat(classes, ' ')..'">'..table.concat(list, '')..'</ul>'
end

function p.createNode(nodeContent)
	return '<li><span>'..nodeContent..'</span>'
end

function p.parameterTrue(value)
    return value ~= nil and value ~= '' and string.lower(value) ~= 'false'
end

return p