Debian Codegraph @

texmf-dist/doc/generic/pgf/pgfmanual-en-library-views.tex

raw
1 % Copyright 2019 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 Free Documentation License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9
10
11 \section{Views Library}
12 \label{section-library-views}
13
14 \begin{tikzlibrary}{views}
15 This library is used for creating \emph{views}, which are transformations
16 of a part of a picture so that this part ``fits'' into a ``viewbox''.
17 Mostly, views are useful in conjunction with animations.
18 \end{tikzlibrary}
19
20 A \emph{view} is essentially a ``window'' through which you see a graphic. To
21 establish a view, you specify a rectangle -- which is the window -- and another
22 rectangle surrounding the to-be-viewed graphic. The graphic will then be
23 rescaled and shifted in such a way that the to-be-viewed rectangle matches the
24 view's rectangle as well as possible. Note that establishing a view causes a
25 \emph{canvas} transformation to be installed, not a coordinate transformation.
26
27 View boxes are only seldom needed in normal graphics; you may prefer to use
28 coordinate transformations or the |spy| library. Their main application is with
29 animations since you can \emph{animate} the to-be-viewed rectangle. This makes
30 it easy to create animations in which you zoom in, zoom out, and pan a graphic.
31
32 \begin{key}{/tikz/meet=\meta{to-be-viewed corner}
33 \opt{|rectangle|} \meta{to-be-viewed corner} \opt{|at|
34 \meta{window corner} |rectangle| \meta{window corner}}%
35 }
36 Use this key with a scope to establish a view for the scope. In the
37 argument to the |meet| key, both |rectangle| texts are optional. Also,
38 everything following |at| is optional; when it is missing, the \meta{window
39 corner}s are assumed to be the same as the \meta{to-be-viewed corner}s. The
40 latter are two corners of a rectangle that should be transformed in such a
41 way that it fits inside the rectangle described by the two window corners.
42
43 More precisely, at the beginning of the scope a canvas transformation is
44 installed that scales and translates the canvas is such a way that
45 %
46 \begin{enumerate}
47 \item the center of the to-be-viewed rectangle lies at the center of
48 the window rectangle and
49 \item the to-be-viewed rectangle has maximum size that it still fits
50 inside the window rectangle.
51 \end{enumerate}
52 %
53 \begin{codeexample}[preamble={\usetikzlibrary{views}}]
54 \tikz {
55 \draw [red, very thick] (0,0) rectangle (20mm,20mm);
56 \begin{scope}[meet = {(0.5,0.5) (2.5,1.5) at (0,0) (2,2)}]
57 \draw [blue, very thick] (5mm,5mm) rectangle (25mm,15mm);
58 \draw [thick] (1,1) circle [x radius=5mm, y radius=10mm] node {Hi};
59 \end{scope} }
60 \end{codeexample}
61 %
62 \begin{codeexample}[preamble={\usetikzlibrary{views}}]
63 \tikz {
64 \draw [red, very thick] (0,0) rectangle (20mm,20mm);
65 \begin{scope}[slice = {(0.5,0.5) (2.5,1.5) at (0,0) (2,2)}]
66 \draw [blue, very thick] (5mm,5mm) rectangle (25mm,15mm);
67 \draw [thick] (1,1) circle [x radius=5mm, y radius=10mm] node {Hi};
68 \end{scope} }
69 \end{codeexample}
70
71 As mentioned earlier, the main use of views is in conjunction with
72 animations. In order to animate a view, you specify the scope containing
73 the |meet| command as the target object and then animate its |:view|
74 attribute:
75 %
76 \begin{codeexample}[preamble={\usetikzlibrary{animations,views}}]
77 \tikz [animate = {
78 my scope:view = {
79 begin on = { click, of next = here },
80 0s = "{(0.5,0.5) (2.5,1.5)}",
81 2s = "{(0.5,0) (1.5,2)}", forever
82 }}] {
83 \draw [red, fill=red!20, very thick, name=here]
84 (0,0) rectangle (20mm,20mm);
85 \begin{scope}[name = my scope,
86 meet = {(0.5,0.5) (2.5,1.5) at (0,0) (2,2)}]
87 \draw [blue, very thick] (5mm,5mm) rectangle (25mm,15mm);
88 \draw [thick] (1,1) circle [x radius=5mm, y radius=10mm] node {Hi};
89 \end{scope} }
90 \end{codeexample}
91 %
92 You can, of course, also specify the animation using the |animate myself:|
93 key when you specify the animation inside the scope:
94 %
95 \begin{codeexample}[preamble={\usetikzlibrary{animations,views}}]
96 \tikz [animate = {
97 my scope:view = {
98 }}] {
99 \draw [red, fill=red!20, very thick, name=here]
100 (0,0) rectangle (20mm,20mm);
101 \begin{scope}[animate = { myself: = { :view = {
102 begin on = { click, of = here },
103 0s = "{(0.5,0.5) (2.5,1.5)}",
104 2s = "{(0.5,0) (1.5,2)}", forever }}},
105 slice = {(0.5,0.5) (2.5,1.5) at (0,0) (2,2)}]
106 \draw [blue, very thick] (5mm,5mm) rectangle (25mm,15mm);
107 \draw [thick] (1,1) circle [x radius=5mm, y radius=10mm] node {Hi};
108 \end{scope} }
109 \end{codeexample}
110 %
111 \end{key}
112
113 \begin{key}{/tikz/view}
114 This is an alias for |/tikz/meet|.
115 \end{key}
116
117 \begin{key}{/tikz/slice=\meta{to-be-viewed corner}
118 \opt{|rectangle|} \meta{to-be-viewed corner} \opt{|at|
119 \meta{window corner} |rectangle| \meta{window corner}}%
120 }
121 This key works exactly like |meet|, only the second rule is changed:
122 %
123 \begin{enumerate}
124 \item[$2'$.] the to-be-viewed rectangle has minimal size that it
125 encompasses all of the window rectangle.
126 \end{enumerate}
127 \end{key}