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
|
% Copyright 2019 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.
\section{Views Library}
\label{section-library-views}
\begin{tikzlibrary}{views}
This library is used for creating \emph{views}, which are transformations
of a part of a picture so that this part ``fits'' into a ``viewbox''.
Mostly, views are useful in conjunction with animations.
\end{tikzlibrary}
A \emph{view} is essentially a ``window'' through which you see a graphic. To
establish a view, you specify a rectangle -- which is the window -- and another
rectangle surrounding the to-be-viewed graphic. The graphic will then be
rescaled and shifted in such a way that the to-be-viewed rectangle matches the
view's rectangle as well as possible. Note that establishing a view causes a
\emph{canvas} transformation to be installed, not a coordinate transformation.
View boxes are only seldom needed in normal graphics; you may prefer to use
coordinate transformations or the |spy| library. Their main application is with
animations since you can \emph{animate} the to-be-viewed rectangle. This makes
it easy to create animations in which you zoom in, zoom out, and pan a graphic.
\begin{key}{/tikz/meet=\meta{to-be-viewed corner}
\opt{|rectangle|} \meta{to-be-viewed corner} \opt{|at|
\meta{window corner} |rectangle| \meta{window corner}}%
}
Use this key with a scope to establish a view for the scope. In the
argument to the |meet| key, both |rectangle| texts are optional. Also,
everything following |at| is optional; when it is missing, the \meta{window
corner}s are assumed to be the same as the \meta{to-be-viewed corner}s. The
latter are two corners of a rectangle that should be transformed in such a
way that it fits inside the rectangle described by the two window corners.
More precisely, at the beginning of the scope a canvas transformation is
installed that scales and translates the canvas is such a way that
%
\begin{enumerate}
\item the center of the to-be-viewed rectangle lies at the center of
the window rectangle and
\item the to-be-viewed rectangle has maximum size that it still fits
inside the window rectangle.
\end{enumerate}
%
\begin{codeexample}[preamble={\usetikzlibrary{views}}]
\tikz {
\draw [red, very thick] (0,0) rectangle (20mm,20mm);
\begin{scope}[meet = {(0.5,0.5) (2.5,1.5) at (0,0) (2,2)}]
\draw [blue, very thick] (5mm,5mm) rectangle (25mm,15mm);
\draw [thick] (1,1) circle [x radius=5mm, y radius=10mm] node {Hi};
\end{scope} }
\end{codeexample}
%
\begin{codeexample}[preamble={\usetikzlibrary{views}}]
\tikz {
\draw [red, very thick] (0,0) rectangle (20mm,20mm);
\begin{scope}[slice = {(0.5,0.5) (2.5,1.5) at (0,0) (2,2)}]
\draw [blue, very thick] (5mm,5mm) rectangle (25mm,15mm);
\draw [thick] (1,1) circle [x radius=5mm, y radius=10mm] node {Hi};
\end{scope} }
\end{codeexample}
As mentioned earlier, the main use of views is in conjunction with
animations. In order to animate a view, you specify the scope containing
the |meet| command as the target object and then animate its |:view|
attribute:
%
\begin{codeexample}[preamble={\usetikzlibrary{animations,views}}]
\tikz [animate = {
my scope:view = {
begin on = { click, of next = here },
0s = "{(0.5,0.5) (2.5,1.5)}",
2s = "{(0.5,0) (1.5,2)}", forever
}}] {
\draw [red, fill=red!20, very thick, name=here]
(0,0) rectangle (20mm,20mm);
\begin{scope}[name = my scope,
meet = {(0.5,0.5) (2.5,1.5) at (0,0) (2,2)}]
\draw [blue, very thick] (5mm,5mm) rectangle (25mm,15mm);
\draw [thick] (1,1) circle [x radius=5mm, y radius=10mm] node {Hi};
\end{scope} }
\end{codeexample}
%
You can, of course, also specify the animation using the |animate myself:|
key when you specify the animation inside the scope:
%
\begin{codeexample}[preamble={\usetikzlibrary{animations,views}}]
\tikz [animate = {
my scope:view = {
}}] {
\draw [red, fill=red!20, very thick, name=here]
(0,0) rectangle (20mm,20mm);
\begin{scope}[animate = { myself: = { :view = {
begin on = { click, of = here },
0s = "{(0.5,0.5) (2.5,1.5)}",
2s = "{(0.5,0) (1.5,2)}", forever }}},
slice = {(0.5,0.5) (2.5,1.5) at (0,0) (2,2)}]
\draw [blue, very thick] (5mm,5mm) rectangle (25mm,15mm);
\draw [thick] (1,1) circle [x radius=5mm, y radius=10mm] node {Hi};
\end{scope} }
\end{codeexample}
%
\end{key}
\begin{key}{/tikz/view}
This is an alias for |/tikz/meet|.
\end{key}
\begin{key}{/tikz/slice=\meta{to-be-viewed corner}
\opt{|rectangle|} \meta{to-be-viewed corner} \opt{|at|
\meta{window corner} |rectangle| \meta{window corner}}%
}
This key works exactly like |meet|, only the second rule is changed:
%
\begin{enumerate}
\item[$2'$.] the to-be-viewed rectangle has minimal size that it
encompasses all of the window rectangle.
\end{enumerate}
\end{key}
|