思维导图上的径向标签 - 第二部分

思维导图上的径向标签 - 第二部分

这是第一部分,其中提供了一种以径向方式创建旋转标签的解决方案。

在此处输入图片描述

输出的特写如下所示:

解决方案

我可以改进解决方案,防止标签在 360 度旋转时上下颠倒,使用以下代码,不同之处在于“ifthenelse”条件子句......

\makeatletter
\newcommand*{\rotateme}[1]{%
    \pgfmathparse{
        (\tikz@grow@circle@from@start-(\pgfkeysvalueof{/tikz/sibling angle})*(\tikznumberofcurrentchild-1))
    }%
    \pgfmathparse{
        ifthenelse(\pgfmathresult > 90 && \pgfmathresult < 270,\pgfmathresult + 180,\pgfmathresult)  
    }
    \rotatebox[origin=c]{\pgfmathresult}{#1}%
}
\makeatother

我现在想做的是扩展这个主题的径向特性,以适应标签很长的情况。用椭圆或圆角矩形替换圆形概念节点,这些节点也会旋转。请注意以下当前输出,错误非常明显。

龙东

相对而言,我对 tikz 的技能很差,有人可以帮忙吗?

完整工作示例如下:

\documentclass[tikz]{standalone}
\usetikzlibrary{mindmap}
\newsavebox\rotatenodebox
\makeatletter
\newcommand*{\rotateme}[1]{%
    \pgfmathparse{
        (\tikz@grow@circle@from@start-(\pgfkeysvalueof{/tikz/sibling angle})*(\tikznumberofcurrentchild-1))
    }%
    \pgfmathparse{
        ifthenelse(\pgfmathresult > 90 && \pgfmathresult < 270,\pgfmathresult + 180,\pgfmathresult)  
    }
    \rotatebox[origin=c]{\pgfmathresult}{#1}%
}
\makeatother

\tikzset{
    conc3/.style={concept,scale=.5},
    rot/.style={
        conc3,
        execute at begin node={\begingroup\begin{lrbox}{\rotatenodebox}},
        execute at end   node={\end{lrbox}\rotateme{\usebox\rotatenodebox}\endgroup},
    }
}
\tikzset{
    conc4/.style={concept,scale=0.75},
    rotL/.style={
        conc4
    }
}
\begin{document}
\begin{tikzpicture}
  \path[small mindmap,concept,text=white]
    node[concept] {Bla} [clockwise from=345]
    child[concept color=red,text=black]{
      node[concept]at(1,0){Bla Bla}[clockwise from=90]
      child[concept color=red!95!black,text=black]{
        node[rotL]{A}[clockwise from = 120]
            child {node[rot] {A.A}}
            child {node[rot] {A.B}}
            child {node[rot] {A.C}}
      }
      child[concept color=red!75!black,text=white,grow=50]{
        node[rotL]{B}[clockwise from = 80]
            child {node[rot] {B.A}}
            child {node[rot] {B.B}}
            child {node[rot] {B.C}}
      }
      child[concept color=red!50!black,text=white ,grow=10]{
        node[rotL]{C}[clockwise from = 40]
            child {node[rot] {C.A}}
            child {node[rot] {C.B}}
            child {node[rot] {C.C}}
      }
      child[concept color=red!25!black,text=white,grow=-30]{
        node[rotL]{D}[clockwise from = 0]
            child {node[rot] {D.A}}
            child {node[rot] {D.B}}
            child {node[rot] {D.C}}
      }
      child[concept color=red!10!black,text=white,grow=-70]{
        node[rotL]{D}[clockwise from = -40]
            child {node[rot] {D.A}}
            child {node[rot] {D.B}}
            child {node[rot] {D.C}}
      }
    }
    child[concept color=green,text=black, grow=195]{
      node[concept]{Bla Bla}[clockwise from=80]
      child[concept color=green!10!black,text=white]{
        node[rotL]{Bla}[clockwise from = 110]
            child {node[rot] {A.A}}
            child {node[rot] {A.B}}
            child {node[rot] {A.C}}
      }
      child[concept color=green!25!black,text=white,grow=120]{
        node[rotL]{Bla}[clockwise from = 150]
            child {node[rot] {A.A}}
            child {node[rot] {A.B}}
            child {node[rot] {A.C}}
      }
      child[concept color=green!50!black,text=white,grow=160]{
        node[rotL]{Bla}[clockwise from = 190]
            child {node[rot] {B.A}}
            child {node[rot] {B.B}}
            child {node[rot] {B.C}}
      }
      child[concept color=green!75!black,text=white ,grow=200]{
        node[rotL]{Bla}[clockwise from = 230]
            child {node[rot] {C.A}}
            child {node[rot] {C.B}}
            child {node[rot] {C.C}}
      }
      child[concept color=green!95!black,text=black,grow=240]{
        node[rotL]{Bla}[clockwise from = 270]
            child {node[rot] {D.A}}
            child {node[rot] {D.B}}
            child {node[rot] {D.C}}
      }
    }
    child[concept color=orange,text=black, grow = 270] {
      node[concept]at(-1.5,-2.5){Bla Bla}[clockwise from=360]
        child[concept color=orange!95!black]{
            node[rotL]{Bla}[clockwise from = 30]
                child {node[rot] {A.A}}
                child {node[rot] {A.B}}
                child {node[rot] {A.C}}
        }
        child[concept color=orange!75!black, grow = 320]{
            node[rotL]{Bla}[clockwise from =350]
                child {node[rot] {In Honour of the Great Long Don Silver}}
                child {node[rot] {In Honour of the Great Long Don Silver}}
                child {node[rot] {In Honour of the Great Long Don Silver}}
        }
        child[concept color=orange!50!black, text=white, grow=280]{
            node[rotL]{Bla}[clockwise from =310]
                child {node[rot] {C.A}}
                child {node[rot] {C.B}}
                child {node[rot] {C.C}}
        }
        child[concept color=orange!25!black, text=white, grow=240]{
            node[rotL]{Bla}[clockwise from =270]
                child {node[rot] {D.A}}
                child {node[rot] {D.B}}
                child {node[rot] {D.C}}
        }
        child[concept color=orange!10!black, text=white, grow=200]{
            node[rotL]{Bla}[clockwise from =230]
                child {node[rot] {E.A}}
                child {node[rot] {E.B}}
                child {node[rot] {E.C}}
        }
    };
\end{tikzpicture}
\end{document}

答案1

这个答案与 Qrrbrbbirbel 对节点文本旋转所做的类似。但我没有旋转节点文本,而是修改了路径,edge from parent以便挤入更多信息。

需要旋转的节点需要密钥mind your rotate

首先是代码和结果,

\documentclass[tikz]{standalone}
\usetikzlibrary{mindmap}
\def\myrotangle{0}
\makeatletter
\tikzset{tikz@concept@setting/.style={edge from parent path={
        (\tikzparentnode) 
        \pgfextra{
        \pgfpointdiff{%}
            \pgfpointanchor{\tikzchildnode}{north}
        }
        {%}
            \pgfpointanchor{\tikzchildnode}{south}
        }
        \pgfmathsetmacro\mychildsize{veclen(\pgf@x,\pgf@y)}
        \pgfpathmoveto{\pgfpointanchor{\tikzchildnode}{center}}
        \pgfset{minimum size=\mychildsize}
        \pgfsetlinewidth{1mm}
        \pgfnode{circle}{center}{}{\tikzchildnode-temp}{\pgfusepath{discard}}
             \pgfpointdiff{%}
                 \pgfpointanchor{\tikzchildnode}{center}
                }
                {%}
                 \pgfpointanchor{\tikzparentnode}{center}
                }
            \pgfmathparse{atan2(\pgf@x,\pgf@y)}%
            \xdef\myrotangle{\pgfmathresult}
            \pgfmathparse{((\myrotangle>90+\pgfkeysvalueof{/tikz/sibling angle})&&(\myrotangle<270+\pgfkeysvalueof{/tikz/sibling angle})?(\myrotangle + 180):(\myrotangle))}
            \xdef\myrotangle{\pgfmathresult}
            }
        to [circle connection bar] (\tikzchildnode-temp)
        }
    }
}

\makeatother


\tikzset{mind your rotate/.style={
    rotate=\myrotangle-\pgfkeysvalueof{/tikz/sibling angle}
    }
}

\begin{document}
\begin{tikzpicture}
  \path[small mindmap,concept,text=white]
    node[concept] (Bla) {Bla} [clockwise from=-15]
    child[concept color=red,text=black]{
      node[concept]at(1,0){Bla Bla}[clockwise from=90]      {}
    }
    child[concept color=green,text=black, grow=195]{
      node[concept]{Bla Bla}[clockwise from=80]
    }
    child[concept color=orange,text=black, grow = -90] {
      node[concept]at(-1.5,-2.5){Bla Bla}[clockwise from=10]
        child[concept color=orange!95!black]{
            node[concept]{Bla}[clockwise from = 40]
                child {node[concept,scale=0.5,mind your rotate] {A.A}}
                child {node[concept,scale=0.5] {A.B}}
                child {node[concept,scale=0.5] {A.C}}
        }
        child[concept color=orange!75!black, grow = -30]{
            node[concept]{Bla}[clockwise from =0]
                child {node[concept,scale=0.5] {B.A}}
                child {node[concept,scale=0.5,mind your rotate] {B.B}}
                child {node[concept,scale=0.5,mind your rotate] {B.C}}
        }
        child[concept color=orange!50!black, text=white, grow=-70]{
            node[concept]{Bla}[clockwise from =-40]
                child {node[concept,scale=0.5] {C.A}}
                child {node[concept,scale=0.5,mind your rotate] {C.B Some important remark that should cause a line break}}
                child {node[concept,scale=0.5,mind your rotate] {C.C}}
        }
        child[concept color=orange!25!black, text=white, grow=-110]{
            node[concept]{Bla}[clockwise from =-80]
                child {node[concept,scale=0.5] {D.A}}
                child {node[concept,scale=0.5,mind your rotate] {D.B Some important remark that should cause a line break}}
                child {node[concept,scale=0.5,mind your rotate] {D.C Some important remark that should cause a line break}}
        }
        child[concept color=orange!10!black, text=white, grow=-150]{
            node[concept]{Bla}[clockwise from =-120]
                child {node[concept,scale=0.5] {E.A}}
                child {node[concept,scale=0.5,mind your rotate] {E.B Some important remark that should cause a line break 
                                                                     and some more text which is tough to come up with 
                                                                     on the fly}}
                child {node[concept,scale=0.5] {E.C}}
        }
    }    
   ;

\draw[yellow] (Bla-3-2-2.north) -- (Bla-3-2-2.south);

\end{tikzpicture}
\end{document}

在此处输入图片描述

在此处输入图片描述

简而言之,发生的事情是:常规父子节点名称被捕获。使用它们的坐标计算旋转角度。还测量了子节点的大小(粗略地!)。然后将临时的非旋转节点放置在子节点之上,这样连接栏就不会混淆。

还有几点我遗漏了;

  • 子节点的尺寸测量相当原始。没有考虑线宽、内部分隔,但我认为手动测量可以实现更平滑的连接。(测量值以黄线显示)
  • 旋转校正代码是直接复制/粘贴完成的,因此可能需要再次检查。我觉得我遗漏了一些东西,但没有进行广泛的测试。
  • 总的来说,我认为这不能与其他节点形状一起使用,因为对于连接转换来说,想出的代码真的很难。

相关内容