visualisation-utils 0.6 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -1
- data/bin/heat-map +13 -71
- data/bin/overlay +1 -3
- data/bin/scatter-plot +16 -69
- data/bin/time-line +91 -0
- data/doc/time-line.png +0 -0
- data/lib/visualisation-utils/version.rb +3 -0
- data/lib/visualisation-utils.rb +96 -0
- data/visualisation-utils.gemspec +18 -19
- data/world.dat +5257 -1319
- metadata +13 -5
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Felix Leipold
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -41,6 +41,47 @@ This incantation will bring up the gnuplot gui with the following graph:
|
|
41
41
|
|
42
42
|

|
43
43
|
|
44
|
+
time-line
|
45
|
+
=========
|
46
|
+
|
47
|
+
The `time-line` tool visualises events in a time-line.
|
48
|
+
The data is expected in two columns, a timestamp and an
|
49
|
+
event name. The default time format is `%Y-%m-%dT%H:%M:%S`.
|
50
|
+
|
51
|
+
Here is a simple example:
|
52
|
+
|
53
|
+
~~~~
|
54
|
+
time-line \
|
55
|
+
--dimensions 1300,600 \
|
56
|
+
-o time-line.png <<'END'
|
57
|
+
2015-04-24T12:21:32 A
|
58
|
+
2015-04-24T10:42:35 B
|
59
|
+
2015-04-23T11:36:26 B
|
60
|
+
2015-04-23T11:36:26 C
|
61
|
+
2015-04-22T12:38:54 A
|
62
|
+
2015-04-22T07:46:29 C
|
63
|
+
2015-04-21T18:02:01 B
|
64
|
+
2015-04-21T18:02:01 A
|
65
|
+
2015-04-17T17:35:21 B
|
66
|
+
2015-04-17T12:33:23 A
|
67
|
+
2015-04-17T09:04:37 D
|
68
|
+
2015-04-17T09:04:37 B
|
69
|
+
2015-04-17T08:29:31 D
|
70
|
+
2015-04-16T07:03:51 C
|
71
|
+
2015-04-15T07:57:23 E
|
72
|
+
2015-04-15T07:57:23 B
|
73
|
+
2015-04-15T07:04:13 B
|
74
|
+
2015-04-14T12:22:07 F
|
75
|
+
2015-04-13T09:52:25 C
|
76
|
+
END
|
77
|
+
~~~~
|
78
|
+
|
79
|
+
It yields the following graph:
|
80
|
+
|
81
|
+

|
82
|
+
|
83
|
+
|
84
|
+
|
44
85
|
heat-map
|
45
86
|
========
|
46
87
|
|
@@ -76,6 +117,6 @@ TODO
|
|
76
117
|
- [X] Secondary y-axis
|
77
118
|
- [ ] Bar chart single series
|
78
119
|
- [ ] Bar chart multiple series
|
79
|
-
- [
|
120
|
+
- [X] Discrete y-values, e.g. to visualise events over time
|
80
121
|
- [ ] Histogram plotting
|
81
122
|
|
data/bin/heat-map
CHANGED
@@ -1,29 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'trollop'
|
3
|
-
require '
|
4
|
-
|
5
|
-
DATA_FILE_NAME="/tmp/plot-"+`date "+%s"`.strip+".dat"
|
6
|
-
PLOT_FILE_NAME="/tmp/plot-"+`date "+%s"`.strip+".plt"
|
3
|
+
require 'visualisation-utils'
|
7
4
|
|
5
|
+
parser = VisualisationUtils::BasicParser.new
|
8
6
|
|
9
7
|
@opts = Trollop::options do
|
10
8
|
banner "heat-map takes comma and newline separated table of coordinate from stdin and renders them using gnuplot"
|
11
|
-
|
12
|
-
opt :debug, "debug"
|
13
|
-
opt :title, "Title", :type=> String, :short => 't'
|
14
|
-
opt :font, "Font", :type => String, :short => 'f'
|
15
|
-
opt :extra_header, "Extra commands to be put in the header of the gnuplot file", :type => String
|
9
|
+
parser.standard_opts(self)
|
16
10
|
end
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
if (!find_executable 'gnuplot')
|
21
|
-
STDERR.puts("This utility depends on gnuplot. Please install gnuplot using your favourite package manager.")
|
22
|
-
exit(1)
|
23
|
-
end
|
12
|
+
gnu_plot_tool=VisualisationUtils::GnuPlotTool.new(@opts)
|
24
13
|
|
25
|
-
|
26
|
-
# TODO I do want to be streamed!
|
27
14
|
input = `cat`
|
28
15
|
|
29
16
|
freq_list = input.split("\n").map{|line|
|
@@ -42,62 +29,27 @@ max_val = freq_values.max
|
|
42
29
|
min_val = freq_values.min
|
43
30
|
mid_val = (min_val + (max_val - min_val)/2).round(1)
|
44
31
|
|
45
|
-
|
32
|
+
if (gnu_plot_tool.debug?)
|
33
|
+
puts "Min. value: #{min_val}, max value: #{max_val}"
|
34
|
+
end
|
46
35
|
|
47
36
|
full_map = (-179..179).map{|lon|
|
48
37
|
(-89..89).map{|lat|
|
49
38
|
key = "#{lat},#{lon}"
|
50
|
-
"#{lat} #{lon} #{freqs[key]||
|
39
|
+
"#{lat} #{lon} #{freqs[key]||"NaN"}"
|
51
40
|
}
|
52
41
|
}.join("\n")
|
53
42
|
|
54
|
-
|
43
|
+
DATA_FILE_NAME="/tmp/plot-"+`date "+%s"`.strip+".dat"
|
55
44
|
File.open(DATA_FILE_NAME, "w"){|f| f.write(full_map)}
|
56
|
-
|
57
|
-
|
58
|
-
font_size = "12"
|
59
|
-
|
60
|
-
extra_header = @opts[:extra_header] || ""
|
61
|
-
|
62
|
-
if (@opts[:outfile])
|
63
|
-
filename = @opts[:outfile]
|
64
|
-
extension = filename.gsub(/[^.]*\./,"")
|
65
|
-
if (extension == "png")
|
66
|
-
terminal=<<EOF
|
67
|
-
set term pngcairo font '#{font},#{font_size}' transparent size 1200,800
|
68
|
-
set output '#{filename}'
|
69
|
-
|
70
|
-
EOF
|
71
|
-
elsif (extension == "eps")
|
72
|
-
terminal=<<EOF
|
73
|
-
set term epscairo size 1200,800 font '#{font},#{font_size}'
|
74
|
-
set output '#{filename}'
|
75
|
-
EOF
|
76
|
-
elsif (extension == "pdf")
|
77
|
-
terminal=<<EOF
|
78
|
-
set term pdfcairo size 22cm,14cm font '#{font},#{font_size}'
|
79
|
-
set output '#{filename}'
|
80
|
-
EOF
|
81
|
-
elsif (extension == "svg")
|
82
|
-
terminal=<<EOF
|
83
|
-
set term svg size 1200,800 font '#{font},#{font_size}'
|
84
|
-
set output '#{filename}'
|
85
|
-
EOF
|
86
|
-
else
|
87
|
-
throw "Unknown output format '.#{extension}'."
|
88
|
-
end
|
89
|
-
|
90
|
-
|
45
|
+
if (gnu_plot_tool.debug?)
|
46
|
+
STDERR.puts "data file " + DATA_FILE_NAME
|
91
47
|
end
|
92
48
|
|
93
49
|
|
94
50
|
world_dat=File.join(File.dirname(File.expand_path(__FILE__)), '/../world.dat')
|
95
51
|
|
96
|
-
|
97
|
-
|
98
|
-
#{terminal}
|
99
|
-
set title "#{title}"
|
100
|
-
|
52
|
+
gnu_plot_tool.plot(<<EOF
|
101
53
|
# color definitions
|
102
54
|
set border lw 1.5
|
103
55
|
set style line 1 lc rgb 'black' lt 1 lw 2
|
@@ -115,14 +67,4 @@ set palette defined (0 "white",#{min_val} "#00ffff",#{mid_val} "yellow",#{max_va
|
|
115
67
|
plot '#{DATA_FILE_NAME}' u 2:1:3 w image, \
|
116
68
|
'#{world_dat}' with lines linestyle 1
|
117
69
|
EOF
|
118
|
-
|
119
|
-
puts "data file " + DATA_FILE_NAME
|
120
|
-
puts "plot file " + PLOT_FILE_NAME
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
File.open(PLOT_FILE_NAME, "w"){|f| f.write(script)}
|
125
|
-
|
126
|
-
persistent_opt = @opts[:outfile]?"":"-p"
|
127
|
-
|
128
|
-
`gnuplot #{persistent_opt} #{PLOT_FILE_NAME}`
|
70
|
+
)
|
data/bin/overlay
CHANGED
@@ -11,6 +11,4 @@ basename="$(basename "$FOREGROUND")"
|
|
11
11
|
SIGNED=`dirname "$FOREGROUND"`"/${basename%.*}.branded.png"
|
12
12
|
|
13
13
|
convert "${FOREGROUND}" "${BACKGROUND}" -gravity center -compose DstOver -composite -background white -format png /tmp/output.png
|
14
|
-
convert /tmp/output.png -background white -flatten -format png "$SIGNED"
|
15
|
-
|
16
|
-
|
14
|
+
convert /tmp/output.png -background white -flatten -format png "$SIGNED"
|
data/bin/scatter-plot
CHANGED
@@ -1,33 +1,26 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'trollop'
|
3
|
-
require '
|
3
|
+
require 'visualisation-utils'
|
4
|
+
|
5
|
+
parser = VisualisationUtils::BasicParser.new
|
6
|
+
|
4
7
|
|
5
8
|
DATA_FILE_NAME="/tmp/plot-"+`date "+%s"`.strip+".dat"
|
6
|
-
PLOT_FILE_NAME="/tmp/plot-"+`date "+%s"`.strip+".plt"
|
7
9
|
|
8
10
|
|
9
11
|
@opts = Trollop::options do
|
10
12
|
banner "scatter-plot takes whitespace separated tables from stdin and renders them using gnuplot"
|
11
|
-
|
12
|
-
opt :legends, "Legend for columns,
|
13
|
-
opt :plot_styles, "Style of plot, comma
|
14
|
-
opt :axis_labels, "Labels for axes, pipe
|
15
|
-
opt :axes, "
|
13
|
+
parser.standard_opts(self)
|
14
|
+
opt :legends, "Legend for columns, comma-separated list", :type => String, :short => 'l'
|
15
|
+
opt :plot_styles, "Style of plot, comma-separated list, values as expected by gnuplot, e.g. lines, points, linespoints, defaults to points", :type => String
|
16
|
+
opt :axis_labels, "Labels for axes, pipe-separated list", :type => String
|
17
|
+
opt :axes, "Y-axes used for the respective columns, pipe-seprated list.", :type => String
|
16
18
|
opt :numc, "Number of data columns", :type => Integer, :short => 'c'
|
17
|
-
opt :debug, "debug"
|
18
|
-
opt :title, "Title", :type=> String, :short => 't'
|
19
|
-
opt :font, "Font", :type => String, :short => 'f'
|
20
19
|
opt :time, "Time format for time series data, strftime expression", :type => String
|
21
|
-
opt :ranges, "A list comma
|
22
|
-
opt :extra_header, "Extra commands to be put in the header of the gnuplot file", :type => String
|
20
|
+
opt :ranges, "A list of comma-separated pairs of gnuplot range-expressions, e.g. xrange [-10:10], yrange[0:40], y2range [0:1]", type:String
|
23
21
|
end
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
if (!find_executable 'gnuplot')
|
28
|
-
STDERR.puts("This utility depends on gnuplot. Please install gnuplot using your favourite package manager.")
|
29
|
-
exit(1)
|
30
|
-
end
|
23
|
+
gnu_plot_tool=VisualisationUtils::GnuPlotTool.new(@opts)
|
31
24
|
|
32
25
|
# TODO I do want to be streamed!
|
33
26
|
input = `cat`
|
@@ -49,46 +42,11 @@ plot_styles = @opts[:plot_styles] ? @opts[:plot_styles].strip().split(/,/) : [
|
|
49
42
|
|
50
43
|
ranges = @opts[:ranges] ? @opts[:ranges].split(",").map{ |r| "set #{r}"}.join("\n") : ""
|
51
44
|
|
52
|
-
font = @opts[:font] || "Futura"
|
53
|
-
font_size = "12"
|
54
45
|
using_list = legends.zip((2..100).to_a, axes, plot_styles).
|
55
46
|
map{|text, index, yaxis, plot_style|
|
56
47
|
"'#{DATA_FILE_NAME}' using 1:#{index} title \"#{text}\" with #{plot_style} ls #{index-1} axes x1y#{yaxis}"
|
57
48
|
}.join(", ")
|
58
49
|
|
59
|
-
extra_header = @opts[:extra_header] || ""
|
60
|
-
|
61
|
-
if (@opts[:outfile])
|
62
|
-
filename = @opts[:outfile]
|
63
|
-
extension = filename.gsub(/[^.]*\./,"")
|
64
|
-
if (extension == "png")
|
65
|
-
terminal=<<EOF
|
66
|
-
set term pngcairo font '#{font},#{font_size}' transparent size 1200,800
|
67
|
-
set output '#{filename}'
|
68
|
-
|
69
|
-
EOF
|
70
|
-
elsif (extension == "eps")
|
71
|
-
terminal=<<EOF
|
72
|
-
set term epscairo size 1200,800 font '#{font},#{font_size}'
|
73
|
-
set output '#{filename}'
|
74
|
-
EOF
|
75
|
-
elsif (extension == "pdf")
|
76
|
-
terminal=<<EOF
|
77
|
-
set term pdfcairo size 22cm,14cm font '#{font},#{font_size}'
|
78
|
-
set output '#{filename}'
|
79
|
-
EOF
|
80
|
-
elsif (extension == "svg")
|
81
|
-
terminal=<<EOF
|
82
|
-
set term svg size 1200,800 font '#{font},#{font_size}'
|
83
|
-
set output '#{filename}'
|
84
|
-
EOF
|
85
|
-
else
|
86
|
-
throw "Unknown output format '.#{extension}'."
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
50
|
|
93
51
|
if (@opts[:time])
|
94
52
|
timeExpr=@opts[:time]
|
@@ -103,8 +61,10 @@ else
|
|
103
61
|
end
|
104
62
|
|
105
63
|
|
106
|
-
|
107
|
-
|
64
|
+
STDERR.puts "data file " + DATA_FILE_NAME
|
65
|
+
|
66
|
+
|
67
|
+
gnu_plot_tool.plot(<<EOF
|
108
68
|
#{axis_labels.map{ | axis | pair=axis.split(":"); "set #{pair[0]}label '#{pair[1]}';"}.join("\n")}
|
109
69
|
set key outside
|
110
70
|
set key left top
|
@@ -120,24 +80,11 @@ set tics nomirror
|
|
120
80
|
set style line 12 lc rgb '#808080' lt 0 lw 1
|
121
81
|
set grid back ls 12
|
122
82
|
set y2tics
|
123
|
-
#{extra_header}
|
124
83
|
|
125
84
|
#{ranges}
|
126
85
|
|
127
|
-
set title "#{title}"
|
128
86
|
#{time}
|
129
87
|
plot #{using_list}
|
130
|
-
|
131
88
|
EOF
|
89
|
+
)
|
132
90
|
|
133
|
-
|
134
|
-
puts "data file " + DATA_FILE_NAME
|
135
|
-
puts "plot file " + PLOT_FILE_NAME
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
File.open(PLOT_FILE_NAME, "w"){|f| f.write(script)}
|
140
|
-
|
141
|
-
persistent_opt = @opts[:outfile]?"":"-p"
|
142
|
-
|
143
|
-
`gnuplot #{persistent_opt} #{PLOT_FILE_NAME}`
|
data/bin/time-line
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'trollop'
|
3
|
+
require 'visualisation-utils'
|
4
|
+
|
5
|
+
parser = VisualisationUtils::BasicParser.new
|
6
|
+
|
7
|
+
DATA_FILE_NAME="/tmp/plot-"+`date "+%s"`.strip+".dat"
|
8
|
+
|
9
|
+
@opts = Trollop::options do
|
10
|
+
banner "time-line takes whitespace separated tables of timestamps and events (names) from stdin and renders them using gnuplot"
|
11
|
+
parser.standard_opts(self)
|
12
|
+
opt :time, "Format for timestamp, strftime expression", :type => String
|
13
|
+
end
|
14
|
+
|
15
|
+
gnu_plot_tool=VisualisationUtils::GnuPlotTool.new(@opts)
|
16
|
+
|
17
|
+
# TODO I do want to be streamed!
|
18
|
+
input = `cat`
|
19
|
+
lines = input.split("\n").map{|line| line.split(/\s+/)}
|
20
|
+
|
21
|
+
values=lines.map{|line| line[1]}.uniq.sort.reverse
|
22
|
+
coords=Hash[values.each_with_index.map { |x,i| [x, i + 0.5] }]
|
23
|
+
|
24
|
+
lines_with_y=lines.map{|line| line[0] + " " + coords[line[1]].to_s}
|
25
|
+
|
26
|
+
File.open(DATA_FILE_NAME, "w"){|f| f.write(lines_with_y.join("\n"))}
|
27
|
+
|
28
|
+
numc_input=input.split(/\n/)[0].split(/\s+/).length - 1
|
29
|
+
|
30
|
+
if gnu_plot_tool.debug?
|
31
|
+
STDERR.puts "Detected numc y-columns #{numc_input}"
|
32
|
+
end
|
33
|
+
|
34
|
+
numc = numc_input
|
35
|
+
|
36
|
+
if (numc != 1)
|
37
|
+
STDERR.puts("Expecting 2 cols of input, a timestamp and an event identifier.")
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
|
41
|
+
axis_labels = (@opts[:axis_labels] || " | ").split("|")
|
42
|
+
|
43
|
+
legends = (@opts[:legends] ? @opts[:legends].strip().split(/,/) : (1..(numc)).map{|x| ""}).map{|x| x.strip}
|
44
|
+
|
45
|
+
axes = @opts[:axes] ? @opts[:axes].split("|") : [1] * legends.length
|
46
|
+
|
47
|
+
plot_styles = @opts[:plot_styles] ? @opts[:plot_styles].strip().split(/,/) : [ "points" ] * legends.length
|
48
|
+
|
49
|
+
using_list = legends.zip((2..100).to_a, axes, plot_styles).
|
50
|
+
map{|text, index, yaxis, plot_style|
|
51
|
+
"'#{DATA_FILE_NAME}' using 1:#{index} title \"#{text}\" with #{plot_style} ls #{index-1} axes x1y#{yaxis}"
|
52
|
+
}.join(", ")
|
53
|
+
|
54
|
+
|
55
|
+
timeExpr=@opts[:time]||"%Y-%m-%dT%H:%M:%S"
|
56
|
+
|
57
|
+
if gnu_plot_tool.debug?
|
58
|
+
STDERR.puts "data file " + DATA_FILE_NAME
|
59
|
+
end
|
60
|
+
|
61
|
+
gnu_plot_tool.plot(<<EOF
|
62
|
+
#{axis_labels.map{ | axis | pair=axis.split(":"); "set #{pair[0]}label '#{pair[1]}';"}.join("\n")}
|
63
|
+
#set key outside
|
64
|
+
#set key left top
|
65
|
+
#set offsets 1, 1, 1, 0
|
66
|
+
set style line 1 lc rgb '#cc0000' pt 4 ps 1 lt 1 lw 3 # --- red
|
67
|
+
set style line 2 lc rgb '#4e9a06' pt 6 ps 1 lt 1 lw 3 # --- green
|
68
|
+
set style line 3 lc rgb '#3465a4' pt 7 ps 1 lt 1 lw 3 # --- blue
|
69
|
+
set style line 4 lc rgb '#f57900' pt 8 ps 1 lt 1 lw 3 # --- orange
|
70
|
+
set style line 5 lc rgb '#edd400' pt 9 ps 1 lt 1 lw 3 # --- butter
|
71
|
+
set style line 11 lc rgb '#808080' lt 1
|
72
|
+
set border 3 back ls 11
|
73
|
+
set tics nomirror
|
74
|
+
set style line 12 lc rgb '#808080' lt 0 lw 1
|
75
|
+
set grid back ls 12
|
76
|
+
|
77
|
+
set yrange [0:#{values.length}]
|
78
|
+
set lmargin 5
|
79
|
+
set rmargin 5
|
80
|
+
|
81
|
+
set ytics (#{coords.map{|pair| '"' + pair[0].gsub("_", " ") + '"' + " " + pair[1].to_s}.join(", ") })
|
82
|
+
|
83
|
+
set xdata time
|
84
|
+
set format x "%d %b %y"
|
85
|
+
set timefmt "#{timeExpr}"
|
86
|
+
set autoscale x
|
87
|
+
|
88
|
+
plot #{using_list}
|
89
|
+
EOF
|
90
|
+
)
|
91
|
+
|
data/doc/time-line.png
ADDED
Binary file
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require "visualisation-utils/version"
|
2
|
+
|
3
|
+
module VisualisationUtils
|
4
|
+
|
5
|
+
class BasicParser
|
6
|
+
def standard_opts(opt)
|
7
|
+
opt.opt :outfile, "Output file name", :type => String, :short => 'o'
|
8
|
+
opt.opt :debug, "debug"
|
9
|
+
opt.opt :title, "Title", :type => String, :short => 't'
|
10
|
+
opt.opt :font, "Font", :type => String, :short => 'f'
|
11
|
+
opt.opt :font_size, "Font size", :type => String
|
12
|
+
opt.opt :dimensions, "Image dimensions", :type => String
|
13
|
+
opt.opt :transparent, "use transparent background"
|
14
|
+
opt.opt :extra_header, "Extra commands to be put in the header of the gnuplot file", :type => String
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Wraps the gnu plot invocation and basic scaffold for shared options
|
19
|
+
# around output format.
|
20
|
+
class GnuPlotTool
|
21
|
+
|
22
|
+
def initialize(opts)
|
23
|
+
@title = opts[:title] || ""
|
24
|
+
@opts = opts
|
25
|
+
@debug = opts[:debug]
|
26
|
+
|
27
|
+
if (! system 'which -s gnuplot')
|
28
|
+
STDERR.puts("This utility depends on gnuplot. Please install gnuplot using your favourite package manager.")
|
29
|
+
exit(1)
|
30
|
+
end
|
31
|
+
|
32
|
+
font = @opts[:font] || "Helvetica"
|
33
|
+
font_size = @opts[:font_size ] || "12"
|
34
|
+
|
35
|
+
@extra_header = @opts[:extra_header] || ""
|
36
|
+
|
37
|
+
dimensions=@opts[:dimensions] || "1200,800"
|
38
|
+
|
39
|
+
if (@opts[:outfile])
|
40
|
+
filename = @opts[:outfile]
|
41
|
+
extension = filename.gsub(/[^.]*\./, "")
|
42
|
+
if (extension == "png")
|
43
|
+
@terminal=<<EOF
|
44
|
+
set term pngcairo font '#{font},#{font_size}' #{@opts[:transparent]?"transparent":""} size #{dimensions}
|
45
|
+
set output '#{filename}'
|
46
|
+
EOF
|
47
|
+
elsif (extension == "eps")
|
48
|
+
@terminal=<<EOF
|
49
|
+
set term epscairo size #{dimensions} font '#{font},#{font_size}'
|
50
|
+
set output '#{filename}'
|
51
|
+
EOF
|
52
|
+
elsif (extension == "pdf")
|
53
|
+
@terminal=<<EOF
|
54
|
+
set term pdfcairo size 22cm,14cm font '#{font},#{font_size}'
|
55
|
+
set output '#{filename}'
|
56
|
+
EOF
|
57
|
+
elsif (extension == "svg")
|
58
|
+
@terminal=<<EOF
|
59
|
+
set term svg size #{dimensions} font '#{font},#{font_size}'
|
60
|
+
set output '#{filename}'
|
61
|
+
EOF
|
62
|
+
else
|
63
|
+
throw "Unknown output format '.#{extension}'."
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def debug?
|
69
|
+
@debug
|
70
|
+
end
|
71
|
+
|
72
|
+
def plot(script)
|
73
|
+
plot_file_name="/tmp/plot-"+`date "+%s"`.strip+".plt"
|
74
|
+
full_script=<<EOF
|
75
|
+
#{@terminal}
|
76
|
+
set title "#{@title}"
|
77
|
+
|
78
|
+
#{@extra_header}
|
79
|
+
|
80
|
+
#{script}
|
81
|
+
EOF
|
82
|
+
|
83
|
+
if (debug?)
|
84
|
+
STDERR.puts "plot file " + plot_file_name
|
85
|
+
end
|
86
|
+
|
87
|
+
File.open(plot_file_name, "w") { |f| f.write(full_script) }
|
88
|
+
|
89
|
+
persistent_opt = @opts[:outfile] ? "" : "-p"
|
90
|
+
|
91
|
+
`gnuplot #{persistent_opt} #{plot_file_name}`
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
data/visualisation-utils.gemspec
CHANGED
@@ -1,23 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
for visualising data from the command line.'
|
6
|
-
s.version = '0.6'
|
7
|
-
s.platform = Gem::Platform::RUBY
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'visualisation-utils/version'
|
8
5
|
|
9
|
-
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "visualisation-utils"
|
8
|
+
gem.version = VisualisationUtils::VERSION
|
9
|
+
gem.authors = ["Felix Leipold"]
|
10
|
+
gem.email = [""]
|
11
|
+
gem.description = %q{visualisation-utils provides a number of utilities
|
12
|
+
for visualising data from the command line.}
|
13
|
+
gem.summary = %q{utilities for quick visualisation}
|
14
|
+
gem.homepage = "https://github.com/programmiersportgruppe/visualisation-utils"
|
10
15
|
|
11
|
-
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
12
20
|
|
13
|
-
|
14
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
-
|
16
|
-
s.author = 'Felix Leipold'
|
17
|
-
s.email = ''
|
18
|
-
s.homepage = 'https://github.com/programmiersportgruppe/visualisation-utils'
|
19
|
-
s.license = 'MIT'
|
20
|
-
|
21
|
-
s.add_dependency('trollop')
|
21
|
+
gem.add_dependency('trollop')
|
22
22
|
end
|
23
|
-
|