plotrobber 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Plotrobber
2
2
 
3
+ A prettier DSL for Gnuplot and Ruby.
4
+
3
5
  Don't write this:
4
6
 
5
7
  Gnuplot.open do |gp|
@@ -1,3 +1,3 @@
1
1
  module Plotrobber
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/plotrobber.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'plotrobber/version'
2
2
 
3
3
  require 'gnuplot'
4
+ require 'tempfile'
4
5
 
5
6
  def plotting(&blk)
6
7
  Gnuplot.open do |gp|
@@ -17,10 +18,47 @@ def plot(title = nil, &blk)
17
18
  end
18
19
 
19
20
  class Gnuplot::Plot
20
- def show(name, args = {})
21
+ def please(s)
22
+ arbitrary_lines << s
23
+ end
24
+
25
+ def candlesticks(name, extra_opts = {})
26
+ with_opt = case extra_opts[:with]
27
+ when Hash, Array then 'candlesticks ' + extra_opts[:with].to_a.join(' ')
28
+ when String then 'candlesticks ' + extra_opts[:with]
29
+ else 'candlesticks'
30
+ end
31
+
32
+ options = {using: '1:3:2:6:5', with: with_opt}.merge(extra_opts)
33
+
34
+ show name, options
35
+ end
36
+
37
+ def show(name, *args)
38
+ if Array === name
39
+ file = Tempfile.new(['plotrobber.','.dat'])
40
+ file.write name.map{|x|x.join("\t")}.join("\n")
41
+ file.close
42
+
43
+ @files ||= []
44
+ @files << file
45
+
46
+ name = file.path
47
+ end
48
+
49
+ unless name.start_with? "'"
50
+ name = "'#{name}'"
51
+ end
52
+
21
53
  self.data << Gnuplot::DataSet.new(name) do |ds|
22
- for k, v in args
23
- ds.send("#{k}=", v)
54
+ for arg in args
55
+ if Hash === arg
56
+ for k, v in arg
57
+ ds.send("#{k}=", v)
58
+ end
59
+ else
60
+ ds.send arg.to_s
61
+ end
24
62
  end
25
63
  end
26
64
  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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-09 00:00:00.000000000 Z
12
+ date: 2013-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gnuplot