Class: TechnicalGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/technical_graph.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = { }) ⇒ TechnicalGraph

Returns a new instance of TechnicalGraph.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/technical_graph.rb', line 22

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

Instance Attribute Details

#axisObject (readonly)

Returns the value of attribute axis.



35
36
37
# File 'lib/technical_graph.rb', line 35

def axis
  @axis
end

#data_processorObject (readonly)

Returns the value of attribute data_processor.



35
36
37
# File 'lib/technical_graph.rb', line 35

def data_processor
  @data_processor
end

#image_drawerObject (readonly)

Returns the value of attribute image_drawer.



35
36
37
# File 'lib/technical_graph.rb', line 35

def image_drawer
  @image_drawer
end

#layersObject (readonly)

Returns the value of attribute layers.



35
36
37
# File 'lib/technical_graph.rb', line 35

def layers
  @layers
end

#loggerObject (readonly)

Returns the value of attribute logger.



35
36
37
# File 'lib/technical_graph.rb', line 35

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



35
36
37
# File 'lib/technical_graph.rb', line 35

def options
  @options
end

Instance Method Details

#add_layer(data = [], options = { }) ⇒ Object

Add new data layer to layer array



48
49
50
51
52
53
# File 'lib/technical_graph.rb', line 48

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_formatObject

Best output image format, used for testing



38
39
40
41
42
43
44
45
# File 'lib/technical_graph.rb', line 38

def best_output_format
  if options[:drawer_class] == :rasem
    return 'svg'
  end
  if options[:drawer_class] == :rmagick
    return 'png'
  end
end

#renderObject

Create graph



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/technical_graph.rb', line 56

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