Module: GoogleChart::LineStyle

Included in:
LineChart
Defined in:
lib/google_chart/line_style.rb

Constant Summary collapse

@@styles =
{ :solid => [1,1,0], :dash => [1,3,2], :dot => [1,1,2] }
@@default_style =
:solid
@@default_width =
1

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
# File 'lib/google_chart/line_style.rb', line 4

def self.included(klass)
  klass.register!(:style)
end

Instance Method Details

#styleObject



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

def style
  @style ||= []
  @width ||= []
  
  # Pad @style and @width with defaults until they are equal in length
  (@style.size - @width.size).times { @width << @@default_width }
  (@width.size - @style.size).times { @style << @@default_style }
  
  unless @style.empty?
    'chls=' + (0...@style.size).map {|i|
      @@styles[@style[i]].map {|n| n * @width[i] }.join(',')
    }.join('|')
  end
end

#style=(style) ⇒ Object



13
14
15
# File 'lib/google_chart/line_style.rb', line 13

def style=(style)
  @style = [style].flatten
end

#width=(width) ⇒ Object



17
18
19
# File 'lib/google_chart/line_style.rb', line 17

def width=(width)
  @width = [width].flatten
end