Using the following code I am trying to visualize nested circles:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,fpu}
\usetikzlibrary{decorations.text}
\begin{document}
\def\sizeA{1.248800}
\def\sizeB{.801900}
\def\sizeC{.450300}
\def\sizeD{.255400}
\def\baseRad{5}
\begin{tikzpicture}[rotate=90,%
textDiscLabel/.style={%
postaction={%
decorate,decoration={%
text along path,%
reverse path=true,%
raise=-2ex,%
text={#1}}
}
}
]
\pgfmathsetmacro{\dRatio}{(\sizeD)/(\sizeA)}
\pgfmathsetmacro{\cRatio}{(\sizeC)/(\sizeA)}
\pgfmathsetmacro{\bRatio}{(\sizeB)/(\sizeA)}
\draw[fill=black!30] (0,0) circle (\baseRad);
\path [textDiscLabel={Size A - 1,248,800}] (0,0) circle (\baseRad);
\pgfmathparse{\baseRad*(\bRatio-1)}
\draw[fill=red!40] (\pgfmathresult,0) circle (\bRatio*\baseRad);
\path [textDiscLabel={Size B - 801,900}] (\pgfmathresult,0) circle (\bRatio*\baseRad);
\pgfmathparse{\baseRad*(\cRatio-1)}
\draw[fill=green!50] (\pgfmathresult,0) circle (\cRatio*\baseRad);
\path [textDiscLabel={Size C - 450,300}] (\pgfmathresult,0) circle (\cRatio*\baseRad);
\pgfmathparse{\baseRad*(\dRatio-1)}
\draw[fill=blue!40] (\pgfmathresult,0) circle (\dRatio*\baseRad);
\path [textDiscLabel={Size D - 255,400}] (\pgfmathresult,0) circle (\dRatio*\baseRad);
\end{tikzpicture}
\end{document}
This yields the following picture:
I fail to adjust the positioning of the text along the perimeter of the discs. In particular, I want it to be centered with respect to the vertical line passing through the centers of the circles. How can I do it? I am looking for a programmed solution because the values that I use may (and will) vary (and thus the radii of the discs).
Bonus question: as you see, the values that I have are between 10^6 to 10^5. PGF
fails to do the computations for the ratios (sizeA
is too big). How can I overcome this and automate the computation and the labeling?
Best Answer
The following should help simply things somewhat. The
text align
key centers the decoration text on the path, but I would use arcs to draw the circle, as it is easier to start the circle borders from the same point and also to know in advance where the center of the the path is located.Also a partial and not particularly robust (or accurate) solution to the scaling problem: use
sp
units in the ratio calculations. Note the formatting in the numbers from the OPs post is lost.