summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/sparklines/sparklines.sty
blob: 78836d6c07b46512436f03043453e00db51b2bc2 (plain)
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
%%% 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