plotrobber 0.0.7 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/plotrobber.rb +81 -19
- data/lib/plotrobber/version.rb +1 -1
- data/plotrobber.gemspec +0 -2
- metadata +3 -19
data/lib/plotrobber.rb
CHANGED
@@ -1,26 +1,85 @@
|
|
1
1
|
require 'plotrobber/version'
|
2
|
-
|
3
|
-
require 'gnuplot'
|
4
2
|
require 'tempfile'
|
5
3
|
|
6
|
-
def plotting(&blk)
|
7
|
-
|
4
|
+
def plotting(preserve=false, &blk)
|
5
|
+
if ENV['DEBUG']
|
6
|
+
@@gp = STDOUT
|
7
|
+
blk[STDOUT]
|
8
|
+
else
|
9
|
+
cmd = 'gnuplot'
|
10
|
+
cmd << ' -preserve' if preserve
|
11
|
+
|
12
|
+
IO.popen(cmd, 'w+') do |io|
|
13
|
+
@@gp = io
|
14
|
+
blk[io]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module Plotrobber
|
20
|
+
class PlotWrapper
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def before_each_plot(&blk)
|
25
|
+
Plotrobber::PlotWrapper.before_each = blk
|
8
26
|
end
|
9
27
|
|
28
|
+
|
10
29
|
def plot(filename=nil, &blk)
|
11
|
-
|
30
|
+
p = Plotrobber::PlotWrapper.new
|
12
31
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
32
|
+
p.magic_terminal(filename) if filename
|
33
|
+
|
34
|
+
p.instance_exec(&Plotrobber::PlotWrapper.before_each) if Plotrobber::PlotWrapper.before_each
|
35
|
+
|
36
|
+
p.instance_exec(p, &blk)
|
37
|
+
|
38
|
+
@@gp << p.to_s << "\nreset\n"
|
17
39
|
end
|
18
40
|
|
19
|
-
class
|
41
|
+
class Plotrobber::PlotWrapper
|
42
|
+
def self.before_each ; @before_each ; end
|
43
|
+
def self.before_each=(blk) ; @before_each = blk ; end
|
44
|
+
|
45
|
+
attr_accessor :commands, :functions
|
46
|
+
|
47
|
+
def initialize
|
48
|
+
@commands = []
|
49
|
+
@functions = []
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
@commands.map(&:to_s).join("\n") + "\nplot\\\n\t" + @functions.join(",\\\n\t")
|
54
|
+
end
|
55
|
+
|
20
56
|
def please(s)
|
21
|
-
|
57
|
+
@commands << s
|
58
|
+
end
|
59
|
+
|
60
|
+
def set(s)
|
61
|
+
please "set #{s}"
|
62
|
+
end
|
63
|
+
|
64
|
+
QUOTED = %w[title output xlabel ylabel]
|
65
|
+
def quote(k, v)
|
66
|
+
if QUOTED.include?(k.to_s) and v !~ /\A'.*'\z/
|
67
|
+
'"%s"' % v
|
68
|
+
else
|
69
|
+
v
|
70
|
+
end
|
22
71
|
end
|
23
72
|
|
73
|
+
|
74
|
+
for cmd in %w[terminal output xtics ytics xlabel ylabel xrange yrange style]
|
75
|
+
class_eval <<-EOS
|
76
|
+
def #{cmd}(s)
|
77
|
+
set "#{cmd} %s" % [quote('#{cmd}', s)]
|
78
|
+
end
|
79
|
+
EOS
|
80
|
+
end
|
81
|
+
|
82
|
+
|
24
83
|
def store(data)
|
25
84
|
(@store ||= {})[data] ||= begin
|
26
85
|
file = Tempfile.new(['plotrobber.','.dat'])
|
@@ -86,16 +145,19 @@ class Gnuplot::Plot
|
|
86
145
|
def show(what, *args)
|
87
146
|
name = source_name what
|
88
147
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
ds.send arg.to_s
|
148
|
+
output = [name]
|
149
|
+
|
150
|
+
for arg in args
|
151
|
+
if Hash === arg
|
152
|
+
for k, v in arg
|
153
|
+
output << k
|
154
|
+
output << quote(k, v) unless v === true
|
97
155
|
end
|
156
|
+
else
|
157
|
+
output << arg.to_s
|
98
158
|
end
|
99
159
|
end
|
160
|
+
|
161
|
+
@functions << output.join(' ')
|
100
162
|
end
|
101
163
|
end
|
data/lib/plotrobber/version.rb
CHANGED
data/plotrobber.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plotrobber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: gnuplot
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
12
|
+
date: 2013-04-20 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
30
14
|
description: gnuplot easier.
|
31
15
|
email:
|
32
16
|
- eli@fox-epste.in
|