summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/tikz-ext/tikzlibraryext.positioning-plus.code.tex
blob: a29d4ace64950b18456f02dc6830ec55719543d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
% This is the TikZ library positioning-plus
% Load with \usetikzlibrary{positioning-plus}
%
% This small library extends TikZ options like 'above', 'left' or 'below right'
% so that they can be used with an optional prefixed factor seperated by ':' (colon)
%
% The option 'left=.5:of somenode' will place
% a new node .5cm (default 'node distance' is '1cm and 1cm') left to (somenode).
% The option 'above right=.2 and .7:of someothernode' will place
% a new node .2cm above and .7cm right of (someothernode).
%
% Additional the options 'xshift*' and 'yshift*' add an additional shift
% as a factor of 'node distance'
% Inspired by http://tex.stackexchange.com/a/117610/16595

\usetikzlibrary{positioning}
\usetikzlibrary{fit}

\pgfdeclaregenericanchor{corner south east}{%
  \pgf@sh@reanchor{#1}{south}%
  \pgf@ya\pgf@y
  \pgf@process{\pgf@sh@reanchor{#1}{east}}%
  \pgf@y\pgf@ya
}
\pgfdeclaregenericanchor{corner north east}{%
  \pgf@sh@reanchor{#1}{north}%
  \pgf@ya\pgf@y
  \pgf@process{\pgf@sh@reanchor{#1}{east}}%
  \pgf@y\pgf@ya
}
\pgfdeclaregenericanchor{corner south west}{%
  \pgf@sh@reanchor{#1}{south}%
  \pgf@ya\pgf@y
  \pgf@process{\pgf@sh@reanchor{#1}{west}}%
  \pgf@y\pgf@ya
}
\pgfdeclaregenericanchor{corner north west}{%
  \pgf@sh@reanchor{#1}{north}%
  \pgf@ya\pgf@y
  \pgf@process{\pgf@sh@reanchor{#1}{west}}%
  \pgf@y\pgf@ya
}

\tikzset{corner above left/.code=\tikz@lib@place@handle@{#1}{corner south east}{-1}{1}{corner north west}{0.707106781}}
\tikzset{corner above right/.code=\tikz@lib@place@handle@{#1}{corner south west}{1}{1}{corner north east}{0.707106781}}
\tikzset{corner below left/.code=\tikz@lib@place@handle@{#1}{corner north east}{-1}{-1}{corner south west}{0.707106781}}
\tikzset{corner below right/.code=\tikz@lib@place@handle@{#1}{corner north west}{1}{-1}{corner south east}{0.707106781}}

\tikzset{corner north left/.code =\tikz@lib@place@handle@{#1}{corner north east}{-1}{0}{corner north west}{1}}
\tikzset{corner north right/.code=\tikz@lib@place@handle@{#1}{corner north west}{1}{0}{corner north east}{1}}
\tikzset{corner south left/.code =\tikz@lib@place@handle@{#1}{corner south east}{-1}{0}{corner south west}{1}}
\tikzset{corner south right/.code=\tikz@lib@place@handle@{#1}{corner south west}{1}{0}{corner south east}{1}}

\tikzset{corner west above/.code =\tikz@lib@place@handle@{#1}{corner south west}{0}{1}{corner north west}{1}}
\tikzset{corner west below/.code=\tikz@lib@place@handle@{#1}{corner north west}{0}{-1}{corner south west}{1}}
\tikzset{corner east above/.code =\tikz@lib@place@handle@{#1}{corner south east}{0}{1}{corner north east}{1}}
\tikzset{corner east below/.code=\tikz@lib@place@handle@{#1}{corner north east}{0}{-1}{corner south east}{1}}

\tikzset{north left/.code =\tikz@lib@place@handle@{#1}{north east}{-1}{0}{north west}{1}}
\tikzset{north right/.code=\tikz@lib@place@handle@{#1}{north west}{1}{0}{north east}{1}}
\tikzset{south left/.code =\tikz@lib@place@handle@{#1}{south east}{-1}{0}{south west}{1}}
\tikzset{south right/.code=\tikz@lib@place@handle@{#1}{south west}{1}{0}{south east}{1}}

\tikzset{west above/.code =\tikz@lib@place@handle@{#1}{south west}{0}{1}{north west}{1}}
\tikzset{west below/.code=\tikz@lib@place@handle@{#1}{north west}{0}{-1}{south west}{1}}
\tikzset{east above/.code =\tikz@lib@place@handle@{#1}{south east}{0}{1}{north east}{1}}
\tikzset{east below/.code=\tikz@lib@place@handle@{#1}{north east}{0}{-1}{south east}{1}}

\newif\ifqrr@tikz@lib@place@postransform
\tikzset{node distance transformation/.is if=qrr@tikz@lib@place@postransform}
\def\tikz@lib@place@handle@@#1#2#3#4{%
  \pgfutil@in@{of }{#1}%
  \ifpgfutil@in@
    \tikz@lib@place@of#1\tikz@stop{#4}%
  \else
    \edef\tikz@lib@place@nums{#1}%
  \fi
  \ifx\tikz@lib@place@nums\pgfutil@empty
    % Ok, nothing to do, we have set the anchor and we are happy...
  \else
    \expandafter\tikz@lib@place@parse@nums\expandafter{\tikz@lib@place@nums}%
    \pgf@x=#2\pgf@x
    \pgf@y=#3\pgf@y
    \ifqrr@tikz@lib@place@postransform
      \pgf@pos@transform{\pgf@x}{\pgf@y}% change from original
    \fi
    \edef\tikz@lib@pos@call{\noexpand\pgftransformshift{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}%
  \fi
}

\def\tikz@lib@place@handle@#1#2#3#4#5#6{%
  \pgfutil@in@{:}{#1}%
  \ifpgfutil@in@
    \tikz@lib@place@handle@qrr@#1\tikz@stop
    \ifx\pgf@temp\pgfutil@empty
      \let\pgf@temp\tikz@node@distance
    \fi
    \pgfmathsetmacro\pgf@tempa{(\pgf@tempa)*#4}%
    \pgfmathsetmacro\pgf@tempb{(\pgf@tempb)*#3}%
    \edef\pgf@marshal{\noexpand\tikz@lib@place@handle@{\pgf@temp}{#2}{\pgf@tempb}{\pgf@tempa}{#5}{#6}}%
    \pgf@marshal
  \else
    \def\tikz@anchor{#2}%
    \let\tikz@do@auto@anchor=\relax
    \edef\tikz@temp{#1}%
    \def\tikz@lib@place@single@factor{#6}%
    \expandafter\tikz@lib@place@handle@@\expandafter{\tikz@temp}{#3}{#4}{#5}%
  \fi
}
\def\tikz@lib@place@handle@qrr@#1:#2\tikz@stop{%
  \pgfutil@in@{and}{#1}%
  \ifpgfutil@in@
    \tikz@lib@place@handle@qrr@@#1\tikz@stop
  \else
    \tikz@lib@place@handle@qrr@@#1and#1\tikz@stop
  \fi
  \def\pgf@temp{#2}%
}
\def\tikz@lib@place@handle@qrr@@#1and#2\tikz@stop{%
  \def\pgf@tempa{#1}%
  \def\pgf@tempb{#2}%
}
\def\qrr@xyshift@starred#1#2#3{%
  \edef\tikz@marshal{\noexpand\pgfutil@in@{and}{\tikz@node@distance}}%
  \tikz@marshal
  \ifpgfutil@in@
    \expandafter\tikz@lib@place@handle@qrr@@\tikz@node@distance\tikz@stop
  \else
    \let#3\tikz@node@distance
  \fi
  \pgfmathparse{(#1)*#3}%
  \ifpgfmathunitsdeclared
    \if#2x%
      \pgftransformshift{\pgfqpoint{\pgfmathresult pt}{0pt}}%
    \else
      \pgftransformshift{\pgfqpoint{0pt}{\pgfmathresult pt}}%
    \fi
  \else
    \ifx#2x%
      \pgf@process{\pgfqpointxy{\pgfmathresult}{0}}%
    \else
      \pgf@process{\pgfqpointxy{0}{\pgfmathresult}}%
    \fi
    \pgftransformshift{\pgfqpoint{\pgf@x}{\pgf@y}}%
  \fi}
\tikzset{
  xshift*/.code=\qrr@xyshift@starred{#1}x\pgf@tempb,
  yshift*/.code=\qrr@xyshift@starred{#1}y\pgf@tempa
}

\def\pgfutil@firstofmany#1#2\pgf@stop{#1}
\def\pgfutil@secondofmany#1#2\pgf@stop{#2}
\def\tikz@lib@place@of@#1#2#3{%
  \def\pgf@tempa{fit bounding box}%
  \edef\pgf@temp{\expandafter\pgfutil@firstofmany#2\pgf@stop}
  \if\pgf@temp(%
    \tikz@lib@place@fit@scan{#2}{0}%
  \else\if\pgf@temp|%
      \expandafter\tikz@lib@place@fit@scan\expandafter{\pgfutil@secondofmany#2\pgf@stop}{1}%
    \else\ifx\pgf@temp\tikz@activebar
        \expandafter\tikz@lib@place@fit@scan\expandafter{\pgfutil@secondofmany#2\pgf@stop}{1}%
      \else\if\pgf@temp-%
          \expandafter\tikz@lib@place@fit@scan\expandafter{\pgfutil@secondofmany#2\pgf@stop}{2}%
        \else\if\pgf@temp+%
            \expandafter\tikz@lib@place@fit@scan\expandafter{\pgfutil@secondofmany#2\pgf@stop}{3}%
          \else
            \def\pgf@tempa{#2}%
          \fi
        \fi
      \fi
    \fi
  \fi
  \expandafter\tikz@scan@one@point\expandafter\tikz@lib@place@remember\expandafter(\pgf@tempa)%
  \iftikz@shapeborder%
    % Ok, this is relative to a border.
    \iftikz@lib@ignore@size%
      \edef\tikz@node@at{\noexpand\pgfpointanchor{\tikz@shapeborder@name}{center}}%
      \def\tikz@anchor{center}%
    \else%
      \edef\tikz@node@at{\noexpand\pgfpointanchor{\tikz@shapeborder@name}{#3}}%
    \fi%
  \fi%
  \edef\tikz@lib@place@nums{#1}%
}
\def\tikz@lib@place@fit@scan#1#2{%
  \pgf@xb=-16000pt\relax%
  \pgf@xa=16000pt\relax%
  \pgf@yb=-16000pt\relax%
  \pgf@ya=16000pt\relax%
  \if\pgfutil@firstofmany#1\pgf@stop(%
    \tikz@lib@fit@scan#1\pgf@stop%
  \else
    \tikz@lib@fit@scan(#1)\pgf@stop
  \fi
  \ifdim\pgf@xa>\pgf@xa
    % shouldn't happen
  \else
     \expandafter\def\csname pgf@sh@ns@fit bounding box\endcsname{rectangle}%
     \expandafter\edef\csname pgf@sh@np@fit bounding box\endcsname{%
       \def\noexpand\southwest{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}%
       \def\noexpand\northeast{\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}%
     }%
     \expandafter\def\csname pgf@sh@nt@fit bounding box\endcsname{{1}{0}{0}{1}{0pt}{0pt}}%
     \expandafter\def\csname pgf@sh@pi@fit bounding box\expandafter\endcsname\expandafter{\pgfpictureid}%
     \ifcase#2\relax
     \or % 1 = vertical
       \pgf@y=\pgf@yb%
       \advance\pgf@y by-\pgf@ya%
       \edef\pgf@marshal{\noexpand\pgfset{minimum height={\the\pgf@y-2*(\noexpand\pgfkeysvalueof{/pgf/outer ysep})}}}%
       \pgf@marshal
     \or % 2 = horizontal
       \pgf@x=\pgf@xb%
       \advance\pgf@x by-\pgf@xa%
       \edef\pgf@marshal{\noexpand\pgfset{minimum width={\the\pgf@x-2*(\noexpand\pgfkeysvalueof{/pgf/outer xsep})}}}%
       \pgf@marshal
     \or % 3 = both directions
       \pgf@y=\pgf@yb%
       \advance\pgf@y by-\pgf@ya%
       \pgf@x=\pgf@xb%
       \advance\pgf@x by-\pgf@xa%
       \edef\pgf@marshal{\noexpand\pgfset{minimum height={\the\pgf@y-2*(\noexpand\pgfkeysvalueof{/pgf/outer ysep})},minimum width={\the\pgf@x-2*(\noexpand\pgfkeysvalueof{/pgf/outer xsep})}}}%
       \pgf@marshal
     \fi
  \fi
}
\tikzset{
  fit bounding box/.code={\tikz@lib@place@fit@scan{#1}{0}},
  span vertical/.code={\tikz@lib@place@fit@scan{#1}{1}},
  span horizontal/.code={\tikz@lib@place@fit@scan{#1}{2}},
  span/.code={\tikz@lib@place@fit@scan{#1}{3}}}

\pgfmathdeclarefunction{x_node_dist}{0}{%
  \begingroup
    \edef\pgfmath@temp{\noexpand\pgfutil@in@{and}{\tikz@node@distance}}%
    \pgfmath@temp\ifpgfutil@in@
      \expandafter\tikz@lib@place@handle@qrr@@\tikz@node@distance\tikz@stop
    \else
      \let\pgf@tempb\tikz@node@distance
    \fi
    \pgfmathparse{\pgf@tempb}%
    \pgfmath@smuggleone\pgfmathresult
  \endgroup
}
\pgfmathdeclarefunction{y_node_dist}{0}{%
  \begingroup
    \edef\pgfmath@temp{\noexpand\pgfutil@in@{and}{\tikz@node@distance}}%
    \pgfmath@temp\ifpgfutil@in@
      \expandafter\tikz@lib@place@handle@qrr@@\tikz@node@distance\tikz@stop
    \else
      \let\pgf@tempa\tikz@node@distance
    \fi
    \pgfmathparse{\pgf@tempa}%
    \pgfmath@smuggleone\pgfmathresult
  \endgroup
}
%\tikzdeclarecoordinatesystem{node distance}{%
%  \tikz@cs@nd#1\tikz@stop}
%\def\tikz@cs@nd#1,#2\tikz@stop{%
%  \def\qrr@xyshift@starred@action##1{\pgftransformshift{##1}}%
%  \qrr@xyshift@starred{#1}x\pgf@tempb
%  \qrr@xyshift@starred{#2}y\pgf@tempa}
\endinput