Difference between revisions of "Template:Cladex/doc"
imported>Peter coxhead m (→Debugging: small addition) |
imported>Peter coxhead m (→Debugging: corrected format) |
||
| Line 372: | Line 372: | ||
If your cladogram doesn't display brackets/bars as you expected, check that: | If your cladogram doesn't display brackets/bars as you expected, check that: | ||
| − | * You understand the numbering system for the parameters <tt>barN<tt>, etc. The N must be the same as the number of the child within its clade. Thus typically you should write <tt>|N=''label for leaf''|barN=''colour for bar''</tt>, e.g. <tt>|2=[[Passeridae]]|bar2=midnightblue</tt>. | + | * You understand the numbering system for the parameters <tt>barN<tt>, etc. The N must be the same as the number of the child within its clade. Thus typically you should write <tt>|N=''label for leaf''|barN=''colour for bar''</tt>, e.g. <tt>|2=<nowiki>[[Passeridae]]</nowiki>|bar2=midnightblue</tt>. |
* You have only attempted to apply brackets/bars to ''leaf'' nodes. | * You have only attempted to apply brackets/bars to ''leaf'' nodes. | ||
* Either the outermost clade uses {{tl|Clade}} or if it has to use <nowiki>{{</nowiki>Cladex<nowiki>}}</nowiki>, then <tt>|style=width:auto</tt> is present. | * Either the outermost clade uses {{tl|Clade}} or if it has to use <nowiki>{{</nowiki>Cladex<nowiki>}}</nowiki>, then <tt>|style=width:auto</tt> is present. | ||
Revision as of 10:33, 1 July 2011
| This is a documentation subpage for Template:Cladex. It contains usage information, categories and other content that is not part of the original template page. |
This template is an eXtended version of {{Clade}}, hence the name. Both templates are for drawing branching trees with the node and base labels being clickable links. Such diagrams are especially suited to represent evolutionary trees (cladograms).
Most of the documentation is the same as the parent template, {{Clade}}, and is included below for convenience. Unless the two extra features of {{Cladex}} are needed, you are advised to use {{Clade}}.
The two extra features of {{Cladex}} are:
- Double lines leading to a node can be produced as easily as dotted lines.
- Brackets or bars of a chosen colour can be placed to the right of a set of leaf nodes in the cladogram, thus allowing paraphyletic groups to be identified. See #Bracketting nodes. Text labels for these brackets/bars can be provided using {{Barlabel}}.
{{Clade}} and {{Cladex}} can be freely mixed, so if only some clades require the extra features, only these need be specified using {{Cladex}}.
Contents
Basic features
Use {{Clade}} unless the extra features of {tl|Cladex}} are needed.
Usage
{{clade
|label1=Base
|1=Node
}}
produces
| Base |
Node |
{{clade
|1={{clade
|label1=[[Subtree1]]
|1=Leaf1
|label2=Subtree2
|2=[[Leaf2]]
}}
}}
produces
| |||||||
{{clade| style=font-size:75%;line-height:75%
|1={{clade
|label1=Subtree1
|1=Leaf1
|label2=Subtree2
|2=Leaf2
}}
}}
produces
| |||||||
Note that the order of the parameters does not matter. Exactly the same output is produced by
{{clade| style=font-size:75%;line-height:75%
|1={{clade
|2=Leaf2
|1=Leaf1
|label1=Subtree1
|label2=Subtree2
}}
}}
| |||||||
{{clade
|1={{clade
|1={{clade | thickness=3
|1=Leaf1
|2=Leaf2
}}
|2=Leaf3
}}
}}
produces
| |||||||||||||
To replace a solid line leading to the Nth child with a dashed line, use |stateN=dashed.
{{clade
|1={{clade
|1={{clade
|1=Leaf1|state1=dashed
|2=Leaf2
}}
|2=Leaf3
}}
}}
produces
| |||||||||||||
{{Cladex}} only. To replace a single line leading to the Nth child by a double line, use |stateN=double. Notice that {{Cladex}} has only been used for the (sub)clade where the double line is wanted. The outermost clade should always be specified with {{Clade}} unless its style is altered – see below.
{{clade
|1={{clade
|1={{cladex
|1=Leaf1
|2=Leaf2|state2=double
}}
|2=Leaf3
}}
}}
produces
| |||||||||||||
Tips
An easy way of creating larger cladograms is to use the Newick format and proceed to edit it using a suitable text editor to produce the markup.
- Start with Newick format ((a,b),(c,d))
- Replace "(" with "{{clade|"
- Replace ")" with "}}"
- Edit to replace commas with pipes and numbers
- Edit clade labels if needed
{{clade
|1={{clade
|1=a
|2=b
}}
|2={{clade
|1=c
|2=d
}}
}}
Example Perl script to automate the conversion:
use constant N=>"\n";
use constant T=>"\t";
my $tree='((a,b),(c,d));'; # get sequence
$tree=~s/[\n\r]//g; # loose those spaces
$tree=~ s/\:[\.\d]+//g; # loose those lengths
while ($tree=~ m/\(/) {
foreach my $clade ($tree=~ m/\(([^\(\)]+)\)/g) {
my @branches=split /\,/,$clade;
s/(\t+)/$1\t/g for @branches;
die 'ERROR: degenerate/empty node!'.N if $#branches<1;
$tree=~ s/\(\Q$clade\E\)/${\join('','{{clade',N,map(T.'|'.($_+1).'='.$branches[$_].N,0..$#branches),T.'}}')}/; # substitute
}
pos($tree)=0;
}
$tree=~s/(\t*)\t\}\}/$1\}\}/g; # lazy fix
print $tree;
Using a box
You can nest the templates and use links around the text. You may use non-breaking spaces ( ) to obtain spaces or to have labels that have spaces.
The entire cladogram can be placed in a box so that text flows nicely around it. You can use Template:Tl:Cladogram to produce the box.
| Example | |||||||||||||||||||||||||||
| |||||||||||||||||||||||||||
| Sample of Template:Tl:Cladogram |
{{cladogram|title=Example
|caption=Sample of {{tl:Cladogram}}
|clades={{clade| style=font-size:75%;line-height:75%
|label1=[[Neornithes]]
|1={{clade
|label1=[[Paleognathae]]
|1=
|label2= [[Neognathae]]
|2={{clade
|1=Other birds
|label1=
|label2=[[Galloanserae]]
|2={{clade
|1=[[Anseriformes]]
|label2=
|2={{clade
|1=[[Galliformes]]
|2=[[Craciformes]]
}}
}}
}}
}}
}}
}}
Bracketting nodes
{{Cladex}} only. To insert a coloured 'bracket' around a set of leaf nodes which follow one another in the generated cladogram:
- Add barbeginN=colour for the first leaf node, where N is the order of that leaf node within its clade, and colour is the required colour.
- Add barN=colour for the remaining nodes other than the last (note that N must be the order of that node within its clade).
- Add barendN=colour for the last node.
Either the outermost clade must be specified by {{Clade}} or if {{Cladex}} is needed there, |style=width:auto must be present.
{{clade|style=font-size:85%;line-height:100%
|1={{cladex
|1=Leaf A
|2=Leaf B|barbegin2=green
|3=Leaf C|bar3=green
|4={{cladex
|1=Leaf D|barend1=green
|2=Leaf E
|3=Leaf F|barbegin3=purple
|4={{cladex
|1=Leaf G|bar1=purple
|2=Leaf H|barend2=purple
}}
}}
}}
}}
produces
| |||||||||||||||||||||||||||||||
The horizontal lines can be omitted by using |barN=colour throughout. Thus the following (note the use of |style=width:auto since the outermost clade uses the extra features of {{Cladex}}):
{{cladex|style=width:auto;font-size:85%;line-height:100%
|1=Leaf A
|2={{cladex
|1=Leaf B|bar1=midnightblue
|2=Leaf C|bar2=midnightblue
}}
|3=Leaf D|bar3=midnightblue
}}
produces
|
Leaf A | |||||||
| |||||||
|
Leaf D | |||||||
Note that brackets or bars must only be applied to leaf nodes. In the example above, it may be tempting to write
{{cladex|style=width:auto;font-size:85%;line-height:100%
|1=Leaf A
|bar2=midnightblue
|2={{cladex
|1=Leaf B
|2=Leaf C
}}
|3=Leaf D|bar3=midnightblue
}}
with the expectation that the bar will be to the right of the whole of the clade containing Leaf B and Leaf C. This does not produce the required output.
Specifying colours
You can use any of the ways in which colours can be specified in HTML; e.g. the standard colour names, the three or six hex digit notations, such as #FC3 or #F3C630, or the rgb() notation.
Supplying text labels
Text labels for each bracket/bar can be added using {{Barlabel}}. Accessibility guidelines require pages not to rely on colour alone, so it's particularly important to add labels if you have more than one bracket/bar and need to refer to them separately.
Debugging
If your cladogram doesn't display brackets/bars as you expected, check that:
- You understand the numbering system for the parameters barN, etc. The N must be the same as the number of the child within its clade. Thus typically you should write |N=label for leaf|barN=colour for bar, e.g. |2=[[Passeridae]]|bar2=midnightblue.
- You have only attempted to apply brackets/bars to leaf nodes.
- Either the outermost clade uses {{Clade}} or if it has to use {{Cladex}}, then |style=width:auto is present.
Limitations
{{Clade}} and {{Cladex}} work by producing hidden tables. The horizontal and vertical lines making up the tree are actually the edges of table cells. The tables are then drawn by the browser or user agent using its internal algorithms. As these differ from browser to browser, the trees drawn produced will not look the same on all browsers.
The bracket/bar drawing part of {{Cladex}} is probably close to the limits of what can be done using table-drawing algorithms to produce cladograms. The vertical bar is always drawn at the very right-hand edge of the hidden outermost table, which is often not how it would be drawn manually. As of 21 June 2011[update], there is no known way round this.
{{Clade}} and {{Cladex}} have some size limitations.
- Both currently allow only a maximum of 17 children per node. It may seem that this could easily be increased by editing the templates, but see the next point.
- Both will only expand a cladogram up to a certain level of complexity. The cladogram at APG_III_system#Phylogeny has had to be broken into two parts, because {{Clade}} will not handle the entire cladogram. Because {{Cladex}} has more complex internal code, it runs out of the allowed resources for template expansion sooner, and can only handle slightly smaller templates than {{Clade}}. Any change to either of these templates could result in large cladograms failing to display correctly.