Class: Drawr::Base
- Inherits:
-
Object
- Object
- Drawr::Base
- Defined in:
- lib/drawr.rb
Instance Attribute Summary collapse
-
#div ⇒ Object
Returns the value of attribute div.
-
#hide_dots ⇒ Object
Returns the value of attribute hide_dots.
-
#labels ⇒ Object
A hash of names for the individual columns, where the key is the array index for the column this label represents.
-
#theme ⇒ Object
Returns the value of attribute theme.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #data(name, data_points = [], color = nil) ⇒ Object
-
#initialize(target_width = 800) ⇒ Base
constructor
A new instance of Base.
- #to_s ⇒ Object
- #write(file) ⇒ Object
- #write_to_div(div) ⇒ Object
Constructor Details
#initialize(target_width = 800) ⇒ Base
Returns a new instance of Base.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/drawr.rb', line 17 def initialize(target_width = 800) @data_points = {} @theme = { :background_color => '#dbdbdb', :color_scheme => 'red', :padding => 'left: 30, right: 0, top: 10, bottom: 30', } @extra_options = {} if target_width.is_a? String @width, @height = target_width.split(/x/, 2) else @width, @height = target_width, (target_width * (3.0/4.0)) end @div = 'plotr' end |
Instance Attribute Details
#div ⇒ Object
Returns the value of attribute div.
6 7 8 |
# File 'lib/drawr.rb', line 6 def div @div end |
#hide_dots ⇒ Object
Returns the value of attribute hide_dots.
5 6 7 |
# File 'lib/drawr.rb', line 5 def hide_dots @hide_dots end |
#labels ⇒ Object
A hash of names for the individual columns, where the key is the array index for the column this label represents.
11 12 13 |
# File 'lib/drawr.rb', line 11 def labels @labels end |
#theme ⇒ Object
Returns the value of attribute theme.
7 8 9 |
# File 'lib/drawr.rb', line 7 def theme @theme end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/drawr.rb', line 4 def title @title end |
Instance Method Details
#data(name, data_points = [], color = nil) ⇒ Object
13 14 15 |
# File 'lib/drawr.rb', line 13 def data(name, data_points = [], color = nil) @data_points[name] = data_points end |
#to_s ⇒ Object
40 41 42 43 44 45 |
# File 'lib/drawr.rb', line 40 def to_s <<END <div><canvas id="#{div}" height="#{@height.to_i}" width="#{@width.to_i}"></canvas></div> <script>#{dataset}\n#{}\n#{commands}</script> END end |
#write(file) ⇒ Object
38 |
# File 'lib/drawr.rb', line 38 def write(file); File.open(file, 'wb') { |f| f.write to_s }; end |
#write_to_div(div) ⇒ Object
33 34 35 36 |
# File 'lib/drawr.rb', line 33 def write_to_div(div) @div = div to_s end |