Class: EvoSynth::Output::GruffExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/evosynth/output/exporter/gruff_exporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ GruffExporter

Returns a new instance of GruffExporter.



33
34
35
36
37
38
39
40
41
# File 'lib/evosynth/output/exporter/gruff_exporter.rb', line 33

def initialize(logger)
	begin
		require 'gruff'
	rescue
		puts "Could not require 'gruff' gem, please install with gem install gruff"
	end

	@logger = logger
end

Instance Method Details

#export(title, filename) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/evosynth/output/exporter/gruff_exporter.rb', line 43

def export(title, filename)
	x, ys = [], []
	data_sets = 0
	@logger.data.each_pair do |key, value|
		data_sets = value.size if value.size > data_sets
		x << key
		value.each_with_index do |y, index|
			ys[index] = [] if ys[index].nil?
			ys[index] << y
		end
	end

	g = Gruff::Line.new
	g.title = title

	data_sets.times { |set|	g.data(@logger.column_names[set], ys[set]) }

	labels = {}
	x.each_with_index { |gen, index| labels[index] = "#{gen}"}
	g.labels = labels

	g.write(filename)
end