| 1 |
%% timing-diagrams.sty |
| 2 |
%% Copyright 2013 Matthieu Moy <[email protected]> |
| 3 |
% |
| 4 |
% This work may be distributed and/or modified under the |
| 5 |
% conditions of the LaTeX Project Public License, either version 1.3 |
| 6 |
% of this license or (at your option) any later version. |
| 7 |
% The latest version of this license is in |
| 8 |
% http://www.latex-project.org/lppl.txt |
| 9 |
% and version 1.3 or later is part of all distributions of LaTeX |
| 10 |
% version 2005/12/01 or later. |
| 11 |
% |
| 12 |
% This work has the LPPL maintenance status `maintained'. |
| 13 |
% |
| 14 |
% The Current Maintainer of this work is M. Matthieu Moy. |
| 15 |
% |
| 16 |
% This work consists of the files timing-diagrams.sty and the example file |
| 17 |
% diagrams-examples.tex. |
| 18 |
\NeedsTeXFormat{LaTeX2e} |
| 19 |
\ProvidesPackage{timing-diagrams}[2013/08/21 Draw timing diagrams in TikZ] |
| 20 |
|
| 21 |
\RequirePackage{tikz} |
| 22 |
\RequirePackage{ifthen} |
| 23 |
|
| 24 |
\usetikzlibrary{shadows} |
| 25 |
\usetikzlibrary{shapes.callouts} |
| 26 |
\usetikzlibrary{decorations.pathreplacing} |
| 27 |
% Work around a bug in some versions of PGF |
| 28 |
% http://tex.stackexchange.com/questions/31921/callout-and-beamer |
| 29 |
\usetikzlibrary{decorations.text} |
| 30 |
|
| 31 |
% Style (override to customize ...) |
| 32 |
\tikzstyle{tboxshadow}=[ |
| 33 |
drop shadow={shadow xshift=1.5pt,shadow yshift=-1.5pt} |
| 34 |
] |
| 35 |
\tikzstyle{tbox}=[ |
| 36 |
top color=green!7, |
| 37 |
bottom color=green!80!black!25, |
| 38 |
fill=green!80!black!25, |
| 39 |
shading=axis, |
| 40 |
shading angle=30, |
| 41 |
draw=black, |
| 42 |
drop shadow={shadow xshift=1.5pt,shadow yshift=-1.5pt} |
| 43 |
] |
| 44 |
\tikzstyle{tcallout}=[ |
| 45 |
top color=yellow!7,bottom color=yellow!40!orange!80!black!25,shading=axis, |
| 46 |
% Cause display bug :-( |
| 47 |
% shading angle=45, |
| 48 |
ellipse callout, draw, drop shadow={shadow xshift=1pt,shadow yshift=-1pt}] |
| 49 |
|
| 50 |
\tikzstyle{tarrow}=[->,line width=.05cm,draw=red!90!blue!60!black] |
| 51 |
\newcommand{\boxheight}{.4} |
| 52 |
|
| 53 |
\newcommand{\tsetcurrent}[2]{ |
| 54 |
\path #2 coordinate (current#1); |
| 55 |
\path #2 ++(0,\boxheight) coordinate (current#1U); |
| 56 |
\path #2 ++(0,-\boxheight) coordinate (current#1L); |
| 57 |
} |
| 58 |
|
| 59 |
\newcommand{\tsetcurrentabs}[2]{ |
| 60 |
% correct absissa, wrong ordinate |
| 61 |
\coordinate (next#1) at (#2, 0); |
| 62 |
\tsetcurrent{#1}{(start#1 -| next#1)}; |
| 63 |
} |
| 64 |
|
| 65 |
\newcommand{\tremember}[2]{ |
| 66 |
\coordinate (remember#2_#1) at (current#1); |
| 67 |
} |
| 68 |
\newcommand{\trecall}[2]{ |
| 69 |
\tsetcurrent{#1}{(remember#2_#1)}; |
| 70 |
} |
| 71 |
|
| 72 |
\newcommand{\tline}[2]{ |
| 73 |
\coordinate (start#1) at (0,#2); |
| 74 |
\tsetcurrent{#1}{(start#1)}; |
| 75 |
} |
| 76 |
|
| 77 |
\newcommand{\ttimeline}[2]{ |
| 78 |
\path (current#1) ++(#2, 0) coordinate (tend#1); |
| 79 |
\draw[->,thick] (current#1)++(-.1,0) -- (tend#1); |
| 80 |
} |
| 81 |
|
| 82 |
\newcommand{\tcaption}[2]{ |
| 83 |
\draw (start#1) ++(-.1,0) node[anchor=east] {#2}; |
| 84 |
} |
| 85 |
|
| 86 |
\newcommand{\tadvance}[3]{ |
| 87 |
\path (current#1) +(#2,0) coordinate (next#1); |
| 88 |
#3 |
| 89 |
\tsetcurrent{#1}{(next#1)}; |
| 90 |
} |
| 91 |
|
| 92 |
\newcommand{\tbox}[3]{ |
| 93 |
\tadvance{#1}{#2}{ |
| 94 |
\path (current#1) +(0,\boxheight) coordinate (topleft#1); |
| 95 |
\path (next#1) +(0,-\boxheight) coordinate (bottomright#1); |
| 96 |
\draw[tbox] (topleft#1) rectangle (bottomright#1); |
| 97 |
\draw (barycentric cs:current#1=.5,next#1=.5) node[anchor=center] {#3}; |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
\newcommand{\tsmallbox}[3]{ |
| 102 |
\tskip{#1}{.05}; |
| 103 |
\tbox{#1}{#2-.1}{#3}; |
| 104 |
\tskip{#1}{.05}; |
| 105 |
} |
| 106 |
|
| 107 |
\newcommand{\tskiptext}[3]{ |
| 108 |
\tadvance{#1}{#2}{ |
| 109 |
\path (current#1) +(0,.2) coordinate (topleft#1); |
| 110 |
\path (next#1) +(0,.2) coordinate (topright#1); |
| 111 |
\draw (topleft#1) edge[<->] node[auto] {#3} (topright#1); |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
\newcommand{\tskiptextL}[3]{ |
| 116 |
\tadvance{#1}{#2}{ |
| 117 |
\path (current#1) +(0,-.2) coordinate (bottomleft#1); |
| 118 |
\path (next#1) +(0,-.2) coordinate (bottomright#1); |
| 119 |
\draw (bottomleft#1) edge[<->] node[midway,below] {#3} (bottomright#1); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
\newcommand{\tskiptextCONF}[4]{ |
| 124 |
\tadvance{#1}{#2}{ |
| 125 |
\path (current#1) +(0,-.2) coordinate (bottomleft#1); |
| 126 |
\path (next#1) +(0,-.2) coordinate (bottomright#1); |
| 127 |
\draw (bottomleft#1) edge[<->] node[#3] {#4} (bottomright#1); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
\newcommand{\tskiptextinbox}[3]{ |
| 132 |
\tadvance{#1}{#2}{ |
| 133 |
\path (current#1) +(0,-.2) coordinate (topleft#1); |
| 134 |
\path (next#1) +(0,-.2) coordinate (topright#1); |
| 135 |
\draw (topleft#1) edge[<->] node[auto] {#3} (topright#1); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
\newcommand{\tskiparrowU}[3]{ |
| 140 |
\tadvance{#1}{#2}{ |
| 141 |
\path (current#1) +(0,\boxheight) coordinate (topleft#1); |
| 142 |
\path (next#1) +(0,\boxheight) coordinate (topright#1); |
| 143 |
\draw (topleft#1) edge[bend left,->] node[above] {#3} (topright#1); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
\newcommand{\tskiparrowL}[3]{ |
| 148 |
\tadvance{#1}{#2}{ |
| 149 |
\path (current#1) +(0,-\boxheight) coordinate (topleft#1); |
| 150 |
\path (next#1) +(0,-\boxheight) coordinate (topright#1); |
| 151 |
\draw (topleft#1) edge[bend right,->] node[below] {#3} (topright#1); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
\newcommand{\tskip}[2]{ |
| 156 |
\tadvance{#1}{#2}{} |
| 157 |
} |
| 158 |
|
| 159 |
\newcommand{\tevent}[1]{ |
| 160 |
\draw[thick,->] (current#1) -- ++(0,.5); |
| 161 |
} |
| 162 |
|
| 163 |
\newcommand{\teventA}[2]{ |
| 164 |
\draw[thick,->] (current#1) -- ++(#2+90:.5); |
| 165 |
} |
| 166 |
|
| 167 |
\newcommand{\ttick}[1]{ |
| 168 |
\draw[tbox,thick] (current#1) ++(0,\boxheight) rectangle ++(.01,-2*\boxheight); |
| 169 |
} |
| 170 |
|
| 171 |
\newcommand{\tstrongtick}[1]{ |
| 172 |
\draw[tboxshadow,fill=black] (current#1) +(-.04,\boxheight) rectangle +(.04,-\boxheight); |
| 173 |
} |
| 174 |
|
| 175 |
\newcommand{\tlighttick}[1]{ |
| 176 |
\draw (current#1) ++(0,\boxheight) rectangle ++(.01,-2*\boxheight); |
| 177 |
} |
| 178 |
|
| 179 |
\newcommand{\tlonglighttick}[1]{ |
| 180 |
\draw (current#1) ++(0,1.2*\boxheight) rectangle ++(.01,-2.4*\boxheight); |
| 181 |
} |
| 182 |
|
| 183 |
\newcommand{\tcatchup}[2]{ |
| 184 |
\coordinate (next#1) at (current#2|-current#1); |
| 185 |
\tsetcurrent{#1}{(next#1)}; |
| 186 |
} |
| 187 |
|
| 188 |
\newcommand{\ttextU}[2]{ |
| 189 |
\draw (current#1) ++(0,\boxheight) node[anchor=south] {#2}; |
| 190 |
} |
| 191 |
|
| 192 |
\newcommand{\ttextL}[2]{ |
| 193 |
\draw (current#1) ++(0,-\boxheight) node[anchor=north] {#2}; |
| 194 |
} |
| 195 |
|
| 196 |
\newcommand{\ttextM}[2]{ |
| 197 |
\draw (current#1) node {#2}; |
| 198 |
} |
| 199 |
|
| 200 |
\newcommand{\tcalloutU}[3][(0,1)]{ |
| 201 |
\draw (current#2) ++#1 |
| 202 |
node[anchor=south,callout absolute pointer={(current#2)++(0,\boxheight)}, tcallout] {#3}; |
| 203 |
} |
| 204 |
|
| 205 |
\newcommand{\ttextarrowU}[3][++(0, .5)]{ |
| 206 |
\path (current#2) ++(0,\boxheight) ++(0,.015) coordinate (tmpcurrentU); |
| 207 |
\draw[black] (current#2) ++(0,\boxheight) #1 |
| 208 |
node[anchor=south,inner sep=.1](tmptext) {#3}; |
| 209 |
\draw[->] (tmptext) -- (tmpcurrentU); |
| 210 |
} |
| 211 |
|
| 212 |
\newcommand{\tstartbrace}[1]{ |
| 213 |
\coordinate (startbrace#1) at (current#1); |
| 214 |
} |
| 215 |
|
| 216 |
\newcommand{\tendbrace}[2]{ |
| 217 |
\coordinate (endbrace#1) at (current#1); |
| 218 |
\draw[decoration={brace,amplitude=1.5mm},decorate] (endbrace#1) -- node[below]{#2} (startbrace#1); |
| 219 |
} |
| 220 |
|
| 221 |
\newcommand{\tcalloutL}[3][(0,-1)]{ |
| 222 |
\draw (current#2) ++#1 |
| 223 |
node[anchor=north,callout absolute pointer={(current#2)++(0,-\boxheight)}, tcallout] {#3}; |
| 224 |
} |
| 225 |
|
| 226 |
\newcommand{\tarrowLU}[3]{ |
| 227 |
\tarrowCoord{(current#1U)}{(current#2L)}{#3} |
| 228 |
} |
| 229 |
\newcommand{\tarrowUL}[3]{ |
| 230 |
\tarrowCoord{(current#1L)}{(current#2U)}{#3} |
| 231 |
} |
| 232 |
|
| 233 |
\newcommand{\tarrowCoord}[3]{ |
| 234 |
\coordinate (tmp1) at #1; |
| 235 |
\coordinate (tmp2) at #2; |
| 236 |
\coordinate (tmpmid1) at (barycentric cs:tmp1=.2,tmp2=.8); |
| 237 |
\coordinate (tmpmid2) at (barycentric cs:tmp1=.8,tmp2=.2); |
| 238 |
\coordinate (tmpmid) at (barycentric cs:tmp1=.5,tmp2=.5); |
| 239 |
\draw[tarrow] (tmp1) .. controls (tmp1 |- tmpmid1) and (tmpmid2 -| tmp2) .. (tmp2); |
| 240 |
\ifthenelse{\equal{#3}{}}{}{ |
| 241 |
\draw (tmpmid) node[shape=circle,fill=white,draw=black] {#3}; |
| 242 |
} |
| 243 |
} |