创建自定义节点来绘制此

创建自定义节点来绘制此

我对 tikz 非常陌生,我已经这样做了:

在此处输入图片描述

使用此代码:

\documentclass{article}

\usepackage[spanish,es-noquoting]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usetikzlibrary{shadows}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{positioning}
\usetikzlibrary{calc,intersections}

\begin{document}
\begin{tikzpicture}[terminal/.style={draw, drop shadow, fill=white, rectangle, inner sep=5pt, font=\bfseries, align=center}]
\tikzset{fallastyle/.style={text=red}}
\tikzset{pasastyle/.style={text=green}}
\def \radius {0.25\textwidth}
\def \margin {20} % margin in angles, depends on the radius

\path[name path=circulo] (0, 0) circle (\radius);

\node(escribir_prueba)[name path=path_escribir_prueba,terminal] at ({0+90}:\radius){(Re)Escribir\\ Prueba};
\node(correr_prueba)[name path=path_correr_prueba, terminal] at ({300+90}:\radius){Correr\\ Prueba};
\node(escribir_codigo)[name path=path_escribir_codigo, terminal] at ({240+90}:\radius){Escribir\\ Código};
\node(correr_todas_pruebas_1)[name path=path_correr_todas_pruebas_1, terminal] at ({180+90}:\radius){Correr todas\\ las pruebas};
\node(refactorizar)[name path=path_refactorizar, terminal] at ({120+90}:\radius){Refactorizar};
\node(correr_todas_pruebas_2)[name path=path_correr_todas_pruebas_2, terminal] at ({60+90}:\radius){Correr todas\\ las pruebas};


\node (start) [node distance=8mm and -1mm, above left=of escribir_prueba, circle, fill=black, minimum width=1pt]{};

% INTERSECCIONES
\path [name intersections={of=circulo and path_escribir_prueba,name=intESCRIBIRPRUEBA}];
\def \ESCRIBIRRIGHT {intESCRIBIRPRUEBA-1}
\def \ESCRIBIRLEFT {intESCRIBIRPRUEBA-2}

\path [name intersections={of=circulo and path_correr_prueba,name=intCORRERPRUEBA}];
\def \CORRERPRUEBAUP {intCORRERPRUEBA-1}
\def \CORRERPRUEBADOWN {intCORRERPRUEBA-2}

\path [name intersections={of=circulo and path_escribir_codigo,name=intESCRIBIRCODIGO}];
\def \ESCRIBIRCODIGOUP {intESCRIBIRCODIGO-1}
\def \ESCRIBIRCODIGODOWN {intESCRIBIRCODIGO-2}

\path [name intersections={of=circulo and path_correr_todas_pruebas_1,name=intCORRERTODASPRUEBASFIRST}];
\def \CORRERTODASPRUEBASFIRSTLEFT {intCORRERTODASPRUEBASFIRST-1}
\def \CORRERTODASPRUEBASFIRSTRIGHT {intCORRERTODASPRUEBASFIRST-2}

\path [name intersections={of=circulo and path_refactorizar,name=intREFACTORIZAR}];
\def \REFACTORIZARUP {intREFACTORIZAR-1}
\def \REFACTORIZARDOWN {intREFACTORIZAR-2}


\path [name intersections={of=circulo and path_correr_todas_pruebas_2,name=intCORRERTODASPRUEBASSECOND}];
\def \CORRERTODASPRUEBASSECONDUP {intCORRERTODASPRUEBASSECOND-1}
\def \CORRERTODASPRUEBASSECONDDOWN {intCORRERTODASPRUEBASSECOND-2}


\draw [->,bend left=15] (\ESCRIBIRRIGHT) to (\CORRERPRUEBAUP);
\draw [->,bend left=15] (node cs:name=correr_prueba, anchor=west) to  node [midway,left,pasastyle] { [pasa] } (node cs:name=escribir_prueba, anchor=south);
\draw [->,bend left=15] (\CORRERPRUEBADOWN) to node [midway,right,fallastyle] { [falla] } (\ESCRIBIRCODIGOUP);
\draw [->,bend left=15] (\ESCRIBIRCODIGODOWN) to (\CORRERTODASPRUEBASFIRSTRIGHT);
\draw [->,bend left=15] (node cs:name=correr_todas_pruebas_1, anchor=north) to  node [midway,left,fallastyle] { [falla] } (node cs:name=escribir_codigo, anchor=west);
\draw [->,bend left=15] (\CORRERTODASPRUEBASFIRSTLEFT) to node [midway,left,pasastyle] { [pasa] } (\REFACTORIZARDOWN);
\draw [->,bend left=15] (\REFACTORIZARUP) to (\CORRERTODASPRUEBASSECONDDOWN);
\draw [->,bend left=15] (node cs:name=correr_todas_pruebas_2, anchor=south) to  node [midway,right,fallastyle] { [falla] } (node cs:name=refactorizar, anchor=north);
\draw [->,bend left=15] (\CORRERTODASPRUEBASSECONDUP) to node [midway,left,pasastyle] { [pasa] }(\ESCRIBIRLEFT);


\draw [->,bend left=15] (node cs:name=start, anchor=east) to (node cs:name=escribir_prueba, anchor=north);
\end{tikzpicture}

我确信这不是最好的方法,但正如我所说,我对 tikz 很陌生,而且概念似乎很清晰:以nodes360/total_nodes 度绘制,找到节点和圆之间的交点,arc在交点之间绘制一个。

到目前为止一切顺利。现在我想这样做,这几乎是同样的事情: 在此处输入图片描述

我想制作 3 个气泡(prueba-codigo-refactor)node,这样我就可以做之前做过的事情。

此代码绘制了 3 个气泡:

\begin{tikzpicture}
\node [draw, circle, fill=white, minimum width=5em]at (0, 0){Prueba};
\node [draw, circle, fill=white, minimum width=5em]at (1.2, -0.6){Código};
\node [draw, circle, fill=white, minimum width=5em]at (1.2, 0.6){Refactor};
\end{tikzpicture}

但我需要整个东西都表现为一个节点。因此问题是:

  1. 我怎样才能使这 3 个气泡成为一个节点(并且表现得像一个节点),以便我可以做之前做过的事情?
  2. 这是我使用 tikz 一天的经验所想到的全部,你肯定更了解并且可能会想出更好的解决方案,我想听听!

我想学习 tikz,所以“这里,粘贴这段代码,然后就可以使用了,再见”对我来说不是最好的答案。另一方面,“看看这个链接,再见”对我来说有点难以理解,MME 会很棒(还有链接)。

答案1

由于节点形状并不特殊,不需要自定义路径,因此只要在某处放置一个节点,就可以放置两个节点。我设计了一种适用于此示例的样式,但您也可以使其更加自定义,以接受定位细节、颜色、样式等。

使用它时需要小心谨慎,因为如果您直接处理路径的底层气泡,它将覆盖气泡。有一些补救措施,但我不确定您是否需要它们。也append after command应该在路径内使用,但在这里我们只是冒险。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning}

\tikzset{single bubble/.style={draw, circle, fill=white, minimum width=5em},
tribubble/.style={
        single bubble,
        append after command={
             \pgfextra{\let\mylastnode\tikzlastnode} 
             node [single bubble, above right = 1mm and 5mm of \mylastnode.center] {Código}
             node [single bubble, below right = 1mm and 5mm of \mylastnode.center] {Refactor}
        }
    }
}


\begin{document}

\begin{tikzpicture}
    \draw (0,0) circle (3cm);
    \node[tribubble] at (45:3cm){Prueba};
    \node[tribubble] at (-45:3cm){Prueba};
\end{tikzpicture}


\end{document}

在此处输入图片描述

相关内容