plotrobber 0.0.7 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,26 +1,85 @@
1
1
  require 'plotrobber/version'
2
-
3
- require 'gnuplot'
4
2
  require 'tempfile'
5
3
 
6
- def plotting(&blk)
7
- IO.popen('gnuplot -preserve', 'w+') {|io| @@gp = io; blk[io] }
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
- @@gp.puts 'reset'
30
+ p = Plotrobber::PlotWrapper.new
12
31
 
13
- Gnuplot::Plot.new(@@gp) do |p|
14
- p.magic_terminal(filename) if filename
15
- p.instance_exec(p, &blk)
16
- end
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 Gnuplot::Plot
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
- arbitrary_lines << s
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
- self.data << Gnuplot::DataSet.new(name) do |ds|
90
- for arg in args
91
- if Hash === arg
92
- for k, v in arg
93
- ds.send("#{k}=", v)
94
- end
95
- else
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
@@ -1,3 +1,3 @@
1
1
  module Plotrobber
2
- VERSION = "0.0.7"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -16,6 +16,4 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
-
20
- gem.add_dependency('gnuplot')
21
19
  end
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.0.7
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-03-22 00:00:00.000000000 Z
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