Debian Codegraph @

texmf-dist/doc/generic/pgf/pgfmanual-en-library-er.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{Entity-Relationship Diagram Drawing Library}
12
13 \begin{tikzlibrary}{er}
14 This packages provides styles for drawing entity-relationship diagrams.
15 \end{tikzlibrary}
16
17 This library is intended to help you in creating E/R-diagrams. It defines only
18 few new styles, but using the style |entity| instead of saying |rectangle,draw|
19 makes the code more expressive.
20
21
22 \subsection{Entities}
23
24 The package defines a simple style for drawing entities:
25
26 \begin{stylekey}{/tikz/entity}
27 This style is to be used with nodes that represent entity types. It causes
28 the node's shape to be set to a rectangle that is drawn and whose minimum
29 size and width are set to sensible values.
30
31 Note that this style is called |entity| despite the fact that it is to be
32 used for nodes representing entity \emph{types} (the difference between an
33 entity and an entity type is the same as the difference between an object
34 and a class in object-oriented programming). If this bothers you, feel free
35 to define a style |entity type| instead.
36 %
37 \begin{codeexample}[preamble={\usetikzlibrary{er,positioning}}]
38 \begin{tikzpicture}
39 \node[entity] (sheep) {Sheep};
40 \node[entity] (genome) [right=of sheep] {Genome};
41 \end{tikzpicture}
42 \end{codeexample}
43 %
44 \end{stylekey}
45
46 \begin{stylekey}{/tikz/every entity}
47 This style is evoked by the style |entity|. To change the appearance of
48 entities, you can change this style.
49 %
50 \begin{codeexample}[preamble={\usetikzlibrary{er,positioning}}]
51 \begin{tikzpicture}
52 [every entity/.style={draw=blue!50,fill=blue!20,thick}]
53 \node[entity] (sheep) {Sheep};
54 \node[entity] (genome) [right=of sheep] {Genome};
55 \end{tikzpicture}
56 \end{codeexample}
57 %
58 \end{stylekey}
59
60
61 \subsection{Relationships}
62
63 Relationships are drawn using styles that are very similar to the styles for
64 entities.
65
66 \begin{stylekey}{/tikz/relationship}
67 This style works like |entity|, only it is to be used for relationships.
68 Again, |relationship|s are actually relationship types.
69 %
70 \begin{codeexample}[preamble={\usetikzlibrary{er}}]
71 \begin{tikzpicture}
72 \node[entity] (sheep) at (0,0) {Sheep};
73 \node[entity] (genome) at (2,0) {Genome};
74 \node[relationship] at (1,1.5) {has}
75 edge (sheep)
76 edge (genome);
77 \end{tikzpicture}
78 \end{codeexample}
79 %
80 \end{stylekey}
81
82 \begin{stylekey}{/tikz/every relationship}
83 Works like |every entity|.
84 %
85 \begin{codeexample}[preamble={\usetikzlibrary{er}}]
86 \begin{tikzpicture}
87 [every entity/.style={fill=blue!20,draw=blue,thick},
88 every relationship/.style={fill=orange!20,draw=orange,thick,aspect=1.5}]
89 \node[entity] (sheep) at (0,0) {Sheep};
90 \node[entity] (genome) at (2,0) {Genome};
91 \node[relationship] at (1,1.5) {has}
92 edge (sheep)
93 edge (genome);
94 \end{tikzpicture}
95 \end{codeexample}
96 %
97 \end{stylekey}
98
99
100 \subsection{Attributes}
101
102 \begin{stylekey}{/tikz/attribute}
103 This style is used to indicate that a node is an attribute. To connect an
104 attribute to its entity, you can use, for example, the |child| command or
105 the |pin| option.
106 %
107 \begin{codeexample}[preamble={\usetikzlibrary{er}}]
108 \begin{tikzpicture}
109 \node[entity] (sheep) {Sheep}
110 child {node[attribute] {name}}
111 child {node[attribute] {color}};
112 \end{tikzpicture}
113 \end{codeexample}
114 %
115 \begin{codeexample}[preamble={\usetikzlibrary{er}}]
116 \begin{tikzpicture}[every pin edge/.style=draw]
117 \node[entity,pin={[attribute]60:name},pin={[attribute]120:color}] {Sheep};
118 \end{tikzpicture}
119 \end{codeexample}
120 %
121 \end{stylekey}
122
123 \begin{stylekey}{/tikz/key attribute}
124 This style is intended for key attributes. By default, the will cause the
125 attribute to be typeset in italics. Typically, underlining is used instead,
126 but that looks ugly and it is difficult to implement in \TeX.
127 \end{stylekey}
128
129 \begin{stylekey}{/tikz/every attribute}
130 This style is used with every attribute, and therefore also for every key
131 attribute.
132 %
133 \begin{codeexample}[preamble={\usetikzlibrary{er}}]
134 \begin{tikzpicture}
135 [text depth=1pt,
136 every attribute/.style={fill=black!20,draw=black},
137 every entity/.style={fill=blue!20,draw=blue,thick},
138 every relationship/.style={fill=orange!20,draw=orange,thick,aspect=1.5}]
139
140 \node[entity] (sheep) at (0,0) {Sheep}
141 child {node [key attribute] {name}};
142 \node[entity] (genome) at (2,0) {Genome};
143 \node[relationship] at (1,1.5) {has}
144 edge (sheep)
145 edge (genome);
146 \end{tikzpicture}
147 \end{codeexample}
148 %
149 \end{stylekey}
150
151
152 %%% Local Variables:
153 %%% mode: latex
154 %%% TeX-master: "pgfmanual-pdftex-version"
155 %%% End: