summaryrefslogtreecommitdiff
path: root/graphics/sparklines
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/sparklines
Initial commit
Diffstat (limited to 'graphics/sparklines')
-rw-r--r--graphics/sparklines/README17
-rw-r--r--graphics/sparklines/sparklines.pdfbin0 -> 136597 bytes
-rw-r--r--graphics/sparklines/sparklines.sty158
-rw-r--r--graphics/sparklines/sparklines.tex333
4 files changed, 508 insertions, 0 deletions
diff --git a/graphics/sparklines/README b/graphics/sparklines/README
new file mode 100644
index 0000000000..37830cdc4d
--- /dev/null
+++ b/graphics/sparklines/README
@@ -0,0 +1,17 @@
+ Sparkline.sty
+
+Sparklines are intense, simple, wordlike graphics (so named by Edward
+Tufte). In lieu of a more detailed introduction, Professor Tufte's site
+has an early release of a chapter on sparklines, see
+www.edwardtufte.com. A PHP implementation can be found at
+http://sparkline.sourceforge.net/.
+
+A sparkline can be added using the sparkline environment. Also, you can
+add sparkling rectangles for the median and special sparkling dots in
+red or blue. Only use sparklines with pdflatex, or with PostScript
+output; sparklines cannot appear in a dvi-file. The sparklines package
+uses pgf, and does not work with pictex. It but might work if
+pictexwd.sty is used, but that has not been tested.
+
+Read sparklines.pdf for more details including history.
+
diff --git a/graphics/sparklines/sparklines.pdf b/graphics/sparklines/sparklines.pdf
new file mode 100644
index 0000000000..45f9401af4
--- /dev/null
+++ b/graphics/sparklines/sparklines.pdf
Binary files differ
diff --git a/graphics/sparklines/sparklines.sty b/graphics/sparklines/sparklines.sty
new file mode 100644
index 0000000000..78836d6c07
--- /dev/null
+++ b/graphics/sparklines/sparklines.sty
@@ -0,0 +1,158 @@
+%%% sparklines.sty Version 1.7
+%%%
+%%% What Are Sparklines?
+%%% Sparklines are intense, simple, wordlike graphics (so named by Edward Tufte).
+%%% In lieu of a more detailed introduction, Professor Tufte's site has an early
+%%% release of a chapter on sparklines, see www.edwardtufte.com. A PHP
+%%% implementation can be found at http://sparkline.sourceforge.net/.
+%%%
+%%% Copyright 2009 Andreas Loeffler
+%%% ========================================================================
+%%% LICENCE:
+%%% This file may be distributed under the terms of the LaTeX Project Public
+%%% License, as described in lppl.txt in the base LaTeX distribution.
+%%% Either version 1 or, at your option, any later version.
+%%% ========================================================================
+%%% al@wacc.de
+%%%
+%%% MODIFICATION HISTORY:
+%%%
+%%% Dec 26 2016:
+%%% version 1.7: Boris Veytsman (borisv@lk.net): Adding optional clipping,
+%%% extensible bottom lines, some bug fixing.
+%%%
+%%% Oct 19, 2014
+%%% version 1.6: Emiel van Miltenburg (emiel.van.miltenburg@vu.nl) -
+%%% Adding a bottom line (the x-axis, this is useful to visually
+%%% separate different bar charts that are next to each other) and
+%%% changing the color of the bottom line.
+%%%
+%%% Nov 21, 2009
+%%% version 1.5: Benno Puetz (puetz@mpipsykl.mpg.de) made change of
+%%% colors possible.
+%%%
+%%% Apr 20, 2009
+%%% version 1.4: Alexander Kowalski
+%%% (Alexander.Kowarik@statistik.gv.at) found an error concerning
+%%% spark-rectangles
+%%%
+%%% Mar 21, 2007
+%%% version 1.3: Dan Luecking (luecking@uark.edu) added user-changeable
+%%% parameters, and expanded documentation
+%%%
+%%% Mar 19, 2007
+%%% version 1.2: Harlan Harris (harlan@harris.name) added
+%%% positive-value-only bars
+%%%
+%%% Apr 21, 2005
+%%% version 1.1: bug removed thanks to Mathias Hofmann
+%%% <mathias.hofmann@web.de>
+%%%
+%%% Dec 12, 2004
+%%% version 1.0: first version of sparklines
+%%%
+
+\ProvidesPackage{sparklines}
+ [2016/12/26 v1.7 Sparklines (see more about sparklines at www.EdwardTufte.com)]
+ \typeout {Package: `sparklines' 1.7bp \space 2016/12/26}
+\RequirePackage{pgf}
+
+% We define the colors of two features: the background rectangle and
+% the spikes in a bar graph
+\definecolor{sparkrectanglecolor}{gray}{0.9}
+\definecolor{sparkspikecolor}{named}{black}
+\definecolor{sparklinecolor}{named}{black}
+\definecolor{sparkbottomlinecolor}{named}{black}
+% We define parameters for changing the sizes. These are
+% \sparklinethickness -- thickness of the line drawn by \spark,
+% \sparkdotwidth -- diameter of the dot drawn by \sparkdot,
+% \sparkspikewidth -- width of bar drawn in \sparkspike,
+% \sparklineheight -- macro, number of ex for the height of picture.
+% \sparkbottomlinewidth -- width of the bottom line
+% Defaults equal old hard-coded values.
+\newlength\sparklinethickness
+\newlength\sparkdotwidth
+\newlength\sparkspikewidth
+\newlength\sparkbottomlinethickness
+\newlength\sparklineclipsep
+\setlength\sparklinethickness{0.2pt}
+\setlength\sparkdotwidth{1.2pt}
+\setlength\sparkspikewidth{2pt}
+\setlength\sparkbottomlinethickness{2pt}
+\setlength\sparklineclipsep{2pt}
+\providecommand{\sparklineheight}{1.75}
+
+% defines sparkline environment
+% Replace hard coded line thickness and picture height with above
+% defined parameters.
+\newenvironment{sparkline}[1]{\pgfpicture{0ex}{0ex}{#1
+ ex}{\sparklineheight ex}
+ \pgfsetlinewidth{\sparklinethickness}
+ \pgfsetxvec{\pgfpoint{#1 ex}{0pt}}
+ \pgfsetyvec{\pgfpoint{0pt}{\sparklineheight ex}}
+} {\pgfstroke \endpgfpicture}
+
+\newenvironment{sparkline*}[1]{\pgfpicture{0ex}{0ex}{#1
+ ex}{\sparklineheight ex}
+ \pgfpathrectanglecorners%
+ {\pgfpoint{-\sparklineclipsep}{-\sparklineclipsep}}%
+ {\pgfpointadd{\pgfpoint{#1 ex}{\sparklineheight ex}}%
+ {\pgfpoint{\sparklineclipsep}{\sparklineclipsep}}}
+ \pgfusepath{clip}
+ \pgfsetlinewidth{\sparklinethickness}
+ \pgfsetxvec{\pgfpoint{#1 ex}{0pt}}
+ \pgfsetyvec{\pgfpoint{0pt}{\sparklineheight ex}}
+} {\pgfstroke \endpgfpicture}
+
+
+% defines sparkdot with color
+% Replace hard-coded diameter with previously defined parameter.
+\def\sparkdot #1 #2 #3 {%
+ {\pgfmoveto{\pgforigin}\color{#3}\pgfcircle[fill]{\pgfxy(#1,#2)}{\sparkdotwidth}}%
+}
+
+% defines sparkrectangle
+% Replace hard-coded rgb value with with previously defined color value.
+\def\sparkrectangle #1 #2 {%
+ \ifdim #1pt > #2pt
+ \errmessage{The upper corner #2 of rectangle cannot be lower than #1}%
+ \fi
+ {\pgfmoveto{\pgforigin}\color{sparkrectanglecolor}%
+ \pgfrect[fill]{\pgfxy(0, #1)}{\pgfxy(1, #2-#1)}}}%
+
+% defines sparkbottomline
+\newcommand{\sparkbottomline}[1][1]{\pgfsetlinewidth{\sparkbottomlinethickness}%
+ \color{sparkbottomlinecolor}%
+ \pgfline{\pgfxy(0,0)}{\pgfxy(#1,0)}\color{sparklinecolor}}
+% defines sparkbottomlinex
+\def\sparkbottomlinex #1 #2 {\pgfsetlinewidth{\sparkbottomlinethickness}%
+ \color{sparkbottomlinecolor}
+ \pgfline{\pgfxy(#1,0)}{\pgfxy(#2,0)}\color{sparklinecolor}}
+
+% defines sparkline-plot
+% Replace \@shouldIstop hack with equivalent \@ifnextchar code.
+\def\spark #1 #2 {%
+ \pgfmoveto{\pgfxy(#1,#2)} %
+ \@SPARK}
+\def\@SPARK#1 #2 {%
+ \pgfsetlinewidth{\sparklinethickness}%
+ \pgfsetstrokecolor{sparklinecolor}%
+ \pgflineto{\pgfxy(#1,#2)} %
+ \@ifnextchar/{\pgfstroke\ignorespaces}{\@SPARK}}
+
+% defines sparkspike
+% Redefine \sparkspike with code that actually detects the color
+% change. The old version had black hard-coded, but even changing that
+% made no difference in the output. The combination of setting stroke
+% color and \pgfusepath{stroke} made it work. In place of hard-coded
+% width and are now previously defined parameters.
+\def\sparkspike #1 #2 {%
+ {%
+ \pgfmoveto{\pgforigin}%
+ \pgfsetlinewidth{\sparkspikewidth}%
+ \pgfsetstrokecolor{sparkspikecolor}%
+ \pgfmoveto{\pgfxy(#1, 0)}%
+ \pgflineto{\pgfxy(#1, #2)}
+ \pgfusepath{stroke}}%
+}
+\endinput
diff --git a/graphics/sparklines/sparklines.tex b/graphics/sparklines/sparklines.tex
new file mode 100644
index 0000000000..1e038cbd5f
--- /dev/null
+++ b/graphics/sparklines/sparklines.tex
@@ -0,0 +1,333 @@
+\documentclass{article}
+
+\usepackage{sparklines}
+
+\renewcommand{\baselinestretch}{1.25}
+\let\env=\texttt
+\let\pkg=\textsf
+
+\definecolor{sparkrectanglecolor}{rgb}{0.8,0.95,0.8}
+\definecolor{sparkspikecolor}{rgb}{1,0,0}
+\setlength{\sparkdotwidth}{1.3pt}
+\setlength{\sparklinethickness}{.3pt}
+
+\begin{document}
+
+\title{Sparklines}
+\author{Andreas Loeffler \and Dan Luecking}
+\date{Updated 27~December 2016 (version 1.7)}\maketitle
+
+\section{What are sparklines?}
+
+Sparklines are intense, simple, wordlike graphics, so named by Edward
+Tufte. This is an example of sparkline:
+\begin{sparkline}{10}
+% This environment has now an own coordinate system. x and y run from 0 to 1.
+%
+% This draws a sparkling-rectangle with lower level y=0.3 and upper
+% level y=0.8
+\sparkrectangle 0.3 0.8
+%
+% This draws a blue colored sparkling-dot at x=0.5, y=0.62
+\sparkdot 0.5 0.62 blue
+%
+% This draws a red colored sparkling-dot at x=1, y=0.2
+\sparkdot 1 0.2 red
+%
+% This draws a sparkline with ten values starting at x=0.1 and
+% y=0.95, then x=0.2 and y=0.8 etc. Drawing finishes if / appears
+\spark 0.1 0.95 0.2 0.8 0.3 0.3 0.4 0.52 0.5 0.62
+ 0.6 0.7 0.7 0.5 0.8 0.4 0.9 0.25 1 0.2 /
+\end{sparkline}
+(the stock price of Daimler Chrysler, for example).
+%
+In lieu of a more detailed introduction, Professor Tufte's site
+has an early release of a chapter on sparklines, see
+www.edwardtufte.com. A PHP implementation can be found at
+http://sparkline.sourceforge.net/.
+
+A sparkline can be added using the \env{sparkline}--environment.
+Also, you can add sparkling rectangles for the median and special
+sparkling dots in red or blue. If we want to add a sparkline, be careful not to leave an empty line
+between the text left of the sparkline and the environment itself,
+since otherwise the sparkline starts a new paragraph.
+
+Sparklines do not appear within a
+dvi-file, they require either pdflatex or conversion to postscript with
+dvips. The \textsf{sparklines} package requires the \pkg{pgf} package.
+This makes it incompatible with \pkg{pictex}: the combination both
+require too many dimension parameters. It is possible that the package \pkg{sparklines}
+can be used with \pkg{pictexwd}; they can at least be loaded together
+without using too many dimensions, but no other test was conducted.
+
+
+\section{Usage}
+\paragraph{Sparkline environment}
+The sparkline at the beginning of the previous section was created with the
+following:
+\begin{verbatim}
+ \begin{sparkline}{10}
+ \sparkrectangle 0.3 0.8
+ \sparkdot 0.5 0.62 blue
+ \sparkdot 1 0.2 red
+ \spark 0.1 0.95 0.2 0.8 0.3 0.3 0.4 0.52 0.5 0.62
+ 0.6 0.7 0.7 0.5 0.8 0.4 0.9 0.25 1 0.2 /
+ \end{sparkline}
+\end{verbatim}
+
+The argument of the environment gives the width of the graphic as a
+multiple of the dimension unit \texttt{ex} (approximately the height of
+the lowercase `x' in the current font). Within the environment,
+$x$-coordinates run from 0 (extreme left of the graphic) to 1 (extreme
+right).
+
+The height of the graphic is given by the \emph{macro}
+\verb$\sparklineheight$, defined to produce \texttt{1.75} by default.
+The units are the same as for the width: the \texttt{ex} of the current
+font. You can redefine that macro (with \verb$\renewcommand$) to force
+another height. Within the graphic, the $y$-coordinate runs from 0
+(lowermost point) to 1 (uppermost).
+
+Each pair of numbers after the macro \verb$\spark$ represents a
+coordinate pair, giving the location of a point in the above described
+coordinate system. The macro draws a line from each point to the next.
+Each number must be followed by a space, and the list is terminated by a
+\texttt{/}. Be careful that there are an even number of coordinates. The
+thickness of the line that is created is the value of the length
+\verb$\sparklinethickness$, which the user may change (with
+\verb$\setlength$). The default value is \texttt{0.2pt}; the above
+example was created with the value \texttt{0.3pt}.
+
+\paragraph{Sparkrectangle}
+The \verb$\sparkrectangle$ command produces a background rectangle. It
+must be followed by two numbers, each followed by a space or the end of
+the line. They are the $y$-coordinates of the bottom and top of the
+rectangle. This is supposed to show the `normal range' of the $y$-data,
+so that a point outside that rectangle represents a departure from
+normal. The color of the rectangle is `\texttt{sparkrectanglecolor}',
+which the user may redefine (with
+\verb$\definecolor$). The initial definition is given by \\
+\indent\verb$\definecolor{sparkrectanglecolor}{gray}{0.9}$\\
+In the above example, it was first changed to a light green.
+
+\paragraph{Sparkdots}
+The colored dots are produced by \verb$\sparkdot$, the diameter of the
+dot is the value of the length \verb$\sparkdotwidth$, which the user may
+change (with \verb$\setlength$). The default value is \texttt{1.2pt};
+the above example was created a value of \texttt{1.3pt}. The command
+takes three parameters, each of which must be followed by a space or the
+end of the line. The first two are the coordinates of the center of the
+dot, the third is the color.
+
+\paragraph{Bar graphs}
+Bar graphs can be drawn easily:
+\begin{sparkline}{5}
+\sparkspike .083 .18
+\sparkspike .25 .55
+\sparkspike .417 1
+\sparkspike .583 .62
+\sparkspike .75 .42
+\sparkspike .917 .5
+\end{sparkline}.
+This was created by the code:
+\begin{verbatim}
+ \begin{sparkline}{5}
+ \sparkspike .083 .18
+ \sparkspike .25 .55
+ \sparkspike .417 1
+ \sparkspike .583 .62
+ \sparkspike .75 .42
+ \sparkspike .917 .5
+ \end{sparkline}.
+\end{verbatim}
+The macro \verb$\sparkspike$ must be followed by a pair of numbers, each
+followed by a space or the end of the line. The first of the pair is the
+horizontal location of the bar and the second is the height. The bars
+are drawn in color `\texttt{sparkspikecolor}' which the user may
+redefine (with \verb$\definecolor$). The default is \texttt{black}; the
+above example was drawn with it changed to \texttt{red}. The width of
+each bar is the value of the length \verb$\sparkspikewidth$, which the
+user may change (with \verb$\setlength$). The default is \texttt{2pt}.
+
+You can combine bars and lines:
+\begin{sparkline}{5}
+ \sparkspike .083 .18
+ \sparkspike .25 .55
+ \sparkspike .417 1
+ \sparkspike .583 .62
+ \sparkspike .75 .42
+ \sparkspike .917 .5
+ \spark 0.1 0.95 0.2 0.8 0.3 0.3 0.4 0.52 0.5 0.62
+ 0.6 0.7 0.7 0.5 0.8 0.4 0.9 0.25 1 0.2 /
+ \sparkdot 1 0.2 blue
+\end{sparkline}\space. This was created with
+\begin{verbatim}
+\begin{sparkline}{5}
+ \sparkspike .083 .18
+ \sparkspike .25 .55
+ \sparkspike .417 1
+ \sparkspike .583 .62
+ \sparkspike .75 .42
+ \sparkspike .917 .5
+ \spark 0.1 0.95 0.2 0.8 0.3 0.3 0.4 0.52 0.5 0.62
+ 0.6 0.7 0.7 0.5 0.8 0.4 0.9 0.25 1 0.2 /
+ \sparkdot 1 0.2 blue
+\end{sparkline}\space.
+\end{verbatim}
+
+
+
+\paragraph{Colors} In case you want to change colors use
+\begin{verbatim}
+\definecolor{sparkrectanglecolor}{gray}{0.9}
+\definecolor{sparkspikecolor}{named}{red}
+\definecolor{sparklinecolor}{named}{red}
+\end{verbatim}
+before the sparkline environment (see a manual about defining colors in \LaTeX{} if you do not understand the definition of \emph{named} etc.).
+
+\paragraph{Bottom line} This adds a bottom line (the x-axis) which can be useful to visually separate different bar charts that are next to each other:
+\begin{sparkline}{5}
+\definecolor{sparkbottomlinecolor}{gray}{0.9}
+\sparkspike .15 .55
+\sparkspike .317 1
+\sparkspike .483 .62
+\sparkspike .65 .42
+\sparkspike .817 .5
+\sparkbottomline[0.9]
+\end{sparkline}.
+The code used was
+\begin{verbatim}
+ \begin{sparkline}{5}
+ \definecolor{sparkbottomlinecolor}{gray}{0.9}
+ \sparkspike .15 .55
+ \sparkspike .317 1
+ \sparkspike .483 .62
+ \sparkspike .65 .42
+ \sparkspike .817 .5
+ \sparkbottomline[0.9]
+ \end{sparkline}.
+\end{verbatim}
+Changing the color of the bottom line is quite easy using the command
+like
+\begin{verbatim}
+\definecolor{sparkbottomlinecolor}{named}{red}
+\end{verbatim}. You can change the thickness of the bottom line using
+command like
+\begin{verbatim}
+\setlength\sparkbottomlinethickness{1pt}
+\end{verbatim}
+
+The optional argument of \verb|\sparkbottomline| is the length of the
+bottom line (by default~1).
+
+If you need to set both start and end of the bottomline, use
+\verb|\sparkbottomlinex| command, which has two obligatory arguments:
+the start and the end, for example,
+\definecolor{sparkbottomlinecolor}{named}{blue}%
+ \begin{sparkline}{5}
+ \sparkspike .15 .55
+ \sparkspike .317 1
+ \sparkspike .483 .62
+ \sparkspike .65 .42
+ \sparkspike .817 .5
+ \sparkbottomlinex 0.3 0.8
+ \end{sparkline}. This was created with the code
+\begin{verbatim}
+ \begin{sparkline}{5}
+ \sparkspike .15 .55
+ \sparkspike .317 1
+ \sparkspike .483 .62
+ \sparkspike .65 .42
+ \sparkspike .817 .5
+ \sparkbottomlinex 0.3 0.8
+ \end{sparkline}
+\end{verbatim}
+
+\paragraph{Clipping}
+
+Sometimes you may have sparklines outside the drawing region, for
+example,
+ \begin{sparkline}{10}
+ \sparkrectangle 0.3 0.8
+ \sparkdot 0.5 0.62 blue
+ \sparkdot 1 0.2 red
+ \spark 0.1 0.95 0.2 0.8 0.3 0.3 0.4 2.52 0.5 0.62
+ 0.6 0.7 0.7 0.5 0.8 0.4 0.9 0.25 1 0.2 /
+ \end{sparkline}. You may want to clip them. The starred version
+ \verb|sparkline*| creates \emph{clipped} sparklines: the graphics
+ outside the rectangle (0,0) -- (1,1) plus a thin border of the width
+ \verb|\sparklineclipsep| is clipped:
+ \begin{sparkline*}{10}
+ \sparkrectangle 0.3 0.8
+ \sparkdot 0.5 0.62 blue
+ \sparkdot 1 0.2 red
+ \spark 0.1 0.95 0.2 0.8 0.3 0.3 0.4 2.52 0.5 0.62
+ 0.6 0.7 0.7 0.5 0.8 0.4 0.9 0.25 1 0.2 /
+ \end{sparkline*}. The first sparkline was created with
+\begin{verbatim}
+ \begin{sparkline}{10}
+ \sparkrectangle 0.3 0.8
+ \sparkdot 0.5 0.62 blue
+ \sparkdot 1 0.2 red
+ \spark 0.1 0.95 0.2 0.8 0.3 0.3 0.4 2.52 0.5 0.62
+ 0.6 0.7 0.7 0.5 0.8 0.4 0.9 0.25 1 0.2 /
+ \end{sparkline}.
+\end{verbatim}
+The second sparkline was created with
+\begin{verbatim}
+ \begin{sparkline*}{10}
+ \sparkrectangle 0.3 0.8
+ \sparkdot 0.5 0.62 blue
+ \sparkdot 1 0.2 red
+ \spark 0.1 0.95 0.2 0.8 0.3 0.3 0.4 2.52 0.5 0.62
+ 0.6 0.7 0.7 0.5 0.8 0.4 0.9 0.25 1 0.2 /
+ \end{sparkline*}.
+\end{verbatim}
+
+The clipping separation is set to 2~pt. You can change it with
+\begin{verbatim}
+\setlength\sparklineclipsep{...}.
+\end{verbatim}
+
+
+\section*{Version history}
+\begin{description}
+
+ \item[] Dev 26, 2016
+
+ version 1.7: Boris Veytsman (borisv@lk.net). Added clipping,
+ extensible bottom lines, some bug fixes.
+
+ \item[] Oct 19, 2014
+
+ version 1.6: Emiel van Miltenburg (emiel.van.miltenburg@vu.nl) - Adding a bottom line (the x-axis, this is useful to visually separate different bar charts that are next to each other) and changing the color of the bottom line.
+
+\item[] Nov 21, 2009
+
+version 1.5: Benno Puetz (puetz@mpipsykl.mpg.de) made change of colors possible.
+
+\item[] Apr 20, 2009
+
+ version 1.4: Alexander Kowalski (Alexander.Kowarik@statistik.gv.at) found an error concerning spark-rectangles
+
+\item[] Mar 21, 2007
+
+ version 1.3: User adjustable colors and parameters added by Dan
+ Luecking $\langle$luecking@uark.edu$\rangle$
+
+\item[] Mar 19, 2007
+
+ version 1.2: Sparkbars added thanks to Harlan Harris
+ $\langle$harlan@harris.name$\rangle$
+
+\item[] Apr 21, 2005
+
+ version 1.1: bug removed thanks to Mathias Hofmann
+ $\langle$mathias.hofmann@web.de$\rangle$
+
+\item[] Dec 12, 2004
+
+ version 1.0: first version of sparklines
+\end{description}
+
+\end{document}