PGF/TikZ Manual | PGFplots | TikZ Editor

TikZ and PGF Manual

Libraries

60 Mindmap Drawing Library

60.1 Overview

This library is intended to make the creation of mindmaps or concept maps easier. A mindmap is a graphical representation of a concept together with related concepts and annotations. Mindmaps are, essentially, trees, possibly with a few extra edges added, but they are usually drawn in a special way: The root concept is placed in the middle of the page and is drawn as a huge circle, ellipse, or cloud. The related concepts then “leave” this root concept via branch-like tendrils.

The mindmap library of TikZ produces mindmaps that look a bit different from the standard mindmaps: While the big root concept is still a circle, related concepts are also depicted as (smaller) circles. The related concepts are linked to the root concept via organic-looking connections. The overall effect is visually rather pleasing, but readers may not immediately think of a mindmap when they see a picture created with this library.

Although it is not strictly necessary, you will usually create mindmaps using TikZ’s tree mechanism and some of the styles and macros of the package work best when used inside trees. However, it is still possible and sometimes necessary to treat parts of a mindmap as a graph with arbitrary edges and this is also possible.

60.2 The Mindmap Style

Every mindmap should be put in a scope or a picture where the mindmap style is used. This style installs some internal settings.

Remark: Note that mindmap redefines font sizes and sibling angle depending on the current concept level (i.e. inside of level 1 concept, level 2 concept etc.). Thus, if you need to redefine these variables, use

level 1 concept/.append style={font=\small}

or

level 2 concept/.append style={sibling angle=90}

after the mindmap style.

60.3 Concepts Nodes

The basic entities of mindmaps are called concepts in TikZ. A concept is a node of style concept and it must be circular for some of the connection macros to work.

60.3.1 Isolated Concepts

The following styles influence how isolated concepts are rendered:

60.3.2 Concepts in Trees

As pointed out earlier, TikZ assumes that your mindmap is built using the child facilities of TikZ. There are numerous options that influence how concepts are rendered at the different levels of a tree.

  • /tikz/level 4 concept(style, no value)

  • Works like level 1 concept. Note that there are no fifth and higher level styles, you need to modify level 5 directly in such cases.

60.4 Connecting Concepts
60.4.1 Simple Connections

The easiest way to connect two concepts is to draw a line between them. In order to give such lines a consistent appearance, it is recommendable to use the following style when drawing such lines:

  • /tikz/concept connection(style, no value)

  • This style can be used for lines between two concepts. Feel free to redefine this style.

A problem arises when you need to connect concepts after the main mindmap has been drawn. In this case you will want the connection lines to lie behind the main mindmap. However, you can draw the lines only after the coordinates of the concepts have been determined. In this case you should place the connecting lines on a background layer as in the following example:

(-tikz- diagram)

\usetikzlibrary {backgrounds,mindmap}
\begin{tikzpicture}
[root concept/.append style={concept color=blue!20,minimum size=2cm},
level 1 concept/.append style={sibling angle=45},
mindmap]
\node [concept] {Root concept}
[clockwise from=45]
child { node[concept] (c1) {child}}
child { node[concept] (c2) {child}}
child { node[concept] (c3) {child}};
\begin{pgfonlayer}{background}
\draw [concept connection] (c1) edge (c2)
edge (c3)
(c2) edge (c3);
\end{pgfonlayer}
\end{tikzpicture}
60.4.2 The Circle Connection Bar Decoration

Instead of a simple line between two concepts, you can also add a bar between the two nodes that has slightly organic ends. These bars are also used by default as the edges from parents in the mindmap tree.

For the drawing of the bars a special decoration is used, which is defined in the mindmap library:

  • Decoration circle connection bar

  • This decoration can be used to connect two circles. The start of the to-be-decorated path should lie on the border of the first circle, the end should lie on the border of the second circle. The following two decoration keys should be initialized with the sizes of the circles:

    • start radius

    • end radius

    Furthermore, the following two decoration keys influence the decoration:

    • amplitude

    • angle

    The decoration turns a straight line into a path that starts on the border of the first circle at the specified angle relative to the line connecting the centers of the circles. The path then changes into a rectangle whose thickness is given by the amplitude. Finally, the path ends with the same angles on the second circle.

    Here is an example that should make this clearer:

    (-tikz- diagram)

    \usetikzlibrary {mindmap}
    \begin{tikzpicture}
    [decoration={start radius=1cm,end radius=.5cm,amplitude=2mm,angle=30}]
    \fill[blue!20] (0,0) circle [radius=1cm];
    \fill[red!20] (2.5,0) circle [radius=.5cm];

    \filldraw [draw=red,fill=black,
    decorate,decoration=circle connection bar] (1,0) -- (2,0);
    \end{tikzpicture}

    As can be seen, the decorated path consists of three parts and is not really useful for drawing. However, if you fill the decorated path only, and if you use the same color as for the circles, the result is better.

    (-tikz- diagram)

    \usetikzlibrary {mindmap}
    \begin{tikzpicture}
    [blue!50,decoration={start radius=1cm,
    end radius=.5cm,amplitude=2mm,angle=30}
    ]
    \fill (0,0) circle [radius=1cm];
    \fill (2.5,0) circle [radius=.5cm];

    \fill [decorate,decoration=circle connection bar] (1,0) -- (2,0);
    \end{tikzpicture}

    In the above example you may notice the small white line between the circles and the decorated path. This is due to rounding errors. Unfortunately, for larger distances, the errors can accumulate quite strongly, especially since TikZ and are not very good at computing square roots. For this reason, it is a good idea to make the circles slightly larger to cover up such problems. When using nodes of shape circle, you can just add the draw option with a line width of one or two points (for very large distances you may need line width up to 4pt).

    (-tikz- diagram)

    \usetikzlibrary {mindmap}
    \begin{tikzpicture}
    [blue!50,decoration={start radius=1cm,
    end radius=.5cm,amplitude=2mm,angle=30}
    ]
    \fill (0,0) circle [radius=1cm+1pt];
    \fill (2.4,0) circle [radius=.5cm+1pt];

    \fill [decorate,decoration=circle connection bar] (1,0) -- (1.9,0);
    \end{tikzpicture}
60.4.3 The Circle Connection Bar To-Path

The circle connection bar decoration is a bit complicated to use. Especially specifying the radii is quite bothersome (the amplitude and the angle can be set once and for all). For this reason, the mindmap library defines a special to-path that performs the necessary computations for you.

In a mindmap we sometimes want colors to change from one concept color to another. Then, the connection bar should, ideally, consist of a smooth transition between these two colors. Getting this right using shadings is a bit tricky if you try this “by hand”, so the mindmap library provides a special option for facilitating this procedure.

60.4.4 Tree Edges

Most of the time, concepts in a mindmap are connected automatically when the mindmap is built as a tree. The reason is that the mindmap installs a circle connection bar path as the edge from parent path. Also, the mindmap option takes care of things like setting the correct draw and outer sep settings and some other stuff.

In detail, the mindmap option sets the edge from parent path to a path that uses the to-path circle connection bar to connect the parent node and the child node. The concept color option (locally) changes this by using circle connection bar switch color instead with the from-color set to the old (parent’s) concept color and the to-color set to the new (child’s) concept color. This means that when you provide the concept color option to a child command, the color will change from the parent’s concept color to the specified color.

Let us now build a tree that way. Please note that we pass the concept color to the respective child and not to a node under it.

(-tikz- diagram)

\usetikzlibrary {mindmap}
\begin{tikzpicture}
\path[mindmap,concept color=black,text=white]
node[concept] {Computer Science}
[clockwise from=0]
% note that `sibling angle' can only be defined in
% `level 1 concept/.append style={}'
child[concept color=green!50!black] {
node[concept] {practical}
[clockwise from=90]
child { node[concept] {algorithms} }
child { node[concept] {data structures} }
child { node[concept] {pro\-gramming languages} }
child { node[concept] {software engineer\-ing} }
}
% note that the `concept color' is passed to the `child'(!)
child[concept color=blue] {
node[concept] {applied}
[clockwise from=-30]
child { node[concept] {databases} }
child { node[concept] {WWW} }
}
child[concept color=red] { node[concept] {technical} }
child[concept color=orange] { node[concept] {theoretical} };
\end{tikzpicture}
60.5 Adding Annotations

An annotation is some text outside a mindmap that, unlike an extra concept, simply explains something in the mindmap. The following style is mainly intended to help readers of the code see that a node in an annotation node.