[pypy-commit] extradoc extradoc: add spark line

cfbolz noreply at buildbot.pypy.org
Thu Sep 6 13:26:42 CEST 2012


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: extradoc
Changeset: r4751:808dff687e14
Date: 2012-09-06 13:26 +0200
http://bitbucket.org/pypy/extradoc/changeset/808dff687e14/

Log:	add spark line

diff --git a/talk/vmil2012/paper.tex b/talk/vmil2012/paper.tex
--- a/talk/vmil2012/paper.tex
+++ b/talk/vmil2012/paper.tex
@@ -1,6 +1,8 @@
 \documentclass[10pt,preprint]{sigplanconf}
 
 \usepackage{ifthen}
+\usepackage{sparklines}
+\usepackage{booktabs}
 \usepackage{fancyvrb}
 \usepackage{color}
 \usepackage{wrapfig}
@@ -1026,6 +1028,7 @@
 
 
 %\section*{Appendix}
+
 %\todo{remove this section and the figures}
 %\begin{figure*}
 %    \include{figures/ops_count_table}
diff --git a/talk/vmil2012/sparklines.sty b/talk/vmil2012/sparklines.sty
new file mode 100644
--- /dev/null
+++ b/talk/vmil2012/sparklines.sty
@@ -0,0 +1,108 @@
+%%% sparklines.sty Version 1.5
+%%%
+%%% 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 at wacc.de
+%%%
+%%% MODIFICATION HISTORY:
+%%% Nov 21, 2009
+%%% version 1.5: Benno Puetz (puetz at mpipsykl.mpg.de) made change of colors possible.
+%%% Apr 20, 2009
+%%% version 1.4: Alexander Kowalski (Alexander.Kowarik at statistik.gv.at) found an error concerning spark-rectangles
+%%% Mar 21, 2007
+%%% version 1.3: Dan Luecking (luecking at uark.edu) added user-changeable
+%%% parameters, and expanded documentation
+%%% Mar 19, 2007
+%%% version 1.2: Harlan Harris (harlan at harris.name) added positive-value-only bars
+%%% Apr 21, 2005
+%%% version 1.1: bug removed thanks to Mathias Hofmann <mathias.hofmann at web.de>
+%%% Dec 12, 2004
+%%% version 1.0: first version of sparklines
+
+\ProvidesPackage{sparklines}
+    [2007/11/21 v1.5 Sparklines (see more about sparklines at www.EdwardTufte.com)]
+    \typeout {Package: `sparklines' 1.5bp \space 2009/11/21}
+\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}
+
+% 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.
+% Defaults equal old hard-coded values.
+\newlength\sparklinethickness
+\newlength\sparkdotwidth
+\newlength\sparkspikewidth
+\setlength\sparklinethickness{0.2pt}
+\setlength\sparkdotwidth{1.2pt}
+\setlength\sparkspikewidth{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}
+
+% 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 sparkline-plot
+% Replace \@shouldIstop hack with equivalent \@ifnextchar code.
+\def\spark #1 #2 {%
+  \pgfmoveto{\pgfxy(#1,#2)} %
+  \@SPARK}
+\def\@SPARK#1 #2 {%
+  \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/talk/vmil2012/tool/build_tables.py b/talk/vmil2012/tool/build_tables.py
--- a/talk/vmil2012/tool/build_tables.py
+++ b/talk/vmil2012/tool/build_tables.py
@@ -26,6 +26,7 @@
 
     table = []
     head = ['Benchmark',
+            'Sparkline' + "~" * 8,
             'Failing',
             '> %d failures' % BRIDGE_THRESHOLD,
             '50\% of failures',
@@ -42,6 +43,7 @@
         num_99 = we_are_n_percent(info, 99)
         num_99_dot_9 = we_are_n_percent(info, 99.9)
         res = [bench.replace('_', '\\_'),
+                make_sparkline(info['results'], num_50 - 1, num_99 - 1, num_99_dot_9 - 1),
                 "%.1f\\%%" % (100 * total_failures/total),
                 "%.1f\\%%" % (100 * bridges/total),
                 "%d~~\\textasciitilde{}~~%.3f\\%%"  % (num_50, num_50 / total * 100),
@@ -68,6 +70,23 @@
             return (i + 1)
     return -1
 
+def make_sparkline(results, index_50, index_99, index_99_9):
+    results = results.values()
+    results.sort()
+    results.reverse()
+    running = 0
+    lines = ["\\begin{sparkline}{20}"]
+    lines.append("\\sparkdot %04f %04f blue" % (float(index_50) / (len(results) - 1), float(results[index_50]) / max(results)))
+    lines.append("\\sparkdot %04f %04f red" % (float(index_99) / (len(results) - 1), float(results[index_99]) / max(results)))
+    lines.append("\\sparkdot %04f %04f green" % (float(index_99_9) / (len(results) - 1), float(results[index_99_9]) / max(results)))
+    lines.append("\\spark")
+    for i, result in enumerate(results):
+        lines.append("%04f %04f" % (float(i) / (len(results) - 1), float(result) / max(results)))
+    lines.append("/")
+    lines.append("\\end{sparkline}")
+    return " ".join(lines)
+
+
 def build_resume_data_table(csvfiles, texfile, template):
     assert len(csvfiles) == 1
     lines = getlines(csvfiles[0])


More information about the pypy-commit mailing list