1. 数学问题

1. 数学问题

如何修改思维导图节点中文本的方向,使得最外层节点的文本从中心呈放射状排列。

例如,在下图中,我寻找橙色圆圈节点内的文本进行旋转,以便它分别与橙色线的方向对齐。

径向思维导图

上述思维导图的代码如下:

\begin{tikzpicture}
  \path[small mindmap,concept,text=white]
    node[concept] {Bla} [clockwise from=-15]
    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[concept]{A}[clockwise from = 120]
            child {node[concept,scale=0.5] {A.A}}
            child {node[concept,scale=0.5] {A.B}}
            child {node[concept,scale=0.5] {A.C}}
      }
      child[concept color=red!75!black,text=white,grow=50]{
        node[concept]{B}[clockwise from = 80]
            child {node[concept,scale=0.5] {B.A}}
            child {node[concept,scale=0.5] {B.B}}
            child {node[concept,scale=0.5] {B.C}}
      }
      child[concept color=red!50!black,text=white ,grow=10]{
        node[concept]{C}[clockwise from = 40]
            child {node[concept,scale=0.5] {C.A}}
            child {node[concept,scale=0.5] {C.B}}
            child {node[concept,scale=0.5] {C.C}}
      }
      child[concept color=red!25!black,text=white,grow=-30]{
        node[concept]{D}[clockwise from = 0]
            child {node[concept,scale=0.5] {D.A}}
            child {node[concept,scale=0.5] {D.B}}
            child {node[concept,scale=0.5] {D.C}}
      }
      child[concept color=red!10!black,text=white,grow=-70]{
        node[concept]{D}[clockwise from = -40]
            child {node[concept,scale=0.5] {D.A}}
            child {node[concept,scale=0.5] {D.B}}
            child {node[concept,scale=0.5] {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[concept]{Bla}[counterclockwise from = 50]
            child {node[concept,scale=0.5] {A.A}}
            child {node[concept,scale=0.5] {A.B}}
            child {node[concept,scale=0.5] {A.C}}
      }
      child[concept color=green!25!black,text=white,grow=120]{
        node[concept]{Bla}[counterclockwise from = 90]
            child {node[concept,scale=0.5] {A.A}}
            child {node[concept,scale=0.5] {A.B}}
            child {node[concept,scale=0.5] {A.C}}
      }
      child[concept color=green!50!black,text=white,grow=160]{
        node[concept]{Bla}[counterclockwise from = 130]
            child {node[concept,scale=0.5] {B.A}}
            child {node[concept,scale=0.5] {B.B}}
            child {node[concept,scale=0.5] {B.C}}
      }
      child[concept color=green!75!black,text=white ,grow=200]{
        node[concept]{Bla}[counterclockwise from = 170]
            child {node[concept,scale=0.5] {C.A}}
            child {node[concept,scale=0.5] {C.B}}
            child {node[concept,scale=0.5] {C.C}}
      }
      child[concept color=green!95!black,text=black,grow=240]{
        node[concept]{Bla}[counterclockwise from = 210]
            child {node[concept,scale=0.5] {D.A}}
            child {node[concept,scale=0.5] {D.B}}
            child {node[concept,scale=0.5] {D.C}}
      }
    }
    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] {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] {B.B}}
                child {node[concept,scale=0.5] {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] {C.B}}
                child {node[concept,scale=0.5] {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] {D.B}}
                child {node[concept,scale=0.5] {D.C}}
        }
        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] {E.B}}
                child {node[concept,scale=0.5] {E.C}}
        }
    }    
   ;
\end{tikzpicture}

更新:继续此主题第二部分,寻找椭圆形或矩形的径向旋转节点。

答案1

这里有两个半问题需要解决。

1. 数学问题

我们必须计算旋转量。

counterclockwise from参数在内部保存\tikz@grow@circle@from@start

对于每个孩子, 的数量/tikz/sibling angle都会增加(counterclockwise)或减少(clockwise)。孩子的号码保存在 中\tikznumberofcurrentchild

对于按顺时针方向放置的橙色子项,文本必须旋转的角度为:

  \tikz@grow@circle@from@start
- (\pgfkeysvalueof{/tikz/sibling angle}) * (\tikznumberofcurrentchild - 1)

閱讀

如果节点的内容不应该颠倒,则必须调整公式:

(
     \tikz@grow@circle@from@start
     - (\pgfkeysvalueof{/tikz/sibling angle}) * (\tikznumberofcurrentchild - 1)
) + 180 * (
      cos(
            \tikz@grow@circle@from@start
          - (\pgfkeysvalueof{/tikz/sibling angle})+(\tikznumberofcurrentchild-1)
      )
      < 0
)

2. 旋转问题

太棒了,这么简单

rotation =   \tikz@grow@circle@from@start
           - (\pgfkeysvalueof{/tikz/sibling angle}) * (\tikznumberofcurrentchild - 1)

应该可以吧?

没有:

在此处输入图片描述

整个节点都会变形(在本例中为旋转),这意味着所有锚节点也会旋转。这会混淆装饰的计算circle connection bar。我们旋转子节点的次数越多,连接条扭曲的程度就越大。

我们当然可以调整装饰的代码circle connection bar,但是代码太多了

旋转文本本身会容易得多。
借助 的graphicx\rotatebox,可以轻松完成此操作:

\newcommand*{\rotateme}[1]{%
    \pgfmathparse{
        \tikz@grow@circle@from@start-
        (\pgfkeysvalueof{/tikz/sibling angle})*(\tikznumberofcurrentchild-1)
    }%
    \rotatebox[origin=c]{\pgfmathresult}{#1}%
}

2½. 节点文本问题

您是否要编辑每个需要旋转的节点并添加\rotateme宏?
我不这么认为!

我的解决方案是借助以下方法收集所有节点的文本

  • execute at begin node
  • execute at and node, 和
  • lrbox将节点的文本保存在名为 的框中的环境\rotatenodebox

然后将此框提供给前面提到的\rotateme宏。

\tikzset{
    conc3/.style={concept,scale=.5},
    orange/.style={
        conc3,
        execute at begin node={\begingroup\begin{lrbox}{\rotatenodebox}},
        execute at end node={\end{lrbox}\rotateme{\usebox\rotatenodebox}\endgroup},
    }
}

代码

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

\tikzset{
    conc3/.style={concept,scale=.5},
    orange/.style={
        conc3,
        execute at begin node={\begingroup\begin{lrbox}{\rotatenodebox}},
        execute at end node={\end{lrbox}\rotateme{\usebox\rotatenodebox}\endgroup},
    }
}
\begin{document}
\begin{tikzpicture}
  \path[small mindmap,concept,text=white]
    node[concept] {Bla} [clockwise from=-15]
    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[concept]{A}[clockwise from = 120]
            child {node[conc3] {A.A}}
            child {node[conc3] {A.B}}
            child {node[conc3] {A.C}}
      }
      child[concept color=red!75!black,text=white,grow=50]{
        node[concept]{B}[clockwise from = 80]
            child {node[conc3] {B.A}}
            child {node[conc3] {B.B}}
            child {node[conc3] {B.C}}
      }
      child[concept color=red!50!black,text=white ,grow=10]{
        node[concept]{C}[clockwise from = 40]
            child {node[conc3] {C.A}}
            child {node[conc3] {C.B}}
            child {node[conc3] {C.C}}
      }
      child[concept color=red!25!black,text=white,grow=-30]{
        node[concept]{D}[clockwise from = 0]
            child {node[conc3] {D.A}}
            child {node[conc3] {D.B}}
            child {node[conc3] {D.C}}
      }
      child[concept color=red!10!black,text=white,grow=-70]{
        node[concept]{D}[clockwise from = -40]
            child {node[conc3] {D.A}}
            child {node[conc3] {D.B}}
            child {node[conc3] {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[concept]{Bla}[counterclockwise from = 50]
            child {node[conc3] {A.A}}
            child {node[conc3] {A.B}}
            child {node[conc3] {A.C}}
      }
      child[concept color=green!25!black,text=white,grow=120]{
        node[concept]{Bla}[counterclockwise from = 90]
            child {node[conc3] {A.A}}
            child {node[conc3] {A.B}}
            child {node[conc3] {A.C}}
      }
      child[concept color=green!50!black,text=white,grow=160]{
        node[concept]{Bla}[counterclockwise from = 130]
            child {node[conc3] {B.A}}
            child {node[conc3] {B.B}}
            child {node[conc3] {B.C}}
      }
      child[concept color=green!75!black,text=white ,grow=200]{
        node[concept]{Bla}[counterclockwise from = 170]
            child {node[conc3] {C.A}}
            child {node[conc3] {C.B}}
            child {node[conc3] {C.C}}
      }
      child[concept color=green!95!black,text=black,grow=240]{
        node[concept]{Bla}[counterclockwise from = 210]
            child {node[conc3] {D.A}}
            child {node[conc3] {D.B}}
            child {node[conc3] {D.C}}
      }
    }
    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[orange] {A.A}}
                child {node[orange] {A.B}}
                child {node[orange] {A.C}}
        }
        child[concept color=orange!75!black, grow = -30]{
            node[concept]{Bla}[clockwise from =0]
                child {node[orange] {B.A}}
                child {node[orange] {B.B}}
                child {node[orange] {B.C}}
        }
        child[concept color=orange!50!black, text=white, grow=-70]{
            node[concept]{Bla}[clockwise from =-40]
                child {node[orange] {C.A}}
                child {node[orange] {C.B}}
                child {node[orange] {C.C}}
        }
        child[concept color=orange!25!black, text=white, grow=-110]{
            node[concept]{Bla}[clockwise from =-80]
                child {node[orange] {D.A}}
                child {node[orange] {D.B}}
                child {node[orange] {D.C}}
        }
        child[concept color=orange!10!black, text=white, grow=-150]{
            node[concept]{Bla}[clockwise from =-120]
                child {node[orange] {E.A}}
                child {node[orange] {E.B}}
                child {node[orange] {E.C}}
        }
    }
   ;
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容