Class: TechnicalGraph
- Inherits:
-
Object
- Object
- TechnicalGraph
- 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
-
#axis ⇒ Object
readonly
Returns the value of attribute axis.
-
#data_processor ⇒ Object
readonly
Returns the value of attribute data_processor.
-
#image_drawer ⇒ Object
readonly
Returns the value of attribute image_drawer.
-
#layers ⇒ Object
readonly
Returns the value of attribute layers.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#add_layer(data = [], options = { }) ⇒ Object
Add new data layer to layer array.
-
#best_output_format ⇒ Object
Best output image format, used for testing.
-
#initialize(options = { }) ⇒ TechnicalGraph
constructor
A new instance of TechnicalGraph.
-
#render ⇒ Object
Create graph.
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 = @log_device = [:log_device] || STDOUT @logger = Logger.new(@log_device) @logger.level = [: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
#axis ⇒ Object (readonly)
Returns the value of attribute axis.
35 36 37 |
# File 'lib/technical_graph.rb', line 35 def axis @axis end |
#data_processor ⇒ Object (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_drawer ⇒ Object (readonly)
Returns the value of attribute image_drawer.
35 36 37 |
# File 'lib/technical_graph.rb', line 35 def image_drawer @image_drawer end |
#layers ⇒ Object (readonly)
Returns the value of attribute layers.
35 36 37 |
# File 'lib/technical_graph.rb', line 35 def layers @layers end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
35 36 37 |
# File 'lib/technical_graph.rb', line 35 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
35 36 37 |
# File 'lib/technical_graph.rb', line 35 def @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 = [], = { }) t = Time.now @layers << DataLayer.new(data, , self) logger.debug "layer added, size #{data.size}" logger.debug " TIME COST #{Time.now - t}" end |
#best_output_format ⇒ Object
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 [:drawer_class] == :rasem return 'svg' end if [:drawer_class] == :rmagick return 'png' end end |
#render ⇒ Object
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 |