class TechnicalGraph
options parameters: :width - width of image :height - height of image :x_min, :x_max, :y_min, :y_max - default or fixed ranges :xy_behaviour:
-
:default - use them as default ranges
-
:fixed - ranges will not be changed during addition of layers
Attributes
axis[R]
data_processor[R]
image_drawer[R]
layers[R]
logger[R]
options[R]
Public Class Methods
new(options = { })
click to toggle source
# File lib/technical_graph.rb, line 23 def initialize(options = { }) @options = options @log_device = options[:log_device] || STDOUT @logger = Logger.new(@log_device) @logger.level = options[:log_level] || Logger::INFO @data_processor = GraphDataProcessor.new(self) @image_drawer = GraphImageDrawer.new(self) @axis = GraphAxis.new(self) @layers = Array.new end
Public Instance Methods
add_layer(data = [], options = { })
click to toggle source
Add new data layer to layer array
# File lib/technical_graph.rb, line 49 def add_layer(data = [], options = { }) t = Time.now @layers << DataLayer.new(data, options, self) logger.debug "layer added, size #{data.size}" logger.debug " TIME COST #{Time.now - t}" end
best_output_format()
click to toggle source
Best output image format, used for testing
# File lib/technical_graph.rb, line 39 def best_output_format if options[:drawer_class] == :rasem return 'svg' end if options[:drawer_class] == :rmagick return 'png' end end
pre_render(ext)
click to toggle source
You don't have to run this
# File lib/technical_graph.rb, line 90 def pre_render(ext) case ext when 'svg', 'svgz' then @options[:drawer_class] = :rasem render when 'png' then if gem_available?('rmagick') # rmagick is at the moment the best solution @options[:drawer_class] = :rmagick else @options[:drawer_class] = :chunky_png end render when 'jpeg', 'jpg', 'bmp', 'gif' then if rmagick_installed? @options[:drawer_class] = :rmagick render else raise Gem::LoadError end else raise ArgumentError end end
render()
click to toggle source
Create graph
# File lib/technical_graph.rb, line 57 def render @layers.each do |l| @data_processor.process_data_layer(l) end # recalculate ranges if needed @image = @image_drawer.crate_blank_graph_image # draw axis @axis.render_on_image(@image) # draw layers @layers.each do |l| # drawing @image_drawer.render_data_layer(l) end # draw legend @image_drawer.render_data_legend end
save_to_file(filename)
click to toggle source
Render and save graph to a file
# File lib/technical_graph.rb, line 77 def save_to_file(filename) ext = File.extname(filename).gsub(/^\./, '') pre_render(ext) @image_drawer.save_to_file(filename) end
to_format(ext)
click to toggle source
Render and return graph string
# File lib/technical_graph.rb, line 84 def to_format(ext) pre_render(ext) @image_drawer.to_format(ext) end