Module:Tree Chart

Usage

This template produces one row in a "family tree"-like chart consisting of boxes and connecting lines based loosely on an ASCII art-like syntax. It is meant to be used in conjunction with Tree Chart/start and Tree Chart/end. The chart is displayed as HTML tables using CSS attributes, and may contain arbitrary wiki markup within the boxes. This implementation was based on the now-deprecated family tree template.

Basic example

This code:

{{Tree Chart/start|align=center|summary=An example family tree}}
{{Tree Chart| | | |GEORGEI |-|v|-| MARY | |GEORGEI=[[George Joestar I]]|MARY=[[Mary Joestar]]}}
{{Tree Chart| | | | | | | |)|-|-|-|.| }}
{{Tree Chart| | | ERINA |v| JONATHAN | |DIO|ERINA=[[Erina Pendleton]]|JONATHAN=[[Jonathan Joestar]]|DIO=[[Dio Brando]]}}
{{Tree Chart| |,|-|-|-|+|-|-|-|.| | | }}
{{Tree Chart| GEORGEII | | KID1  | | KID2 | | |GEORGEII=[[George Joestar II]]|KID1=George's Imaginary Brother|KID2=George's Imaginary Sister}}
{{Tree Chart/end}}

produces this:

George Joestar IMary Joestar
Erina PendletonJonathan JoestarDio Brando
George Joestar IIGeorge's Imaginary BrotherGeorge's Imaginary Sister

This chart visually displays the information that George Joestar II has an imaginary brother and sister; his mom Erina married his dad Jonathan Joestar; his dad's parents were George Joestar I and Mary Joestar; and his dad had a brother named Dio. The code above produces a table of size 9 rows x 18 columns.

Parameters

The template accepts any number of unnamed parameters with each parameter specifying a tile or a box.

  • Boxes can contain arbitrary wiki markup. The content of each box is specified using additional named parameters appended to the template call. Each box is three tiles wide and normally has a black border two pixels wide. Boxes can have any name that is a valid template parameter name, subject to a minimum of two alphabetical characters.
  • Tiles are line drawing symbols used to connect the boxes. They consist of various styles of horizontal and vertical lines along with corners and crossings as needed. Tiles are specified using their one- or two-character name: for the most common tiles, that character is more or less approximate to the tile's appearance. A special case of a tile is the empty tile, specified by a single space character. A table of available tiles is given below.
Solid lines:
!
  ,
  v
  .
 
-
  )
  +
  (
 
`
  ^
  '
 
Dashed lines:
:
  F
  V
  7
 
~
  D
  %
  C
 
L
  A
  J
 
Dotted lines:
Q
  S
  M
  T
 
P
  H
  R
  G
 
Y
  W
  Z
 
Horiz dashed, vert solid:
fy
y
ye
f
t
e
fh
h
he
Horiz solid, vert dashed:
dj
j
jc
d
*
c
di
i
ic
Horiz solid, vert dotted:
kr
r
rl
k
a
l
kq
q
ql
Horiz dashed, vert dotted:
kr2
r2
rl2
k2
a2
l2
kq2
q2
ql2
Horiz dotted, vert solid:
om
m
mp
o
b
p
on
n
np
Horiz dotted, vert dashed:
om2
m2
mp2
o2
b2
p2
on2
n2
np2


Miscellaneous:
k3
T2
l3
l4
G2
T4
b3
E
K
U
X
X2
T3
T
X2
np
np2


Style attributes

The appearance of the boxes in a row may be controlled by the following optional template parameters:

  • border specifies the width of the box border in pixels,
  • boxstyle can be used to append arbitrary CSS declarations directly to the box style attributes. For example, the following code:
{{Tree Chart/start}}
{{Tree Chart|border=1|boxstyle=color:white; background:green; | | FOO |y| BAR | |FOO=Box 1|BAR=Box 2}}
{{Tree Chart| | |,|-|^|-|.| | }}
{{Tree Chart|border=3|boxstyle=background:yellow; | | FOO | | BAR | |FOO=Box 3|BAR=Box 4}}
{{Tree Chart/end}}

produces this chart:

Box 1Box 2
Box 3Box 4

Style attributes can even be set for individual boxes within each row, as in the example below:

{{Tree Chart/start}}
{{Tree Chart| | | | |CLEAR| | | | |CLEAR=Clear box}}
{{Tree Chart| |,|-|-|'|!|`|-|-|.| }}
{{Tree Chart|RED  |~|GREEN|~|BLUE |RED=Red box|GREEN=Green box|BLUE=Blue box
|boxstyle_RED  =color:white; background-color: red;
|boxstyle_GREEN=color:yellow; background-color: green;
|boxstyle_BLUE =color:white; background-color: blue;
}}
{{Tree Chart/end}}

which produces this:

Clear box
Red boxGreen boxBlue box

Note: When specifying style attributes for individual named boxes, make sure the box names are aligned to the left side of the area reserved for them in the template call (as in "|RED  |" instead of "| RED |" in the example above), otherwise the template will end up looking for a style parameter with spaces in its name.

The Tree Chart/start template also accepts an optional |style= parameter that can be used to set CSS styles for the entire diagram, and an optional |align= parameter to set the chart alignment.


require('strict')

local p = {}

local cells = mw.loadData('Module:Tree Chart/data')

function p._main(cell_args)
	local ret = mw.html.create()
	local top = ret:tag('tr')
						:css{ height = '1px',
								['text-align'] = 'center' }
	local bottom = ret:tag('tr')
						:css{ height = '1px',
								['text-align'] = 'center' }
	for _, v in ipairs(cell_args) do
		if type(v) == 'string' then
			top:wikitext(cells[v].t)
			bottom:wikitext(cells[v].b)
		else
			top:tag('td')
				:attr{ colspan = v.colspan or cell_args.colspan or 6,
						rowspan = v.rowspan or cell_args.rowspan or 2 }
				:css{ padding = '0.2em',
						border = (v.border or cell_args.border or '2') .. 'px solid' }
				:cssText(v.boxstyle or cell_args.boxstyle)
				:addClass('familytree familytree-box')
				:wikitext(v.text)
		end
	end
	return tostring(ret)
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Tree Chart', trim = false, removeBlanks = false})
	local cell_args = {
		colspan = args.colspan,
		rowspan = args.rowspan,
		border = args.border,
		boxstyle = args.boxstyle
	}
	for _, val in ipairs(args) do
		local trimmedVal = val:match('^%s*(.-)%s*$')
		if trimmedVal == '' then
			trimmedVal = '$'
		end
		if cells[trimmedVal] then
			table.insert(cell_args, trimmedVal)
		else
			-- Unnamed params behave weirdly
			-- white space at the front counts for param_{{{1}}}, but not whitespace at the end, so remove it
			local rightTrimmedVal = val:gsub('%s+$','')
			table.insert(cell_args, {
				text = args[trimmedVal] or ('{{{'..trimmedVal..'}}}'),
				colspan = args['colspan_'..rightTrimmedVal],
				rowspan = args['rowspan_'..rightTrimmedVal],
				border = args['border_'..rightTrimmedVal],
				boxstyle = args['boxstyle_'..rightTrimmedVal]
			})
		end
	end
	
	return p._main(cell_args)
end

return p