Module: Viiite::Command::Plot::GnuplotUtils

Extended by:
GnuplotUtils
Included in:
GnuplotUtils
Defined in:
lib/viiite/command/plot/to_gnuplot.rb

Instance Method Summary collapse

Instance Method Details

#to_data(rel) ⇒ Object



36
37
38
# File 'lib/viiite/command/plot/to_gnuplot.rb', line 36

def to_data(rel)
  [rel.collect{|t| t[:x]}, rel.collect{|t| t[:y]}]
end

#to_dataset(tuple) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/viiite/command/plot/to_gnuplot.rb', line 39

def to_dataset(tuple)
  ds = Gnuplot::DataSet.new(to_data(tuple[:data]))
  tuple.each_pair do |k,v|
    next if k == :data
    ds.send(:"#{k}=", v) if ds.respond_to?(:"#{k}=")
  end
  ds
end

#to_plot(graph) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/viiite/command/plot/to_gnuplot.rb', line 47

def to_plot(graph)
  Gnuplot::Plot.new do |plot|
    graph.each_pair do |k,v|
      next if k == :series
      plot.set(k.id2name, v)
    end
    plot.data = graph[:series].collect{|d| to_dataset(d)}
  end
end

#to_plots(graphs, buffer = "") ⇒ Object



56
57
58
59
60
# File 'lib/viiite/command/plot/to_gnuplot.rb', line 56

def to_plots(graphs, buffer = "")
  graphs.each do |tuple|
    buffer << to_plot(tuple).to_gplot << "\n"
  end
end