Class: GraphImageDrawerChunky
- Inherits:
-
Object
- Object
- GraphImageDrawerChunky
- Includes:
- GraphImageDrawerModule
- Defined in:
- lib/technical_graph/graph_image_drawer_chunky.rb
Instance Attribute Summary
Attributes included from GraphImageDrawerModule
Instance Method Summary collapse
-
#axis(x_array, y_array, _options = { :color => 'black', :width => 1 }, render_labels = false, x_labels = [], y_labels = []) ⇒ Object
Draw both array axis.
-
#axis_labels(parameter_label, value_label, _options = { :color => 'black', :width => 1, :size => 20 }) ⇒ Object
Label for parameters and values.
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#create_blank_image ⇒ Object
Initialize blank image.
- #legend(legend_data) ⇒ Object
- #render_data_layer(l, coords) ⇒ Object
-
#save(file) ⇒ Object
Save output to file.
-
#to_format(format) ⇒ Object
Export image.
Methods included from GraphImageDrawerModule
#deflate_string, #format_from_filename, #height, #initialize, #logger, #options, #random_filename, #to_png, #to_svg, #to_svgz, #truncate_string, #width, #x_axis, #y_axis
Instance Method Details
#axis(x_array, y_array, _options = { :color => 'black', :width => 1 }, render_labels = false, x_labels = [], y_labels = []) ⇒ Object
Draw both array axis
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/technical_graph/graph_image_drawer_chunky.rb', line 17 def axis(x_array, y_array, = { :color => 'black', :width => 1 }, render_labels = false, x_labels = [], y_labels = []) # for single axis x_array = [x_array] if not x_array.kind_of? Array y_array = [y_array] if not y_array.kind_of? Array x_array.each_with_index do |x, i| @image.line(x, 0, x, height, ChunkyPNG::Color.from_hex([:color])) # labels # chunky_png probably can't write text #label = x_labels[i] #if render_labels and not label.nil? # label = "#{truncate_string % label}" # plot_axis_text.text(x + 15, height - 15, label) #end end y_array.each_with_index do |y, i| @image.line(0, y, width, y, ChunkyPNG::Color.from_hex([:color])) # labels #label = y_labels[i] #if render_labels and not label.nil? # label = "#{truncate_string % label}" # plot_axis_text.text(15, y + 15, label) #end end end |
#axis_labels(parameter_label, value_label, _options = { :color => 'black', :width => 1, :size => 20 }) ⇒ Object
Label for parameters and values
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/technical_graph/graph_image_drawer_chunky.rb', line 49 def axis_labels(parameter_label, value_label, = { :color => 'black', :width => 1, :size => 20 }) # chunky_png probably can't write text #if options[:x_axis_label].to_s.size > 0 # plot = axis_labels_draw_object # plot.stroke(_options[:color]) # plot.stroke_width(_options[:width]) # # plot.text( # (width / 2).to_i, # height - 40, # options[:x_axis_label].to_s # ) # plot.draw(@image) #end # # #if options[:y_axis_label].to_s.size > 0 # plot = axis_labels_draw_object # plot.stroke(_options[:color]) # plot.stroke_width(_options[:width]) # plot = plot.rotate(90) # # plot.text( # (height / 2).to_i, # -40, # options[:y_axis_label].to_s # ) # plot.draw(@image) #end end |
#close ⇒ Object
131 132 133 134 |
# File 'lib/technical_graph/graph_image_drawer_chunky.rb', line 131 def close # only for compatibility @closed = true end |
#closed? ⇒ Boolean
136 137 138 |
# File 'lib/technical_graph/graph_image_drawer_chunky.rb', line 136 def closed? @closed end |
#create_blank_image ⇒ Object
Initialize blank image
12 13 14 |
# File 'lib/technical_graph/graph_image_drawer_chunky.rb', line 12 def create_blank_image @image = ChunkyPNG::Image.new(width, height, ChunkyPNG::Color::WHITE) end |
#legend(legend_data) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/technical_graph/graph_image_drawer_chunky.rb', line 109 def legend(legend_data) # chunky_png probably can't write text #legend_text_offset = (options[:legend_font_size] / 2.0).round - 4 # #legend_data.each do |l| # plot = axis_draw_object # plot_text = layer_no_stroke(plot) # # plot.fill(l[:color]) # plot.stroke(l[:color]) # plot_text.fill(l[:color]) # plot_text.pointsize(options[:legend_font_size]) # # plot.circle(l[:x], l[:y], l[:x] + 2, l[:y]) # plot_text.text(l[:x] + 5, l[:y] + legend_text_offset, l[:label]) # # plot.draw(@image) # plot_text.draw(@image) #end end |
#render_data_layer(l, coords) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/technical_graph/graph_image_drawer_chunky.rb', line 81 def render_data_layer(l, coords) # chunky_png probably can't write text ## value labels #if l.value_labels # plot = layer_no_stroke(layer_value_labels_draw_object(l)) # coords.each do |c| # string_label = "#{truncate_string % c[:dy]}" # plot.text( # c[:ax] + 5, c[:ay], # string_label # ) # end # plot.draw(@image) #end # lines and dots coords.each do |c| # additional circle #plot.circle(c[:ax], c[:ay], c[:ax] + 2, c[:ay]) #plot.circle(c[:bx], c[:by], c[:bx] + 2, c[:by]) # line @image.line(c[:ax], c[:ay], c[:bx], c[:by], ChunkyPNG::Color.from_hex(l.color)) end end |
#save(file) ⇒ Object
Save output to file
141 142 143 144 145 146 147 148 |
# File 'lib/technical_graph/graph_image_drawer_chunky.rb', line 141 def save(file) t = Time.now @image.save(file) logger.debug "saving image" logger.debug " TIME COST #{Time.now - t}" end |
#to_format(format) ⇒ Object
Export image
151 152 153 154 155 156 157 158 159 |
# File 'lib/technical_graph/graph_image_drawer_chunky.rb', line 151 def to_format(format) t = Time.now blob = @image.to_blob logger.debug "exporting image as string" logger.debug " TIME COST #{Time.now - t}" return blob end |