-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot-graph
executable file
·89 lines (77 loc) · 2.05 KB
/
plot-graph
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
#!/bin/sh
#==============================================================================
# plot-graph
# File ID: ccf32478-1c7d-11e4-af72-000df06acc56
#
# Generate Gnuplopt graphs of the Open Hub data.
#
# Author: Øyvind A. Holm <[email protected]>
# License: GNU General Public License version 2 or later.
#==============================================================================
progname=plot-graph
VERSION=0.7.1
test "$1" = "--bezier" && { use_bezier=1; shift; } || unset use_bezier
test "$1" = "--svg" && { use_svg=1; shift; } || unset use_svg
test "$1" = "--zoom" && { use_zoom=1; shift; } || unset use_zoom
file="$1"
filebase="$(basename "$1" .dat)"
graph() {
local column=$1
local lt=$2
local title=$3
printf '"%s" using 1:%u title "%s" ' "$file" "$column" "$title"
if test -z "$use_bezier"; then
echo -n w l lt rgb \"$lt\"
printf ', "%s" using 1:%u notitle ' \
"$file" "$column"
echo w l s b dt 2 lt rgb \"$lt\"
else
echo -n w l s b lt rgb \"$lt\"
fi
}
set_svg() {
test "$use_svg" != "1" && return
test "$use_zoom" = "1" && { svg_str="-zoom"; } || unset svg_str
echo set terminal svg size 1189,841
echo set output \"graph/$filebase$svg_str.svg\"
echo set object 1 rect from screen 0, 0, 0 to screen 1, 1, 0 behind
echo set object 1 rect fc rgb \"white\" fillstyle solid 1.0
}
set_yrange() {
if test "$use_zoom" = "1"; then
maxcount=$(
cut -f 2,3,5,6 -d ' ' "$file" |
fmt -1 |
sort -n |
tail -1
)
echo "set yrange [0.1:$maxcount]"
else
echo "set yrange [0.1:]"
fi
}
cleanup() {
rm -f $tmpfile
}
tmpfile=$(date +%s).$$.tmp
cat <<END >$tmpfile
$(set_svg)
set xdata time
set grid
set timefmt "%Y-%m-%dT%H:%M:%SZ"
set format x "%Y-%m-%d"
$(set_yrange)
plot \
$(graph 2 red Bazaar), \\
$(graph 3 blue CVS), \\
$(graph 4 green Git), \\
$(graph 5 cyan Mercurial), \\
$(graph 6 magenta Subversion)
END
trap cleanup INT TERM
if test "$use_svg" != "1"; then
echo "pause -1 \"$progname: Press Enter...\"" >>$tmpfile
fi
gnuplot -persist $tmpfile
rm -f $tmpfile
# vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :