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
|
%% timing-diagrams.sty
%% Copyright 2013 Matthieu Moy <Matthieu.Moy@imag.fr>
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is M. Matthieu Moy.
%
% This work consists of the files timing-diagrams.sty and the example file
% diagrams-examples.tex.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{timing-diagrams}[2013/08/21 Draw timing diagrams in TikZ]
\RequirePackage{tikz}
\RequirePackage{ifthen}
\usetikzlibrary{shadows}
\usetikzlibrary{shapes.callouts}
\usetikzlibrary{decorations.pathreplacing}
% Work around a bug in some versions of PGF
% http://tex.stackexchange.com/questions/31921/callout-and-beamer
\usetikzlibrary{decorations.text}
% Style (override to customize ...)
\tikzstyle{tboxshadow}=[
drop shadow={shadow xshift=1.5pt,shadow yshift=-1.5pt}
]
\tikzstyle{tbox}=[
top color=green!7,
bottom color=green!80!black!25,
fill=green!80!black!25,
shading=axis,
shading angle=30,
draw=black,
drop shadow={shadow xshift=1.5pt,shadow yshift=-1.5pt}
]
\tikzstyle{tcallout}=[
top color=yellow!7,bottom color=yellow!40!orange!80!black!25,shading=axis,
% Cause display bug :-(
% shading angle=45,
ellipse callout, draw, drop shadow={shadow xshift=1pt,shadow yshift=-1pt}]
\tikzstyle{tarrow}=[->,line width=.05cm,draw=red!90!blue!60!black]
\newcommand{\boxheight}{.4}
\newcommand{\tsetcurrent}[2]{
\path #2 coordinate (current#1);
\path #2 ++(0,\boxheight) coordinate (current#1U);
\path #2 ++(0,-\boxheight) coordinate (current#1L);
}
\newcommand{\tsetcurrentabs}[2]{
% correct absissa, wrong ordinate
\coordinate (next#1) at (#2, 0);
\tsetcurrent{#1}{(start#1 -| next#1)};
}
\newcommand{\tremember}[2]{
\coordinate (remember#2_#1) at (current#1);
}
\newcommand{\trecall}[2]{
\tsetcurrent{#1}{(remember#2_#1)};
}
\newcommand{\tline}[2]{
\coordinate (start#1) at (0,#2);
\tsetcurrent{#1}{(start#1)};
}
\newcommand{\ttimeline}[2]{
\path (current#1) ++(#2, 0) coordinate (tend#1);
\draw[->,thick] (current#1)++(-.1,0) -- (tend#1);
}
\newcommand{\tcaption}[2]{
\draw (start#1) ++(-.1,0) node[anchor=east] {#2};
}
\newcommand{\tadvance}[3]{
\path (current#1) +(#2,0) coordinate (next#1);
#3
\tsetcurrent{#1}{(next#1)};
}
\newcommand{\tbox}[3]{
\tadvance{#1}{#2}{
\path (current#1) +(0,\boxheight) coordinate (topleft#1);
\path (next#1) +(0,-\boxheight) coordinate (bottomright#1);
\draw[tbox] (topleft#1) rectangle (bottomright#1);
\draw (barycentric cs:current#1=.5,next#1=.5) node[anchor=center] {#3};
}
}
\newcommand{\tsmallbox}[3]{
\tskip{#1}{.05};
\tbox{#1}{#2-.1}{#3};
\tskip{#1}{.05};
}
\newcommand{\tskiptext}[3]{
\tadvance{#1}{#2}{
\path (current#1) +(0,.2) coordinate (topleft#1);
\path (next#1) +(0,.2) coordinate (topright#1);
\draw (topleft#1) edge[<->] node[auto] {#3} (topright#1);
}
}
\newcommand{\tskiptextL}[3]{
\tadvance{#1}{#2}{
\path (current#1) +(0,-.2) coordinate (bottomleft#1);
\path (next#1) +(0,-.2) coordinate (bottomright#1);
\draw (bottomleft#1) edge[<->] node[midway,below] {#3} (bottomright#1);
}
}
\newcommand{\tskiptextCONF}[4]{
\tadvance{#1}{#2}{
\path (current#1) +(0,-.2) coordinate (bottomleft#1);
\path (next#1) +(0,-.2) coordinate (bottomright#1);
\draw (bottomleft#1) edge[<->] node[#3] {#4} (bottomright#1);
}
}
\newcommand{\tskiptextinbox}[3]{
\tadvance{#1}{#2}{
\path (current#1) +(0,-.2) coordinate (topleft#1);
\path (next#1) +(0,-.2) coordinate (topright#1);
\draw (topleft#1) edge[<->] node[auto] {#3} (topright#1);
}
}
\newcommand{\tskiparrowU}[3]{
\tadvance{#1}{#2}{
\path (current#1) +(0,\boxheight) coordinate (topleft#1);
\path (next#1) +(0,\boxheight) coordinate (topright#1);
\draw (topleft#1) edge[bend left,->] node[above] {#3} (topright#1);
}
}
\newcommand{\tskiparrowL}[3]{
\tadvance{#1}{#2}{
\path (current#1) +(0,-\boxheight) coordinate (topleft#1);
\path (next#1) +(0,-\boxheight) coordinate (topright#1);
\draw (topleft#1) edge[bend right,->] node[below] {#3} (topright#1);
}
}
\newcommand{\tskip}[2]{
\tadvance{#1}{#2}{}
}
\newcommand{\tevent}[1]{
\draw[thick,->] (current#1) -- ++(0,.5);
}
\newcommand{\teventA}[2]{
\draw[thick,->] (current#1) -- ++(#2+90:.5);
}
\newcommand{\ttick}[1]{
\draw[tbox,thick] (current#1) ++(0,\boxheight) rectangle ++(.01,-2*\boxheight);
}
\newcommand{\tstrongtick}[1]{
\draw[tboxshadow,fill=black] (current#1) +(-.04,\boxheight) rectangle +(.04,-\boxheight);
}
\newcommand{\tlighttick}[1]{
\draw (current#1) ++(0,\boxheight) rectangle ++(.01,-2*\boxheight);
}
\newcommand{\tlonglighttick}[1]{
\draw (current#1) ++(0,1.2*\boxheight) rectangle ++(.01,-2.4*\boxheight);
}
\newcommand{\tcatchup}[2]{
\coordinate (next#1) at (current#2|-current#1);
\tsetcurrent{#1}{(next#1)};
}
\newcommand{\ttextU}[2]{
\draw (current#1) ++(0,\boxheight) node[anchor=south] {#2};
}
\newcommand{\ttextL}[2]{
\draw (current#1) ++(0,-\boxheight) node[anchor=north] {#2};
}
\newcommand{\ttextM}[2]{
\draw (current#1) node {#2};
}
\newcommand{\tcalloutU}[3][(0,1)]{
\draw (current#2) ++#1
node[anchor=south,callout absolute pointer={(current#2)++(0,\boxheight)}, tcallout] {#3};
}
\newcommand{\ttextarrowU}[3][++(0, .5)]{
\path (current#2) ++(0,\boxheight) ++(0,.015) coordinate (tmpcurrentU);
\draw[black] (current#2) ++(0,\boxheight) #1
node[anchor=south,inner sep=.1](tmptext) {#3};
\draw[->] (tmptext) -- (tmpcurrentU);
}
\newcommand{\tstartbrace}[1]{
\coordinate (startbrace#1) at (current#1);
}
\newcommand{\tendbrace}[2]{
\coordinate (endbrace#1) at (current#1);
\draw[decoration={brace,amplitude=1.5mm},decorate] (endbrace#1) -- node[below]{#2} (startbrace#1);
}
\newcommand{\tcalloutL}[3][(0,-1)]{
\draw (current#2) ++#1
node[anchor=north,callout absolute pointer={(current#2)++(0,-\boxheight)}, tcallout] {#3};
}
\newcommand{\tarrowLU}[3]{
\tarrowCoord{(current#1U)}{(current#2L)}{#3}
}
\newcommand{\tarrowUL}[3]{
\tarrowCoord{(current#1L)}{(current#2U)}{#3}
}
\newcommand{\tarrowCoord}[3]{
\coordinate (tmp1) at #1;
\coordinate (tmp2) at #2;
\coordinate (tmpmid1) at (barycentric cs:tmp1=.2,tmp2=.8);
\coordinate (tmpmid2) at (barycentric cs:tmp1=.8,tmp2=.2);
\coordinate (tmpmid) at (barycentric cs:tmp1=.5,tmp2=.5);
\draw[tarrow] (tmp1) .. controls (tmp1 |- tmpmid1) and (tmpmid2 -| tmp2) .. (tmp2);
\ifthenelse{\equal{#3}{}}{}{
\draw (tmpmid) node[shape=circle,fill=white,draw=black] {#3};
}
}
|