summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/tikz-osci/tikz-osci.sty
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-10-25 03:01:25 +0000
committerNorbert Preining <norbert@preining.info>2023-10-25 03:01:25 +0000
commit241082cbe6f4fe8c38e91c38418ca828ac8d2f7c (patch)
tree206f7f6660cf81875a12824d3f7f92939c63b757 /graphics/pgf/contrib/tikz-osci/tikz-osci.sty
parent7fc03b60d145610ff8e62c3d3a0d5fe037f6597d (diff)
CTAN sync 202310250301
Diffstat (limited to 'graphics/pgf/contrib/tikz-osci/tikz-osci.sty')
-rw-r--r--graphics/pgf/contrib/tikz-osci/tikz-osci.sty309
1 files changed, 230 insertions, 79 deletions
diff --git a/graphics/pgf/contrib/tikz-osci/tikz-osci.sty b/graphics/pgf/contrib/tikz-osci/tikz-osci.sty
index 73ab24f5da..4c83f6c743 100644
--- a/graphics/pgf/contrib/tikz-osci/tikz-osci.sty
+++ b/graphics/pgf/contrib/tikz-osci/tikz-osci.sty
@@ -8,92 +8,116 @@
% tained anymore.
%
% Author: Thibault Giauffret
-% Date: 2013/10/08
-% Version: 0.3.0
+% Date: 2023/10/24
+% Version: 0.4.0
% Licence : Released under the LaTeX Project Public License v1.3c or later, see http://www.latex-project.org/lppl.txtf
% Not an expert... Just doing it for fun.
% -----------------------------------------------------------
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{tikz-osci}[2023/10/08 0.3.0 Tikz Osci package]
+\ProvidesPackage{tikz-osci}[2023/10/24 0.4.0 Tikz Osci package]
% Required packages
\RequirePackage[dvipsnames]{xcolor}
\RequirePackage{pgfkeys}
\RequirePackage{pgfplots}
\RequirePackage{tikz}
-\usetikzlibrary{arrows,shapes,positioning}
-\usetikzlibrary{decorations.markings,decorations.pathmorphing,
- decorations.pathreplacing}
-\usetikzlibrary{calc,patterns,shapes.geometric}
-
-
-% Init the keys and get the values
-\pgfkeys{
- /osci/.cd,
- scale/.store in=\scale,
- scale=1,
- rounded corners/.store in=\roundedCorners,
- rounded corners=10,
- second channel/.store in=\secondChannel,
- second channel=0,
- screen offset one/.store in=\screenOffsetOne,
- screen offset one=0,
- screen offset two/.store in=\screenOffsetTwo,
- screen offset two=-0,
- time div/.store in=\timeDiv,
- time div=20,
- voltage div one/.store in=\voltageDivOne,
- voltage div one=1,
- voltage div two/.store in=\voltageDivTwo,
- voltage div two=1,
- sample rate/.store in=\sampleRate,
- sample rate=200,
- xy mode/.store in=\xyMode,
- xy mode=0,
- math mode/.store in=\mathMode,
- math mode=0,
- math mode hide source/.store in=\mathModeHideSource,
- math mode hide source=0,
- func one/.store in=\funcOne,
- func one=2*sin(2*180/0.020*x),
- func two/.store in=\funcTwo,
- func two=0.6*sin(2*180/0.020*x)+0.2*sin(2*180/0.040*x),
- indicators/.store in=\indicators,
- indicators=1,
- color one/.store in=\colorOne,
- color one=D62626,
- color text one/.store in=\colorTextOne,
- color text one=FFFFFF,
- color two/.store in=\colorTwo,
- color two=1053AF,
- color text two/.store in=\colorTextTwo,
- color text two=FFFFFF,
- color three/.store in=\colorThree,
- color three=2E8B73,
- color text three/.store in=\colorTextThree,
- color text three=FFFFFF,
- graph back color/.store in=\graphBackColor,
- graph back color=FFFFFF,
- info back color/.store in=\infoBackColor,
- info back color=D6D6D6,
- info text color/.store in=\infoTextColor,
- info text color=000000,
- main axis color/.store in=\mainAxisColor,
- main axis color=000000,
- grid color/.store in=\gridColor,
- grid color=AAAAAA,
+\usetikzlibrary{arrows,shapes,positioning,decorations.markings,decorations.pathmorphing,
+ decorations.pathreplacing,calc,patterns,shapes.geometric}
+
+% Raised text
+\newcommand*{\raisedtext}[1]{%
+ \begingroup
+ \leavevmode
+ \rlap{\kern-.2pt\raise.2pt\hbox{\color{white}#1}}%
+ \rlap{\kern.2pt\raise-.2pt\hbox{\color{black!30}#1}}%
+ \hbox{#1}%
+ \endgroup
}
% The main command
\newcommand\osci[1][]{
- % Get the values
+ % Init the keys and get the values and add the user's values
\pgfkeys{
/osci/.cd,
- #1,
+ scale/.store in=\scale,
+ scale=1,
+ rounded corners/.store in=\roundedCorners,
+ rounded corners=10,
+ second channel/.store in=\secondChannel,
+ second channel=0,
+ screen offset one/.store in=\screenOffsetOne,
+ screen offset one=0,
+ screen offset two/.store in=\screenOffsetTwo,
+ screen offset two=-0,
+ time div/.store in=\timeDiv,
+ time div=20,
+ voltage div one/.store in=\voltageDivOne,
+ voltage div one=1,
+ voltage div two/.store in=\voltageDivTwo,
+ voltage div two=1,
+ sample rate/.store in=\sampleRate,
+ sample rate=200,
+ xy mode/.store in=\xyMode,
+ xy mode=0,
+ math mode/.store in=\mathMode,
+ math mode=0,
+ math mode hide source/.store in=\mathModeHideSource,
+ math mode hide source=0,
+ func one/.store in=\funcOne,
+ func one=2*sin(2*180/0.020*x),
+ func two/.store in=\funcTwo,
+ func two=0.6*sin(2*180/0.020*x)+0.2*sin(2*180/0.040*x),
+ indicators/.store in=\indicators,
+ indicators=1,
+ vertical cursor one/.store in=\verticalCursorOne,
+ vertical cursor one=false,
+ vertical cursor two/.store in=\verticalCursorTwo,
+ vertical cursor two=false,
+ horizontal cursor one/.store in=\horizontalCursorOne,
+ horizontal cursor one=false,
+ horizontal cursor two/.store in=\horizontalCursorTwo,
+ horizontal cursor two=false,
+ cursor precision/.store in=\cursorPrecision,
+ cursor precision=1,
+ color one/.store in=\colorOne,
+ color one=D62626,
+ color text one/.store in=\colorTextOne,
+ color text one=FFFFFF,
+ color two/.store in=\colorTwo,
+ color two=1053AF,
+ color text two/.store in=\colorTextTwo,
+ color text two=FFFFFF,
+ color three/.store in=\colorThree,
+ color three=2E8B73,
+ color text three/.store in=\colorTextThree,
+ color text three=FFFFFF,
+ graph back color/.store in=\graphBackColor,
+ graph back color=FFFFFF,
+ info back color/.store in=\infoBackColor,
+ info back color=D6D6D6,
+ info text color/.store in=\infoTextColor,
+ info text color=000000,
+ main axis color/.store in=\mainAxisColor,
+ main axis color=000000,
+ grid color/.store in=\gridColor,
+ grid color=AAAAAA,
+ horizontal cursor color/.store in=\horizontalCursorColor,
+ horizontal cursor color=FFA500,
+ vertical cursor color/.store in=\verticalCursorColor,
+ vertical cursor color=800080,
+ smooth one/.store in=\smoothOne,
+ smooth one=0,
+ smooth two/.store in=\smoothTwo,
+ smooth two=0,
+ smooth three/.store in=\smoothThree,
+ smooth three=0,
+ #1
}
+
+ % Set the scale of the picture
\scalebox{\scale}{
% Begin the picture
\begin{tikzpicture}
@@ -110,6 +134,8 @@
\definecolor{colorTextOne}{HTML}{\colorTextOne}
\definecolor{colorTextTwo}{HTML}{\colorTextTwo}
\definecolor{colorTextThree}{HTML}{\colorTextThree}
+ \definecolor{verticalCursorColor}{HTML}{\verticalCursorColor}
+ \definecolor{horizontalCursorColor}{HTML}{\horizontalCursorColor}
% Draw the info box
\draw[black,thick, fill= infoBackColor]
@@ -123,6 +149,33 @@
% Add time/div label
\draw (5,-0.15) node[anchor=north, color= infoTextColor] {\timeDiv\ ms/div};
+ % Test if smoothOne is enabled
+ \ifnum\smoothOne=1
+ % set \smoothOne to smooth
+ \def\smoothOne{smooth}
+ \else
+ % set \smoothOne to empty
+ \def\smoothOne{}
+ \fi
+
+ % Test if smoothTwo is enabled
+ \ifnum\smoothTwo=1
+ % set \smoothTwo to smooth
+ \def\smoothTwo{smooth}
+ \else
+ % set \smoothTwo to empty
+ \def\smoothTwo{}
+ \fi
+
+ % Test if smoothThree is enabled
+ \ifnum\smoothThree=1
+ % set \smoothThree to smooth
+ \def\smoothThree{smooth}
+ \else
+ % set \smoothThree to empty
+ \def\smoothThree{}
+ \fi
+
% Add XY mode indicator
% Lissajou mode
\ifnum\xyMode=1
@@ -218,28 +271,27 @@
\pgfplotsset{ every non boxed x axis/.append style={x axis line style=-},
every non boxed y axis/.append style={y axis line style=-}}
- % Lissajou mode
+ % Lissajous mode
\ifnum\xyMode=1
-
\addplot
[domain=0:360,variable=\x,
- samples=200,smooth,very thick,color=thirdcolor]
+ samples=200,very thick,color=thirdcolor, \smoothThree]
({(\funcOne)/\voltageDivOne},{(\funcTwo)/\voltageDivTwo});
\draw[thirdcolor,fill=thirdcolor] (4,-0.78) rectangle (6,-1.28);
\draw (5,-0.75) node[anchor=north, color=white] {XY mode};
\else
+ % Show source signals
\ifnum\mathModeHideSource=0
% Draw each channel separately
% First channel plot
- \addplot[color=firstcolor,very thick,domain=-5*(\timeDiv/1000):5*(\timeDiv/1000),
- smooth, samples=\sampleRate]{(\funcOne)/\voltageDivOne+\screenOffsetOne};
+ \addplot[color=firstcolor,very thick,domain=-5*(\timeDiv/1000):5*(\timeDiv/1000),samples=\sampleRate,\smoothOne]{(\funcOne)/\voltageDivOne+\screenOffsetOne};
% If the second channel is enabled, draw it
\ifnum\secondChannel=1
% Draw the second channel
- \addplot[color=secondcolor,very thick,domain=-5*(\timeDiv/1000):5*(\timeDiv/1000), smooth, samples=\sampleRate]{(\funcTwo)/\voltageDivTwo+\screenOffsetTwo};
+ \addplot[color=secondcolor,very thick,domain=-5*(\timeDiv/1000):5*(\timeDiv/1000), samples=\sampleRate,\smoothTwo]{(\funcTwo)/\voltageDivTwo+\screenOffsetTwo};
\fi
\fi
@@ -247,14 +299,13 @@
% Add mode
\ifnum\mathMode=1
\addplot[color=thirdcolor,very thick,domain=-5*(\timeDiv/1000):5*(\timeDiv/1000),
- smooth, samples=\sampleRate]{(\funcOne)/\voltageDivOne + (\funcTwo)/\voltageDivTwo};
+ smooth, samples=\sampleRate, \smoothThree]{(\funcOne)/\voltageDivOne + (\funcTwo)/\voltageDivTwo};
\else
% Substract mode
\ifnum\mathMode=2
- \addplot[color=thirdcolor,very thick,domain=-5*(\timeDiv/1000):5*(\timeDiv/1000),
- smooth, samples=\sampleRate]{(\funcOne)/\voltageDivOne - (\funcTwo)/\voltageDivTwo};
+ \addplot[color=thirdcolor,very thick,domain=-5*(\timeDiv/1000):5*(\timeDiv/1000), samples=\sampleRate, \smoothThree]{(\funcOne)/\voltageDivOne - (\funcTwo)/\voltageDivTwo};
\draw[thirdcolor,fill=thirdcolor] (4,-0.78) rectangle (6,-1.28);
\draw (5,-0.75) node[anchor=north, color=white] {Substract};
@@ -262,8 +313,7 @@
% Multiply mode
\ifnum\mathMode=3
- \addplot[color=thirdcolor,very thick,domain=-5*(\timeDiv/1000):5*(\timeDiv/1000),
- smooth, samples=\sampleRate]{(\funcOne)/\voltageDivOne * (\funcTwo)/\voltageDivTwo};
+ \addplot[color=thirdcolor,very thick,domain=-5*(\timeDiv/1000):5*(\timeDiv/1000) ,samples=\sampleRate, \smoothThree]{(\funcOne)/\voltageDivOne * (\funcTwo)/\voltageDivTwo};
\draw[thirdcolor,fill=thirdcolor] (4,-0.78) rectangle (6,-1.28);
\draw (5,-0.75) node[anchor=north, color=white] {Multiply};
@@ -271,8 +321,7 @@
% Divide mode
\ifnum\mathMode=4
- \addplot[color=thirdcolor,very thick,domain=-5*(\timeDiv/1000):5*(\timeDiv/1000),
- smooth, samples=\sampleRate]{(\funcOne)/\voltageDivOne / (\funcTwo)/\voltageDivTwo};
+ \addplot[color=thirdcolor,very thick,domain=-5*(\timeDiv/1000):5*(\timeDiv/1000), samples=\sampleRate, \smoothThree]{(\funcOne)/\voltageDivOne / (\funcTwo)/\voltageDivTwo};
\draw[thirdcolor,fill=thirdcolor] (4,-0.78) rectangle (6,-1.28);
\draw (5,-0.75) node[anchor=north, color=white] {Divide};
\fi
@@ -285,6 +334,7 @@
\ifnum\xyMode=1
\else
+ % Show the channel indicators
\ifnum\indicators=1
% Draw the first channel's screen marker
\draw[firstcolor,fill=firstcolor] (0.4, \screenOffsetOne+4) -- (0, \screenOffsetOne+4+0.3) -- (0, \screenOffsetOne+4-0.3) -- cycle;
@@ -297,6 +347,107 @@
\draw (-0.04, \screenOffsetTwo+4) node[anchor=west, color=colorTextTwo,font=\fontsize{8}{10}\selectfont] {2};
\fi
\fi
+
+
+ % Draw the vertical cursors
+
+ % Define the false value
+ \def\false{false}
+
+ % Set the value of \verticalCursorOne
+ \pgfmathsetmacro{\verticalCursorOneValue}{\verticalCursorOne*\timeDiv}
+
+
+ % If the first vertical cursor is enabled
+ \ifx\verticalCursorOne\false
+ \else
+ % Draw the first vertical cursor with \verticalCursorOne value
+ \draw[verticalCursorColor,very thick,dashed] (\verticalCursorOne+5,0) -- (\verticalCursorOne+5,8);
+ \draw[verticalCursorColor,very thick,fill=verticalCursorColor] (\verticalCursorOne+5-0.25,7.5) rectangle (\verticalCursorOne+5+0.25,8);
+
+ % Draw the indicator
+ \draw[white,very thick] (\verticalCursorOne+5,7.45) node[anchor=south, color=white,font=\fontsize{10}{12}\selectfont] {A};
+
+ % Draw the legend
+ \draw[verticalCursorColor,very thick] (0.25,0.5) node[anchor=west, color=verticalCursorColor,font=\fontsize{10}{12}\selectfont] {\raisedtext{CurA \pgfmathprintnumber[precision=\cursorPrecision, assume math mode=true,fixed zerofill]{\verticalCursorOneValue}\ ms}};
+
+ % If the second vertical cursor is enabled
+ \ifx\verticalCursorTwo\false
+ \else
+ % Draw the time difference between the two vertical cursors
+ \pgfmathsetmacro{\verticalCursorDiff}{\verticalCursorTwo-\verticalCursorOne}
+ \pgfmathsetmacro{\verticalCursorDiffValue}{\verticalCursorDiff*\timeDiv}
+ \draw[verticalCursorColor,very thick] (0.25,1.5) node[anchor=west, color=verticalCursorColor,font=\fontsize{10}{12}\selectfont] {\raisedtext{CurB - CurA \pgfmathprintnumber[precision=\cursorPrecision, assume math mode=true,fixed zerofill]{\verticalCursorDiffValue}\ ms}};
+ \fi
+
+ \fi
+
+ % Set the value of \verticalCursorTwo
+ \pgfmathsetmacro{\verticalCursorTwoValue}{\verticalCursorTwo*\timeDiv}
+
+ % If the second vertical cursor is enabled
+ \ifx\verticalCursorTwo\false
+ \else
+ % Draw the second vertical cursor with \verticalCursorTwo value
+ \draw[verticalCursorColor,very thick,dashed] (\verticalCursorTwo+5,0) -- (\verticalCursorTwo+5,8);
+ \draw[verticalCursorColor,very thick,fill=verticalCursorColor] (\verticalCursorTwo+5-0.25,7.5) rectangle (\verticalCursorTwo+5+0.25,8);
+
+ % Draw the indicator
+ \draw[white,very thick] (\verticalCursorTwo+5,7.45) node[anchor=south, color=white,font=\fontsize{10}{12}\selectfont] {B};
+
+ % Draw the legend
+ \draw[verticalCursorColor,very thick] (0.25,1) node[anchor=west, color=verticalCursorColor,font=\fontsize{10}{12}\selectfont] {\raisedtext{CurB \pgfmathprintnumber[precision=\cursorPrecision, assume math mode=true,fixed zerofill]{\verticalCursorTwoValue}\ ms}};
+
+ \fi
+
+
+ % Draw the horizontal cursors
+
+ % Set the value of \horizontalCursorOne
+ \pgfmathsetmacro{\horizontalCursorOneValue}{\horizontalCursorOne*\voltageDivOne}
+
+ % If the first horizontal cursor is enabled
+ \ifx\horizontalCursorOne\false
+ \else
+ % Draw the first horizontal cursor with \horizontalCursorOne value
+ \draw[horizontalCursorColor,very thick,dashed] (0,\horizontalCursorOne+4) -- (10,\horizontalCursorOne+4);
+ \draw[horizontalCursorColor,very thick,fill=horizontalCursorColor] (9.5,\horizontalCursorOne+4-0.25) rectangle (10.5,\horizontalCursorOne+4+0.25);
+
+ % Draw the indicator
+ \draw[white,very thick] (10,\horizontalCursorOne+4) node[anchor=east, color=white,font=\fontsize{10}{12}\selectfont] {A};
+
+ % Draw the legend
+ \draw[horizontalCursorColor,very thick] (5.25,0.5) node[anchor=west, color=horizontalCursorColor,font=\fontsize{10}{12}\selectfont] {\raisedtext{CurA \pgfmathprintnumber[precision=\cursorPrecision, assume math mode=true,fixed zerofill]{\horizontalCursorOneValue}\ V}};
+
+ % If the second horizontal cursor is enabled
+ \ifx\horizontalCursorTwo\false
+ \else
+ % Draw the voltage difference between the two horizontal cursors
+ \pgfmathsetmacro{\horizontalCursorDiff}{\horizontalCursorTwo-\horizontalCursorOne}
+ \pgfmathsetmacro{\horizontalCursorDiffValue}{\horizontalCursorDiff*\voltageDivOne}
+ \draw[horizontalCursorColor,very thick] (5.25,1.5) node[anchor=west, color=horizontalCursorColor,font=\fontsize{10}{12}\selectfont] {\raisedtext{CurB - CurA \pgfmathprintnumber[precision=\cursorPrecision, assume math mode=true,fixed zerofill]{\horizontalCursorDiffValue}\ V}};
+ \fi
+ \fi
+
+ % Set the value of \horizontalCursorTwo
+ \pgfmathsetmacro{\horizontalCursorTwoValue}{\horizontalCursorTwo*\voltageDivOne}
+
+ % If the second horizontal cursor is enabled
+ \ifx\horizontalCursorTwo\false
+ \else
+ % Draw the second horizontal cursor with \horizontalCursorTwo value
+ \draw[horizontalCursorColor,very thick,dashed] (0,\horizontalCursorTwo+4) -- (10,\horizontalCursorTwo+4);
+ \draw[horizontalCursorColor,very thick,fill=horizontalCursorColor] (9.5,\horizontalCursorTwo+4-0.25) rectangle (10.5,\horizontalCursorTwo+4+0.25);
+
+ % Draw the indicator
+ \draw[white,very thick] (10,\horizontalCursorTwo+4) node[anchor=east, color=white,font=\fontsize{10}{12}\selectfont] {B};
+
+ % Draw the legend
+ \draw[horizontalCursorColor,very thick] (5.25,1) node[anchor=west, color=horizontalCursorColor,font=\fontsize{10}{12}\selectfont] {\raisedtext{CurB \pgfmathprintnumber[precision=\cursorPrecision, assume math mode=true,fixed zerofill]{\horizontalCursorTwoValue}\ V}};
+
+ \fi
+
+ % End xyMode test
\fi
\end{scope}