gnuplotter 0.0.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +83 -1
- data/Rakefile +17 -0
- data/examples/heatmap.rb +28 -0
- data/examples/histogram.rb +31 -0
- data/examples/lines.rb +30 -0
- data/{gnuplotter.gemspecs → gnuplotter.gemspec} +0 -2
- data/lib/gnuplotter.rb +259 -0
- data/lib/gnuplotter/version.rb +2 -2
- data/test/helper.rb +54 -0
- data/test/test_gnuplotter.rb +108 -0
- metadata +13 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee985cfe2433db143aeb9be53f61fb781dcde027
|
4
|
+
data.tar.gz: 0fab1e8d3ef299dfd4b81f5421d45955ef6a1bae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29b60ec46a3ce0ec355457737fe8d9ccbe52344e1ac95e97bdbeafda492103a722b5a029c267cc11074d81490f51ab0e490caebedb8d8822e61f9f232802bbef
|
7
|
+
data.tar.gz: 25b22ca33e40b96d03316e06fe971ae7e112cc8be235ff59934b258516896bc7f73d77c59f6efb5cd7d48e9f055357d96813f12b4466482430113e00ed754daa
|
data/README.md
CHANGED
@@ -1,2 +1,84 @@
|
|
1
1
|
# gnuplotter
|
2
|
-
|
2
|
+
|
3
|
+
Gnuplot is a very powerful tool to plot scientific data. This is a Ruby wrapper
|
4
|
+
around Gnuplot with a syntax closely following Gnuplot's.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
First you must install Gnuplot. Follow the instruction at the Gnuplot website:
|
9
|
+
|
10
|
+
http://www.gnuplot.info/
|
11
|
+
|
12
|
+
Then install the Ruby gem run:
|
13
|
+
|
14
|
+
`gem install gnuplotter`
|
15
|
+
|
16
|
+
All done!
|
17
|
+
|
18
|
+
Example
|
19
|
+
-------
|
20
|
+
|
21
|
+
```
|
22
|
+
#!/usr/bin/env ruby
|
23
|
+
|
24
|
+
require 'gnuplotter'
|
25
|
+
|
26
|
+
data1 = [
|
27
|
+
[0, 0, 0.5, 0.5],
|
28
|
+
[0, 1, -0.5, 0.5],
|
29
|
+
[1, 1, 1, 0]
|
30
|
+
]
|
31
|
+
|
32
|
+
data2 = [
|
33
|
+
[10, 10, 1.5, 1.5],
|
34
|
+
[10, 11, -1.5, 1.5],
|
35
|
+
[11, 11, 11, 10]
|
36
|
+
]
|
37
|
+
|
38
|
+
gp = GnuPlotter.new
|
39
|
+
|
40
|
+
gp.set title: "Foobar"
|
41
|
+
gp.set terminal: "dumb"
|
42
|
+
|
43
|
+
gp.add_dataset(using: "1:2:3:4", with: "vectors nohead", title: "'foo'") do |plotter|
|
44
|
+
data1.map { |d| plotter << d }
|
45
|
+
end
|
46
|
+
|
47
|
+
gp.add_dataset(using: "1:2:3:4", with: "vectors nohead", title: "'bar'") do |plotter|
|
48
|
+
data2.map { |d| plotter << d }
|
49
|
+
end
|
50
|
+
|
51
|
+
puts gp.plot
|
52
|
+
```
|
53
|
+
|
54
|
+
See more examples in the `examples/` directory.
|
55
|
+
|
56
|
+
Testing
|
57
|
+
-------
|
58
|
+
gnuplotter have a `to_gp` method that dumps a standaline Gnuplot script with
|
59
|
+
data, which is very useful for debugging and testing. For the above example
|
60
|
+
the output is:
|
61
|
+
|
62
|
+
```
|
63
|
+
set title "Foobar"
|
64
|
+
set terminal dumb
|
65
|
+
plot "-" using 1:2:3:4 with vectors nohead title 'foo', "-" using 1:2:3:4 with vectors nohead title 'bar'
|
66
|
+
0 0 0.5 0.5
|
67
|
+
0 1 -0.5 0.5
|
68
|
+
1 1 1 0
|
69
|
+
e
|
70
|
+
10 10 1.5 1.5
|
71
|
+
10 11 -1.5 1.5
|
72
|
+
11 11 11 10
|
73
|
+
e
|
74
|
+
```
|
75
|
+
|
76
|
+
|
77
|
+
Author
|
78
|
+
------
|
79
|
+
Copyright 2015 Martin Asser Hansen mail@maasha.dk
|
80
|
+
|
81
|
+
License
|
82
|
+
-------
|
83
|
+
GPL/v2
|
84
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require 'bundler'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
|
7
|
+
task :default => "test"
|
8
|
+
|
9
|
+
Rake::TestTask.new do |t|
|
10
|
+
t.test_files = Dir['test/*'].select { |f| File.basename(f).match(/^test_.+\.rb$/) }
|
11
|
+
t.warning = true
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Add or update rdoc"
|
15
|
+
task :doc do
|
16
|
+
`rdoc lib/`
|
17
|
+
end
|
data/examples/heatmap.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'gnuplotter'
|
4
|
+
|
5
|
+
gp = GnuPlotter.new
|
6
|
+
gp.set title: "Heatmap"
|
7
|
+
gp.set view: "map"
|
8
|
+
gp.set autoscale: "xfix"
|
9
|
+
gp.set autoscale: "yfix"
|
10
|
+
gp.set nokey: true
|
11
|
+
gp.set tic: "scale 0"
|
12
|
+
gp.set palette: "rgbformulae 22,13,10"
|
13
|
+
gp.unset xtics: true
|
14
|
+
gp.unset ytics: true
|
15
|
+
|
16
|
+
gp.add_dataset(matrix: :true, with: "image") do |plotter|
|
17
|
+
row = []
|
18
|
+
|
19
|
+
0.upto(400) do |i|
|
20
|
+
0.upto(600) do |j|
|
21
|
+
row[j] = i + j
|
22
|
+
end
|
23
|
+
|
24
|
+
plotter << row
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
gp.splot
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'gnuplotter'
|
4
|
+
|
5
|
+
data = [
|
6
|
+
["Dogs", 343],
|
7
|
+
["Fishes", 143],
|
8
|
+
["Cats", 123],
|
9
|
+
["Birds", 321],
|
10
|
+
["Bugs", 80],
|
11
|
+
["Cows", 200],
|
12
|
+
["Snakes", 140]
|
13
|
+
]
|
14
|
+
|
15
|
+
gp = GnuPlotter.new
|
16
|
+
gp.set terminal: "dumb"
|
17
|
+
gp.set title: "Animals"
|
18
|
+
gp.set xlabel: "Type"
|
19
|
+
gp.set ylabel: "Count"
|
20
|
+
gp.set yrange: "[0:*]"
|
21
|
+
gp.set autoscale: "xfix"
|
22
|
+
gp.set style: "fill solid 0.5 border"
|
23
|
+
gp.set xtics: "out"
|
24
|
+
gp.set ytics: "out"
|
25
|
+
gp.set xtics: "rotate" # Don't work with dumb terminal, try "png"
|
26
|
+
|
27
|
+
gp.add_dataset(using: "2:xticlabels(1)", with: "boxes notitle") do |plotter|
|
28
|
+
data.each { |d| plotter << d }
|
29
|
+
end
|
30
|
+
|
31
|
+
puts gp.plot
|
data/examples/lines.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'gnuplotter'
|
4
|
+
|
5
|
+
data1 = [
|
6
|
+
[0, 0, 0.5, 0.5],
|
7
|
+
[0, 1, -0.5, 0.5],
|
8
|
+
[1, 1, 1, 0]
|
9
|
+
]
|
10
|
+
|
11
|
+
data2 = [
|
12
|
+
[10, 10, 1.5, 1.5],
|
13
|
+
[10, 11, -1.5, 1.5],
|
14
|
+
[11, 11, 11, 10]
|
15
|
+
]
|
16
|
+
|
17
|
+
gp = GnuPlotter.new
|
18
|
+
|
19
|
+
gp.set title: "Foobar"
|
20
|
+
gp.set terminal: "dumb"
|
21
|
+
|
22
|
+
gp.add_dataset(using: "1:2:3:4", with: "vectors nohead", title: "'foo'") do |plotter|
|
23
|
+
data1.map { |d| plotter << d }
|
24
|
+
end
|
25
|
+
|
26
|
+
gp.add_dataset(using: "1:2:3:4", with: "vectors nohead", title: "'bar'") do |plotter|
|
27
|
+
data2.map { |d| plotter << d }
|
28
|
+
end
|
29
|
+
|
30
|
+
puts gp.plot
|
@@ -17,7 +17,5 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.rubygems_version = "2.0.0"
|
18
18
|
s.files = `git ls-files`.split("\n")
|
19
19
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
-
s.extra_rdoc_files = Dir["wiki/*.rdoc"]
|
22
20
|
s.require_paths = ["lib"]
|
23
21
|
end
|
data/lib/gnuplotter.rb
ADDED
@@ -0,0 +1,259 @@
|
|
1
|
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
|
2
|
+
# #
|
3
|
+
# Copyright (C) 2015 Martin Asser Hansen (mail@maasha.dk). #
|
4
|
+
# #
|
5
|
+
# This program is free software; you can redistribute it and/or #
|
6
|
+
# modify it under the terms of the GNU General Public License #
|
7
|
+
# as published by the Free Software Foundation; either version 2 #
|
8
|
+
# of the License, or (at your option) any later version. #
|
9
|
+
# #
|
10
|
+
# This program is distributed in the hope that it will be useful, #
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
13
|
+
# GNU General Public License for more details. #
|
14
|
+
# #
|
15
|
+
# You should have received a copy of the GNU General Public License #
|
16
|
+
# along with this program; if not, write to the Free Software #
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #
|
18
|
+
# #
|
19
|
+
# http://www.gnu.org/copyleft/gpl.html #
|
20
|
+
# #
|
21
|
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
|
22
|
+
|
23
|
+
require 'gnuplotter/version'
|
24
|
+
require 'tempfile'
|
25
|
+
require 'open3'
|
26
|
+
|
27
|
+
# Error class for all things Gnuplotter.
|
28
|
+
class GnuPlotterError < StandardError; end
|
29
|
+
|
30
|
+
class GnuPlotter
|
31
|
+
|
32
|
+
# Quotes around the values of the below keys are stripped.
|
33
|
+
NOQUOTE = [
|
34
|
+
:auto,
|
35
|
+
:autoscale,
|
36
|
+
:cbrange,
|
37
|
+
:border,
|
38
|
+
:boxwidth,
|
39
|
+
:datafile,
|
40
|
+
:grid,
|
41
|
+
:key,
|
42
|
+
:logscale,
|
43
|
+
:nocbtics,
|
44
|
+
:palette,
|
45
|
+
:rtics,
|
46
|
+
:terminal,
|
47
|
+
:tic,
|
48
|
+
:style,
|
49
|
+
:view,
|
50
|
+
:yrange,
|
51
|
+
:ytics,
|
52
|
+
:xrange,
|
53
|
+
:xtics,
|
54
|
+
:ztics
|
55
|
+
]
|
56
|
+
|
57
|
+
# Constructor method for a GnuPlot object.
|
58
|
+
def initialize
|
59
|
+
@options = Hash.new { |h1, k1| h1[k1] = Hash.new { |h2, k2| h2[k2] = [] } }
|
60
|
+
@datasets = []
|
61
|
+
end
|
62
|
+
|
63
|
+
# Method to set an option in the GnuPlot environment e.g:
|
64
|
+
# set(title: "Nobel Prize")
|
65
|
+
# set(grid: :true) # note no such thing as set(grid).
|
66
|
+
def set(options)
|
67
|
+
raise GnuPlotterError, "Non-hash options given" unless options.is_a? Hash
|
68
|
+
|
69
|
+
options.each do |key, value|
|
70
|
+
@options[:set][key.to_sym] << value
|
71
|
+
end
|
72
|
+
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
# Method to unset an option in the GnuPlot environment e.g:
|
77
|
+
# unset(ytics: true) # note no such thing as unset(ytics).
|
78
|
+
def unset(options)
|
79
|
+
raise GnuPlotterError, "Non-hash options given" unless options.is_a? Hash
|
80
|
+
|
81
|
+
options.each do |key, value|
|
82
|
+
@options[:unset][key.to_sym] << value || true
|
83
|
+
end
|
84
|
+
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
# Method that returns a GnuPlot script as a list of lines.
|
89
|
+
def to_gp(cmd = "plot")
|
90
|
+
if ! @datasets.empty?
|
91
|
+
data_lines = []
|
92
|
+
|
93
|
+
@datasets.each do |dataset|
|
94
|
+
data_lines.push(*dataset.format_data, "e")
|
95
|
+
end
|
96
|
+
|
97
|
+
plot_settings + [data_settings(cmd, true)] + data_lines
|
98
|
+
else
|
99
|
+
plot_settings
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Method to add a dataset to the current GnuPlot.
|
104
|
+
# add_dataset(using: "1:2:3:4", with: "vectors nohead", title: "'bar'") do |plotter|
|
105
|
+
# data.map { |d| plotter << d }
|
106
|
+
# end
|
107
|
+
def add_dataset(options = {})
|
108
|
+
raise GnuPlotterError, "No block given" unless block_given?
|
109
|
+
|
110
|
+
dataset = DataSet.new(options)
|
111
|
+
@datasets << dataset
|
112
|
+
|
113
|
+
yield dataset
|
114
|
+
end
|
115
|
+
|
116
|
+
# Method to execute the plotting of added datasets.
|
117
|
+
# Any plot data, i.e. dumb terminal, is returned.
|
118
|
+
def plot
|
119
|
+
gnuplot("plot")
|
120
|
+
end
|
121
|
+
|
122
|
+
# Method to execute the splotting of added datasets.
|
123
|
+
# Any plot data, i.e. dumb terminal, is returned.
|
124
|
+
def splot
|
125
|
+
gnuplot("splot")
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
# Method that calls gnuplot via open3 and performs the plotting.
|
131
|
+
# Any plot data, i.e. dumb terminal, is returned.
|
132
|
+
def gnuplot(method)
|
133
|
+
@datasets.each { |dataset| dataset.close }
|
134
|
+
|
135
|
+
result = nil
|
136
|
+
|
137
|
+
Open3.popen3("gnuplot -persist") do |stdin, stdout, stderr, wait_thr|
|
138
|
+
plot_settings.each { |line| stdin.puts line }
|
139
|
+
|
140
|
+
if @datasets.empty?
|
141
|
+
stdin.puts "#{method} 1/0"
|
142
|
+
else
|
143
|
+
stdin.puts data_settings(method)
|
144
|
+
end
|
145
|
+
|
146
|
+
stdin.close
|
147
|
+
result = stdout.read
|
148
|
+
stdout.close
|
149
|
+
|
150
|
+
exit_status = wait_thr.value
|
151
|
+
|
152
|
+
unless exit_status.success?
|
153
|
+
raise GnuPlotterError, stderr.read
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
@datasets.each { |dataset| dataset.delete }
|
158
|
+
|
159
|
+
result
|
160
|
+
end
|
161
|
+
|
162
|
+
# Returns a list of lines with the plot settings.
|
163
|
+
def plot_settings
|
164
|
+
lines = []
|
165
|
+
|
166
|
+
@options.each do |method, options|
|
167
|
+
options.each do |key, list|
|
168
|
+
list.each do |value|
|
169
|
+
if value == :true or value === true
|
170
|
+
lines << %Q{#{method} #{key}}
|
171
|
+
elsif NOQUOTE.include? key.to_sym
|
172
|
+
lines << %Q{#{method} #{key} #{value}}
|
173
|
+
else
|
174
|
+
lines << %Q{#{method} #{key} "#{value}"}
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
lines
|
181
|
+
end
|
182
|
+
|
183
|
+
# Returns one comma seperated line with plot settings for each dataset.
|
184
|
+
def data_settings(method, input = nil)
|
185
|
+
list = []
|
186
|
+
|
187
|
+
@datasets.each do |dataset|
|
188
|
+
list << dataset.format_options(input)
|
189
|
+
end
|
190
|
+
|
191
|
+
"#{method} " + list.join(", ")
|
192
|
+
end
|
193
|
+
|
194
|
+
# Nested class for GnuPlot datasets.
|
195
|
+
class DataSet
|
196
|
+
# Constructor for the DataSet object.
|
197
|
+
def initialize(options = {})
|
198
|
+
@options = options
|
199
|
+
@file = Tempfile.new("gp")
|
200
|
+
@io = @file.open
|
201
|
+
end
|
202
|
+
|
203
|
+
# Write method.
|
204
|
+
def <<(*obj)
|
205
|
+
@io.puts obj.join(" ")
|
206
|
+
end
|
207
|
+
|
208
|
+
alias :write :<<
|
209
|
+
|
210
|
+
# Method to close a DataSet temporary file io.
|
211
|
+
def close
|
212
|
+
@io.close unless @io.closed?
|
213
|
+
end
|
214
|
+
|
215
|
+
# Method to delete a DataSet temporary file.
|
216
|
+
def delete
|
217
|
+
@io.close unless @io.closed?
|
218
|
+
@file.unlink if File.exist? @file.path
|
219
|
+
end
|
220
|
+
|
221
|
+
# Method that builds a plot/splot command string from dataset options.
|
222
|
+
def format_options(input = nil)
|
223
|
+
options = []
|
224
|
+
|
225
|
+
if input
|
226
|
+
options << %Q{"-"}
|
227
|
+
else
|
228
|
+
options << %Q{"#{@file.path}"}
|
229
|
+
end
|
230
|
+
|
231
|
+
@options.each do |key, value|
|
232
|
+
if value == :true
|
233
|
+
options << "#{key}"
|
234
|
+
else
|
235
|
+
options << "#{key} #{value}"
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
options.join(" ")
|
240
|
+
end
|
241
|
+
|
242
|
+
# Method that returns data lines from file.
|
243
|
+
def format_data
|
244
|
+
lines = []
|
245
|
+
|
246
|
+
@io.close if @io.respond_to? :close
|
247
|
+
|
248
|
+
File.open(@file) do |ios|
|
249
|
+
ios.each do |line|
|
250
|
+
line.chomp!
|
251
|
+
|
252
|
+
lines << line
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
lines
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
data/lib/gnuplotter/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "
|
1
|
+
class GnuPlotter
|
2
|
+
VERSION = "1.0.0"
|
3
3
|
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
|
2
|
+
# #
|
3
|
+
# Copyright (C) 2007-2014 Martin Asser Hansen (mail@maasha.dk). #
|
4
|
+
# #
|
5
|
+
# This program is free software; you can redistribute it and/or #
|
6
|
+
# modify it under the terms of the GNU General Public License #
|
7
|
+
# as published by the Free Software Foundation; either version 2 #
|
8
|
+
# of the License, or (at your option) any later version. #
|
9
|
+
# #
|
10
|
+
# This program is distributed in the hope that it will be useful, #
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
13
|
+
# GNU General Public License for more details. #
|
14
|
+
# #
|
15
|
+
# You should have received a copy of the GNU General Public License #
|
16
|
+
# along with this program; if not, write to the Free Software #
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #
|
18
|
+
# #
|
19
|
+
# http://www.gnu.org/copyleft/gpl.html #
|
20
|
+
# #
|
21
|
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
|
22
|
+
# #
|
23
|
+
# This software is part of the Biopieces framework (www.biopieces.org). #
|
24
|
+
# #
|
25
|
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
|
26
|
+
|
27
|
+
require 'gnuplotter'
|
28
|
+
require 'test/unit'
|
29
|
+
|
30
|
+
module Kernel
|
31
|
+
def capture_stdout
|
32
|
+
out = StringIO.new
|
33
|
+
$stdout = out
|
34
|
+
yield
|
35
|
+
return out.string
|
36
|
+
ensure
|
37
|
+
$stdout = STDOUT
|
38
|
+
end
|
39
|
+
|
40
|
+
def capture_stderr
|
41
|
+
out = StringIO.new
|
42
|
+
$stderr = out
|
43
|
+
yield
|
44
|
+
return out.string
|
45
|
+
ensure
|
46
|
+
$stderr = STDERR
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Test::Unit::TestCase
|
51
|
+
def self.test(desc, &impl)
|
52
|
+
define_method("test #{desc}", &impl)
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
require 'test/helper'
|
5
|
+
|
6
|
+
class TestGnuPlotter < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@data1 = [
|
9
|
+
[0, 0, 0.5, 0.5],
|
10
|
+
[0, 1, -0.5, 0.5],
|
11
|
+
[1, 1, 1, 0]
|
12
|
+
]
|
13
|
+
|
14
|
+
@data2 = [
|
15
|
+
[10, 10, 1.5, 1.5],
|
16
|
+
[10, 11, -1.5, 1.5],
|
17
|
+
[11, 11, 11, 10]
|
18
|
+
]
|
19
|
+
|
20
|
+
@gp = GnuPlotter.new.set(title: "test").set(terminal: "dumb")
|
21
|
+
end
|
22
|
+
|
23
|
+
test "#to_gp with no settings returns empty array" do
|
24
|
+
assert_equal([], GnuPlotter.new.to_gp)
|
25
|
+
end
|
26
|
+
|
27
|
+
test "#set with non-hash options raises" do
|
28
|
+
assert_raise(GnuPlotterError) { GnuPlotter.new.set("title") }
|
29
|
+
end
|
30
|
+
|
31
|
+
test "#unset with non-hash options raises" do
|
32
|
+
assert_raise(GnuPlotterError) { GnuPlotter.new.set("title") }
|
33
|
+
end
|
34
|
+
|
35
|
+
test "#to_gp with set quoted and unquoted options returns correctly" do
|
36
|
+
gp = GnuPlotter.new.set(title: "test").set(terminal: "dumb")
|
37
|
+
assert_equal(['set title "test"', 'set terminal dumb'], gp.to_gp)
|
38
|
+
end
|
39
|
+
|
40
|
+
test "#to_gp with unset quoted and unquoted options returns correctly" do
|
41
|
+
gp = GnuPlotter.new.unset(title: true).unset(terminal: true)
|
42
|
+
assert_equal(['unset title', 'unset terminal'], gp.to_gp)
|
43
|
+
end
|
44
|
+
|
45
|
+
test "#add_dataset without block raises" do
|
46
|
+
assert_raise(GnuPlotterError) { @gp.add_dataset }
|
47
|
+
end
|
48
|
+
|
49
|
+
test "#to_gp with one dataset returns correctly" do
|
50
|
+
@gp.add_dataset(using: "1:2:3:4", with: "vectors nohead", title: "'foo'") do |plotter|
|
51
|
+
@data1.map { |d| plotter << d }
|
52
|
+
end
|
53
|
+
|
54
|
+
expected = [
|
55
|
+
'set title "test"',
|
56
|
+
'set terminal dumb',
|
57
|
+
'plot "-" using 1:2:3:4 with vectors nohead title \'foo\'',
|
58
|
+
'0 0 0.5 0.5',
|
59
|
+
'0 1 -0.5 0.5',
|
60
|
+
'1 1 1 0',
|
61
|
+
'e'
|
62
|
+
]
|
63
|
+
|
64
|
+
assert_equal(expected, @gp.to_gp)
|
65
|
+
end
|
66
|
+
|
67
|
+
test "#to_gp with two datasets returns correctly" do
|
68
|
+
@gp.add_dataset(using: "1:2:3:4", with: "vectors nohead", title: "'foo'") do |plotter|
|
69
|
+
@data1.map { |d| plotter << d }
|
70
|
+
end
|
71
|
+
|
72
|
+
@gp.add_dataset(using: "1:2:3:4", with: "vectors nohead", title: "'bar'") do |plotter|
|
73
|
+
@data2.map { |d| plotter << d }
|
74
|
+
end
|
75
|
+
|
76
|
+
expected = [
|
77
|
+
'set title "test"',
|
78
|
+
'set terminal dumb',
|
79
|
+
'plot "-" using 1:2:3:4 with vectors nohead title \'foo\', "-" using 1:2:3:4 with vectors nohead title \'bar\'',
|
80
|
+
'0 0 0.5 0.5',
|
81
|
+
'0 1 -0.5 0.5',
|
82
|
+
'1 1 1 0',
|
83
|
+
'e',
|
84
|
+
'10 10 1.5 1.5',
|
85
|
+
'10 11 -1.5 1.5',
|
86
|
+
'11 11 11 10',
|
87
|
+
'e'
|
88
|
+
]
|
89
|
+
|
90
|
+
assert_equal(expected, @gp.to_gp)
|
91
|
+
end
|
92
|
+
|
93
|
+
test "#plot produces something" do
|
94
|
+
@gp.add_dataset(using: "1:2:3:4", with: "vectors nohead", title: "'foo'") do |plotter|
|
95
|
+
@data1.map { |d| plotter << d }
|
96
|
+
end
|
97
|
+
|
98
|
+
assert_equal(String, @gp.plot.class)
|
99
|
+
end
|
100
|
+
|
101
|
+
test "#splot produces something" do
|
102
|
+
@gp.add_dataset(matrix: "with lines notitle") do |plotter|
|
103
|
+
@data1.map { |d| plotter << d }
|
104
|
+
end
|
105
|
+
|
106
|
+
assert_equal(String, @gp.splot.class)
|
107
|
+
end
|
108
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gnuplotter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin A. Hansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: GnuPlotter is a wrapper around gnuplot.
|
14
14
|
email: mail@maasha.dk
|
@@ -19,8 +19,15 @@ files:
|
|
19
19
|
- ".gitignore"
|
20
20
|
- LICENSE
|
21
21
|
- README.md
|
22
|
-
-
|
22
|
+
- Rakefile
|
23
|
+
- examples/heatmap.rb
|
24
|
+
- examples/histogram.rb
|
25
|
+
- examples/lines.rb
|
26
|
+
- gnuplotter.gemspec
|
27
|
+
- lib/gnuplotter.rb
|
23
28
|
- lib/gnuplotter/version.rb
|
29
|
+
- test/helper.rb
|
30
|
+
- test/test_gnuplotter.rb
|
24
31
|
homepage: http://github.com/maasha/gnuplotter
|
25
32
|
licenses:
|
26
33
|
- GPL2
|
@@ -45,4 +52,6 @@ rubygems_version: 2.4.5
|
|
45
52
|
signing_key:
|
46
53
|
specification_version: 4
|
47
54
|
summary: GnuPlotter
|
48
|
-
test_files:
|
55
|
+
test_files:
|
56
|
+
- test/helper.rb
|
57
|
+
- test/test_gnuplotter.rb
|