Debian Codegraph @

texmf-dist/tex/generic/pgf/libraries/datavisualization/pgflibrarydatavisualization.polar.code.tex

raw
1 % Copyright 2018 by Till Tantau
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Public License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9
10 \ProvidesFileRCS{pgflibrarydatavisualization.polar.code.tex}
11
12 \usepgfmodule{datavisualization}%
13
14 % This file defines code for doing plots involving polar
15 % coordinates. This includes not only standard polar plots, but also
16 % pie charts.
17
18
19
20 \pgfooclass{polar transformer}
21 {%
22 % Class polar mapper
23 %
24 % A polar mapper is used to transform attributes given as (2d) polar
25 % coordinates to canvas coordinates. Note that no special ranges
26 % can be specified and that the angle must be given in degrees. You
27 % can, however, use a standard mapper to change these things.
28
29 \attribute angle;%
30 % The attribute from which the angle is read.
31
32 \attribute radius;%
33 % The attribute from which the radius is read.
34
35 \attribute unit vector 0 degrees;%
36 % The unit vector 0 degrees
37
38 \attribute unit vector 90 degrees;%
39 % The unit vector 90 degrees
40
41
42
43 % Constructor
44 %
45 % #1 = angle attribute. Example: rotation.
46 % #2 = radius attribute. Example: height.
47 % #3 = unit vector 0 degrees
48 % #4 = unit vector 90 degrees
49 %
50 \method polar transformer(#1,#2,#3,#4) {
51 \pgfooset{angle}{#1}
52 \pgfooset{radius}{#2}
53 \pgfooset{unit vector 0 degrees}{#3}
54 \pgfooset{unit vector 90 degrees}{#4}
55 }%
56
57 % Method
58 \method default connects() {
59 \pgfoothis.get handle(\pgf@dv@me)
60 \pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,transform,transform datapoint signal)
61 \pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,path,path signal)
62 \pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,direction,direction signal)
63 }%
64
65 % Getters
66 \method get angle attribute(#1) {
67 \pgfooget{angle}{#1}
68 }%
69
70 \method get radius attribute(#1) {
71 \pgfooget{radius}{#1}
72 }%
73
74
75 % Slot
76 %
77 % This slot should be connected to the transform datapoint
78 % signal. When this signal is emitted, the coordinate system will be
79 % shifted according to the current value of the attribute.
80 \method transform() {
81 \pgfkeysgetvalue{/data point/\pgfoovalueof{angle}/const}\pgf@dv@angle%
82 \ifx\pgf@dv@angle\relax
83 \pgfkeysgetvalue{/data point/\pgfoovalueof{angle}}\pgf@dv@angle%
84 \fi
85 \ifx\pgf@dv@angle\relax\else%
86 \ifx\pgf@dv@angle\pgfutil@empty\else%
87 \pgfkeysgetvalue{/data point/\pgfoovalueof{radius}/const}\pgf@dv@radius%
88 \ifx\pgf@dv@radius\relax
89 \pgfkeysgetvalue{/data point/\pgfoovalueof{radius}}\pgf@dv@radius%
90 \fi
91 \ifx\pgf@dv@radius\pgfutil@empty\else%
92 \ifx\pgf@dv@radius\relax\else%
93 \pgfdvmathenter{\pgf@dv@val}{\pgf@dv@angle}%
94 \pgfdvmathexitbyscientificformat{\pgf@dv@angle}{\pgf@dv@val}%
95 \pgfdvmathenter{\pgf@dv@val}{\pgf@dv@radius}%
96 \pgfdvmathexitbyscientificformat{\pgf@dv@radius}{\pgf@dv@val}%
97 \pgfmathsincos{\pgf@dv@angle}%
98 \pgfmathmultiply{\pgfmathresultx}{\pgf@dv@radius}%
99 \let\pgf@dv@polar@temp=\pgfmathresult
100 \pgftransformshift{\pgfpointscale{\pgf@dv@polar@temp}{\pgfoovalueof{unit vector 0 degrees}}}%
101 \pgfmathmultiply{\pgfmathresulty}{\pgf@dv@radius}%
102 \let\pgf@dv@polar@temp=\pgfmathresult
103 \pgftransformshift{\pgfpointscale{\pgf@dv@polar@temp}{\pgfoovalueof{unit vector 90 degrees}}}%
104 \fi%
105 \fi%
106 \fi%
107 \fi%
108 }%
109
110
111
112 % Reaction to the path signal
113 %
114 % Here is what we do: When a pgfdvpathmoveto is done, the radius and
115 % the angle are recorded. When a pgfdvpathlineto is done, the saved
116 % radius and angle are compared with the new angle and radius. If,
117 % and only if, the radius is the same, but the angle is different,
118 % the lineto is caught and replaced by an arc from the previous
119 % position to the new position.
120
121 \attribute prev angle;%
122 \attribute prev radius;%
123
124 \method path(#1) {%
125 \ifpgfdvhandled%
126 \else%
127 \ifx#1\pgfdvpathlinetotoken
128 % Ok, let us have a look...
129 \pgfooget{prev radius}\pgf@dv@prev@rad
130 \pgfkeysgetvalue{/data point/\pgfoovalueof{radius}}\pgf@dv@current@rad
131 \ifx\pgf@dv@current@rad\relax
132 \else
133 \ifx\pgf@dv@current@rad\pgf@dv@prev@rad%
134 \pgfooget{prev angle}\pgf@dv@prev@angle
135 \pgfkeysgetvalue{/data point/\pgfoovalueof{angle}}\pgf@dv@current@angle
136 \ifx\pgf@dv@current@angle\relax
137 \else
138 \ifx\pgf@dv@current@angle\pgf@dv@prev@angle%
139 % do nothing
140 \else%
141 % Do arc:
142 \pgfdvmathenter{\pgf@dv@val}{\pgf@dv@prev@angle}%
143 \pgfdvmathexitbyscientificformat{\pgf@dv@prev@angle}{\pgf@dv@val}%
144 \pgfdvmathenter{\pgf@dv@val}{\pgf@dv@prev@rad}%
145 \pgfdvmathexitbyscientificformat{\pgf@dv@prev@rad}{\pgf@dv@val}%
146 \pgfdvmathenter{\pgf@dv@val}{\pgf@dv@current@angle}%
147 \pgfdvmathexitbyscientificformat{\pgf@dv@current@angle}{\pgf@dv@val}%
148 \pgfdvmathenter{\pgf@dv@val}{\pgf@dv@current@rad}%
149 \pgfdvmathexitbyscientificformat{\pgf@dv@current@rad}{\pgf@dv@val}%
150 \pgfpatharcaxes{\pgf@dv@prev@angle}{\pgf@dv@current@angle}
151 {\pgfpointscale{\pgf@dv@current@rad}{\pgfoovalueof{unit vector 0 degrees}}}
152 {\pgfpointscale{\pgf@dv@current@rad}{\pgfoovalueof{unit vector 90 degrees}}}%
153 \pgfdvhandledtrue%
154 \fi%
155 \fi%
156 \fi%
157 \fi%
158 \fi%
159 \fi%
160 % No matter what, record the current position
161 \pgfooeset{prev angle}{\pgfkeysvalueof{/data point/\pgfoovalueof{angle}}}
162 \pgfooeset{prev radius}{\pgfkeysvalueof{/data point/\pgfoovalueof{radius}}}
163 }%
164
165 % Method
166 %
167 % React to direction signals. See pgfpointdvdirection for an
168 % explanation
169 %
170 \method direction(#1) {%
171 \ifx#1\pgfdvdirectionfromtoken
172 % Record from angle and radius
173 \xdef\pgf@dv@polar@from@angle{\pgfkeysvalueof{/data point/\pgfoovalueof{angle}}}
174 \xdef\pgf@dv@polar@from@radius{\pgfkeysvalueof{/data point/\pgfoovalueof{radius}}}
175 \else\ifx#1\pgfdvdirectiontotoken%
176 % Record to angle and radius
177 \xdef\pgf@dv@polar@to@angle{\pgfkeysvalueof{/data point/\pgfoovalueof{angle}}}
178 \xdef\pgf@dv@polar@to@radius{\pgfkeysvalueof{/data point/\pgfoovalueof{radius}}}
179 \else%
180 \ifx\pgf@dv@polar@from@radius\pgf@dv@polar@to@radius%
181 \pgfdvmathenter{\pgf@dv@a}{\pgf@dv@polar@from@angle}%
182 \pgfdvmathenter{\pgf@dv@b}{\pgf@dv@polar@to@angle}%
183 \pgfdvmathifless{\pgf@dv@a}{\pgf@dv@b}{\def\pgf@dv@temp@sign{+}}{\def\pgf@dv@temp@sign{-}}%
184 \pgfkeysgetvalue{/data point/\pgfoovalueof{angle}}\pgf@temp%
185 \ifx\pgf@temp\relax%
186 \else%
187 \pgfdvmathenter{\pgf@dv@val}{\pgf@temp}%
188 \pgfdvmathexitbyscientificformat{\pgf@dv@polar@angle}{\pgf@dv@val}%
189 \pgf@process{\pgfpointpolar{\pgf@dv@polar@angle\pgf@dv@temp@sign90}{1pt}}%
190 \pgfdvhandledtrue%
191 \fi%
192 \fi%
193 \fi\fi%
194 }%
195 }%
196
197
198 \endinput