% Copyright 2006 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesFileRCS[v\pgfversion] $Header: /cvsroot/pgf/pgf/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarymindmap.code.tex,v 1.5 2008/02/10 16:29:07 tantau Exp $


\usetikzlibrary{trees,decorations}


% A decoration for connecting circle nodes
%
% Parameters: start radius, end radius, amplitude, angle

\pgfdeclaredecoration{circle connection bar}{initial}
{
  \state{initial}[width=0pt,next state=bar]
  {
    {
    \pgftransformxshift{-\pgfkeysvalueof{/pgf/decoration/start radius}}%
    \pgfpathmoveto{\pgfpointpolar{\pgfdecorationsegmentangle}{\pgfkeysvalueof{/pgf/decoration/start radius}}}
    \pgfpatharc{\pgfdecorationsegmentangle}{-\pgfdecorationsegmentangle}{\pgfkeysvalueof{/pgf/decoration/start radius}}
    \pgfutil@tempcnta=-\pgfdecorationsegmentangle\relax
    \advance\pgfutil@tempcnta by90\relax
    \pgfmathsetlength\pgfutil@tempdima{\pgfkeysvalueof{/pgf/decoration/start radius}}
    \pgfmathsetlength\pgfutil@tempdimb{\pgfdecorationsegmentamplitude}
    \pgfpathcurveto
    {\pgfpointadd
      {\pgfpointpolar{-\pgfdecorationsegmentangle}{\pgfkeysvalueof{/pgf/decoration/start radius}}}
      {\pgfpointpolar{\the\pgfutil@tempcnta}{.25\pgfutil@tempdima}}}
    {\pgfqpoint{1.25\pgfutil@tempdima}{-.5\pgfutil@tempdimb}}
    {\pgfqpoint{1.5\pgfutil@tempdima}{-.5\pgfutil@tempdimb}}
    \pgfpathlineto{\pgfpoint{1.5\pgfutil@tempdima}{.5\pgfutil@tempdimb}}
    \pgfutil@tempcnta=\pgfdecorationsegmentangle\relax
    \advance\pgfutil@tempcnta by-90\relax
    \pgfpathcurveto
    {\pgfpoint{1.25\pgfutil@tempdima}{.5\pgfutil@tempdimb}}
    {\pgfpointadd
      {\pgfpointpolar{\pgfdecorationsegmentangle}{\pgfkeysvalueof{/pgf/decoration/start radius}}}
      {\pgfpointpolar{\the\pgfutil@tempcnta}{.25\pgfutil@tempdima}}}
    {\pgfpointpolar{\pgfdecorationsegmentangle}{\pgfkeysvalueof{/pgf/decoration/start radius}}}
    \pgfpathclose
    }
  }
  \state{bar}[width=0pt,next state=end]
  {
    \pgfmathsetlength\pgfutil@tempdima{\pgfkeysvalueof{/pgf/decoration/start radius}}%
    \pgfmathsetlength\pgfutil@tempdimb{\pgfkeysvalueof{/pgf/decoration/end radius}}%
    \pgfmathsetlength\pgf@xc{\pgfdecorationsegmentamplitude}%
    \pgfpathrectangle
    {\pgfqpoint{.5\pgfutil@tempdima}{-.5\pgf@xc}}
    {\pgfpoint{\pgfdecoratedremainingdistance+-.5\pgfutil@tempdimb+-.5\pgfutil@tempdima}{\pgf@xc}}
  }
  \state{end}[width=0pt,next state=final]
  {
    {
    \pgftransformxshift{\pgfdecoratedremainingdistance}%
    \pgftransformxscale{-1}%
    \pgftransformxshift{-\pgfkeysvalueof{/pgf/decoration/end radius}}%
    \pgfpathmoveto{\pgfpointpolar{\pgfdecorationsegmentangle}{\pgfkeysvalueof{/pgf/decoration/end radius}}}
    \pgfpatharc{\pgfdecorationsegmentangle}{-\pgfdecorationsegmentangle}{\pgfkeysvalueof{/pgf/decoration/end radius}}
    \pgfutil@tempcnta=-\pgfdecorationsegmentangle\relax
    \advance\pgfutil@tempcnta by90\relax
    \pgfmathsetlength\pgfutil@tempdima{\pgfkeysvalueof{/pgf/decoration/end radius}}
    \pgfmathsetlength\pgfutil@tempdimb{\pgfdecorationsegmentamplitude}%
    \pgfpathcurveto
    {\pgfpointadd
      {\pgfpointpolar{-\pgfdecorationsegmentangle}{\pgfkeysvalueof{/pgf/decoration/end radius}}}
      {\pgfpointpolar{\the\pgfutil@tempcnta}{.25\pgfutil@tempdima}}}
    {\pgfqpoint{1.25\pgfutil@tempdima}{-.5\pgfutil@tempdimb}}
    {\pgfqpoint{1.5\pgfutil@tempdima}{-.5\pgfutil@tempdimb}}
    \pgfpathlineto{\pgfpoint{1.5\pgfutil@tempdima}{.5\pgfutil@tempdimb}}
    \pgfutil@tempcnta=\pgfdecorationsegmentangle\relax
    \advance\pgfutil@tempcnta by-90\relax
    \pgfpathcurveto
    {\pgfpoint{1.25\pgfutil@tempdima}{.5\pgfutil@tempdimb}}
    {\pgfpointadd
      {\pgfpointpolar{\pgfdecorationsegmentangle}{\pgfkeysvalueof{/pgf/decoration/end radius}}}
      {\pgfpointpolar{\the\pgfutil@tempcnta}{.25\pgfutil@tempdima}}}
    {\pgfpointpolar{\pgfdecorationsegmentangle}{\pgfkeysvalueof{/pgf/decoration/end radius}}}
    \pgfpathclose
    }
  }
  \state{final}
  {}
}



\pgfkeys{/pgf/decoration/angle=20}

% To paths for connecting circle nodes

\tikzstyle{circle connection bar}=
[to path={
  \pgfextra{\tikz@compute@circle@radii\tikz@compute@segmentamplitude}
  [fill=\tikz@concept@color,draw=none]
  [every circle connection bar]
  decorate [decoration=circle connection bar]
  { -- (\tikztotarget) \tikztonodes}
}]
\tikzstyle{every circle connection bar}=[]

\def\tikz@compute@circle@radii{%
  \pgf@process{\pgfpointtransformed{\pgfpointanchor{\tikztostart}{center}}}%
  \pgf@xa=\pgf@x%
  \pgf@process{\pgfpointtransformed{\pgfpointanchor{\tikztostart}{west}}}%
  \advance\pgf@xa by-\pgf@x%
  \pgfkeys{/pgf/decoration/start radius/.expanded=\the\pgf@xa}%
  \pgf@process{\pgfpointtransformed{\pgfpointanchor{\tikztotarget}{center}}}%
  \pgf@xa=\pgf@x%
  \pgf@process{\pgfpointtransformed{\pgfpointanchor{\tikztotarget}{west}}}%
  \advance\pgf@xa by-\pgf@x%
  \pgfkeys{/pgf/decoration/end radius/.expanded=\the\pgf@xa}%
}
\def\tikz@compute@segmentamplitude{%
  \pgf@x=\pgfkeysvalueof{/pgf/decoration/start radius}\relax%
  \ifdim\pgf@x>\pgfkeysvalueof{/pgf/decoration/end radius}\relax%
    \pgf@x=\pgfkeysvalueof{/pgf/decoration/end radius}\relax%
  \fi%
  \pgf@x=.175\pgf@x\relax%
  \edef\pgfdecorationsegmentamplitude{\the\pgf@x}%
}


% Switch color in a mindmap

\tikzoption{circle connection bar switch color}{\tikz@parse@switch#1\pgf@unique}
\def\tikz@parse@switch from (#1) to (#2)\pgf@unique{%
  \def\tikz@to@path{%
    \pgfextra{%
      \pgfutil@colorlet{tikz@switch@from}{#1}%
      \pgfutil@colorlet{tikz@switch@to}{#2}%
      \tikz@compute@circle@radii\tikz@compute@segmentamplitude%
      \tikz@compute@rotation%
    }
    [fill=none,draw=none]
    [every circle connection bar]
    decorate [decoration=circle connection bar]
    {-- (\tikztotarget) \tikztonodes} 
    [shading=tikz@shade@bar]
  }
}

\tikzoption{concept color}{%
  \let\tikz@old@concept@color=\tikz@concept@color%
  \def\tikz@edge@to@parent@path{
    (\tikzparentnode)
    to[circle connection bar switch color=from (\tikz@old@concept@color) to (#1)]
    (\tikzchildnode)}
  \def\tikz@concept@color{#1}%
}

\pgfdeclarehorizontalshading[tikz@switch@from,tikz@switch@to]{tikz@shade@bar}{100bp}{%
  color(0pt)=(tikz@switch@from);
  color(50bp)=(tikz@switch@from);
  color(55bp)=(tikz@switch@to);
  color(100bp)=(tikz@switch@to)}

\def\tikz@compute@rotation{%
  \pgf@process{\pgfpointnormalised{\pgfpointdiff{\pgfpointanchor{\tikztostart}{center}}{\pgfpointanchor{\tikztotarget}{center}}}}%
  \pgf@ya=-\pgf@y%
  \edef\pgf@marshal{%
    \noexpand\pgfsetadditionalshadetransform{%
      \noexpand\pgftransformcm
      {\pgf@sys@tonumber{\pgf@x}}{\pgf@sys@tonumber{\pgf@y}}%
      {\pgf@sys@tonumber{\pgf@ya}}{\pgf@sys@tonumber{\pgf@x}}%
      {\noexpand\pgfpointorigin}%
    }%
  }%
  \pgf@marshal%
}




% A concept node

\tikzstyle{concept}=          [circle,fill=\tikz@concept@color,draw=\tikz@concept@color,every concept]
\tikzstyle{every concept}=    []

\def\tikz@concept@color{black}

\tikzstyle{tikz@concept@setting}=[edge from parent path={(\tikzparentnode) to [circle connection bar] (\tikzchildnode)}]
\tikzstyle{tikz@concept@color@set}=[]


\tikzstyle{extra concept}=     [concept color=black!50,level 2 concept,concept,every extra concept]
\tikzstyle{every extra concept}=[]

\tikzstyle{concept connection}=[line width=1mm,shorten <=2mm,shorten >=2mm,cap=round,draw=black!50]


% A mindmap

\tikzstyle{mindmap}=
  [fill,draw,very thick,outer sep=0pt,inner sep=1pt,%
   every child/.append style={style=tikz@concept@setting,style=tikz@concept@color@set},%
   root concept,
   level 1/.append style={level 1 concept},
   level 2/.append style={level 2 concept},
   level 3/.append style={level 3 concept},
   level 4/.append style={level 4 concept},
   text centered,%       
   segment angle=20,
   style=every mindmap,
  ]
\tikzstyle{every mindmap}=[]


\tikzstyle{root concept}=   [minimum size=4cm,text width=3.5cm,font=\pgfutil@font@large]
\tikzstyle{level 1 concept}=[minimum size=2.25cm,
                             level distance=5cm,
                             text width=2cm,
                             sibling angle=60,
                             font=\pgfutil@font@small]
\tikzstyle{level 2 concept}=[minimum size=1.75cm,%
                             level distance=2.9cm,%
                             text width=1.5cm,%
                             sibling angle=60,%
                             font=\pgfutil@font@footnotesize]
\tikzstyle{level 3 concept}=[minimum size=1.15cm,%
                             text width=1cm,%
                             level distance=2.4cm,%
                             sibling angle=30,%
                             font=\pgfutil@font@tiny]
\tikzstyle{level 4 concept}=[minimum size=0.9cm,%
                             text width=0.7cm,
                             level distance=1.85cm,%
                             sibling angle=30,%
                             font=\pgfutil@font@tiny]
  
\tikzstyle{large mindmap}=
  [%
  root concept/.style={minimum size=5.6cm,text width=4.5cm,font=\pgfutil@font@Large},
  level 1 concept/.style={%
    minimum size=3.2cm,
    level distance=7cm,
    text width=2.8cm,
    sibling angle=60,
    font=},%
  level 2 concept/.style={%
    minimum size=2.45cm,%
    level distance=4cm,%
    text width=2.2cm,%
    sibling angle=60,%
    font=\pgfutil@font@small%
    },%
  level 3 concept/.style={%
    minimum size=1.63cm,%
    text width=1.4cm,%
    level distance=3.38cm,%
    sibling angle=30,%
    font=\pgfutil@font@scriptsize},%
  level 4 concept/.style={%
    minimum size=1.27cm,%
    text width=1cm,
    level distance=2.60cm,%
    sibling angle=30,%
    font=\pgfutil@font@tiny},%
  mindmap,%
  line width=2pt
  ]
  
\tikzstyle{huge mindmap}=
  [%
  root concept/.style={minimum size=8cm,text width=7cm,font=\pgfutil@font@huge},
  level 1 concept/.style={%
    minimum size=4.5cm,
    level distance=10cm,
    text width=4cm,
    sibling angle=60,
    font=\pgfutil@font@large},%
  level 2 concept/.style={%
    minimum size=3.5cm,%
    level distance=5.8cm,%
    text width=3cm,%
    sibling angle=60,%
    font=%
    },%
  level 3 concept/.style={%
    minimum size=2.3cm,%
    text width=2cm,%
    level distance=4.8cm,%
    sibling angle=30,%
    font=\pgfutil@font@footnotesize},%
  level 4 concept/.style={%
    minimum size=1.7cm,%
    text width=1.4cm,
    level distance=3.7cm,%
    sibling angle=30,%
    font=\pgfutil@font@scriptsize},%
  mindmap,%
  line width=3pt
  ]
  

% Annotations

\tikzstyle{annotation}=[shape=rectangle,
                        minimum size=0pt,
                        text width=3.5cm,
                        outer sep=1.5mm,
                        inner sep=1mm,
                        text badly ragged,
                        rounded corners,
                        font=\pgfutil@font@tiny,
                        every annotation]
\tikzstyle{every annotation}=[]



\endinput

