Class: RubyCharts::Charts::BaseChart
- Inherits:
-
Object
- Object
- RubyCharts::Charts::BaseChart
- Defined in:
- lib/ruby_charts/charts/base_chart.rb
Constant Summary collapse
- COLORS =
[ [255, 107, 107], # Red [78, 205, 196], # Teal [69, 183, 209], # Blue [255, 160, 122], # Orange [154, 216, 200], # Mint [247, 220, 111], # Yellow [187, 143, 206], # Purple [133, 193, 226], # Light Blue [248, 184, 139], # Peach [170, 190, 198] # Gray ].freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #colors(*color_array) ⇒ Object
- #font(path) ⇒ Object
-
#initialize(data) ⇒ BaseChart
constructor
A new instance of BaseChart.
- #legend(position: :right) ⇒ Object
- #render ⇒ Object
- #save(filename) ⇒ Object
- #subtitle(text) ⇒ Object
- #title(text) ⇒ Object
Constructor Details
#initialize(data) ⇒ BaseChart
Returns a new instance of BaseChart.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby_charts/charts/base_chart.rb', line 23 def initialize(data) @data = data @options = { width: 1200, height: 700, title: 'Chart', subtitle: nil, colors: COLORS, padding: 80, font: Config.font(:regular), font_bold: Config.font(:bold) } end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
21 22 23 |
# File 'lib/ruby_charts/charts/base_chart.rb', line 21 def data @data end |
#options ⇒ Object
Returns the value of attribute options.
21 22 23 |
# File 'lib/ruby_charts/charts/base_chart.rb', line 21 def @options end |
Instance Method Details
#colors(*color_array) ⇒ Object
47 48 49 50 |
# File 'lib/ruby_charts/charts/base_chart.rb', line 47 def colors(*color_array) @options[:colors] = color_array.flatten self end |
#font(path) ⇒ Object
52 53 54 55 |
# File 'lib/ruby_charts/charts/base_chart.rb', line 52 def font(path) @options[:font] = path self end |
#legend(position: :right) ⇒ Object
57 58 59 60 |
# File 'lib/ruby_charts/charts/base_chart.rb', line 57 def legend(position: :right) @options[:legend] = position self end |
#render ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ruby_charts/charts/base_chart.rb', line 62 def render @img = GD::Image.new(@options[:width], @options[:height]) @img.fill([255, 255, 255]) draw_background draw_title draw_chart_content @img end |
#save(filename) ⇒ Object
73 74 75 76 77 |
# File 'lib/ruby_charts/charts/base_chart.rb', line 73 def save(filename) render.save(filename) puts "✓ Chart saved: #{filename}" filename end |
#subtitle(text) ⇒ Object
42 43 44 45 |
# File 'lib/ruby_charts/charts/base_chart.rb', line 42 def subtitle(text) @options[:subtitle] = text self end |
#title(text) ⇒ Object
37 38 39 40 |
# File 'lib/ruby_charts/charts/base_chart.rb', line 37 def title(text) @options[:title] = text self end |