Class: ActsAsDashboard::LineGraphWidget

Inherits:
Widget
  • Object
show all
Defined in:
lib/acts_as_dashboard/line_graph_widget.rb

Constant Summary collapse

@@default_height =
'200px'
@@default_width =
'400px'
@@default_x_axis =
:numbers

Instance Attribute Summary collapse

Attributes inherited from Widget

#block, #name, #title, #type, #update_interval

Instance Method Summary collapse

Methods inherited from Widget

#data

Constructor Details

#initialize(options = {}) ⇒ LineGraphWidget

Returns a new instance of LineGraphWidget.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/acts_as_dashboard/line_graph_widget.rb', line 12

def initialize(options = {})
  options.delete :type

  # Allow American spelling of the word "colours".
  if options[:line_colors]
    options[:line_colours] = options[:line_colors]
    options.delete :line_colors
  end

  self.type         = :line_graph
  self.height       = options[:height ] || @@default_height
  self.width        = options[:width  ] || @@default_width
  self.x_axis       = options[:x_axis ] || @@default_x_axis
  self.line_colours = options[:line_colours]  if options[:line_colours]

  super
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



7
8
9
# File 'lib/acts_as_dashboard/line_graph_widget.rb', line 7

def height
  @height
end

#line_coloursObject

Returns the value of attribute line_colours.



9
10
11
# File 'lib/acts_as_dashboard/line_graph_widget.rb', line 9

def line_colours
  @line_colours
end

#widthObject

Returns the value of attribute width.



8
9
10
# File 'lib/acts_as_dashboard/line_graph_widget.rb', line 8

def width
  @width
end

#x_axisObject

Returns the value of attribute x_axis.



10
11
12
# File 'lib/acts_as_dashboard/line_graph_widget.rb', line 10

def x_axis
  @x_axis
end

Instance Method Details

#attributesObject



65
66
67
68
69
70
71
72
# File 'lib/acts_as_dashboard/line_graph_widget.rb', line 65

def attributes
  super.merge({
    :height       => @height,
    :width        => @width,
    :line_colours => @line_colours,
    :x_axis       => @x_axis,
  })
end

#line_colorsObject

Allow American spelling of the word “colours”.



61
62
63
# File 'lib/acts_as_dashboard/line_graph_widget.rb', line 61

def line_colors
  line_colours
end

#line_colour=(line_colour) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
44
# File 'lib/acts_as_dashboard/line_graph_widget.rb', line 40

def line_colour=(line_colour)
  raise ArgumentError, 'The "line_colour" argument must be a String.' unless line_colour.is_a? String

  self.line_colours = [line_colour]
end