Class: OpenFlashChart::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/open_flash_chart/base.rb

Instance Method Summary (collapse)

Constructor Details

- (Base) initialize(args = {}) {|_self| ... }

Returns a new instance of Base

Yields:

  • (_self)

Yield Parameters:



4
5
6
7
8
9
10
11
# File 'lib/open_flash_chart/base.rb', line 4

def initialize(args={})
  # set all the instance variables we want
  # assuming something like this OpenFlashChart.new(:x_axis => 5, :y_axis => 10, :elements => ["one", "two"], ...)
  args.each do |k,v|
    self.instance_variable_set("@#{k}", v)
  end
  yield self if block_given?  # magic pen pattern
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method_name, *args, &blk)



107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/open_flash_chart/base.rb', line 107

def method_missing(method_name, *args, &blk)
  case method_name.to_s
  when /(.*)=/   # i.e., if it is something x_legend=
    # if the user wants to set an instance variable then let them
    # the other args (args[0]) are ignored since it is a set method
    self.instance_variable_set("@#{$1}", args[0])
  when /^set_(.*)/
    # backwards compatible ... the user can still use the same set_y_legend methods if they want
    self.instance_variable_set("@#{$1}", args[0])
  else
    # if the method/attribute is missing and it is not a set method then hmmmm better let the user know
    super
  end
end

Instance Method Details

- (Object) <<(e)



60
61
62
# File 'lib/open_flash_chart/base.rb', line 60

def <<(e)
  add_element e
end

- (Object) add_element(element)



55
56
57
58
# File 'lib/open_flash_chart/base.rb', line 55

def add_element(element)
  @elements ||= []
  @elements << element
end

- (Object) append_value(v)



69
70
71
72
# File 'lib/open_flash_chart/base.rb', line 69

def append_value(v)
  @values ||= []
  @values << v
end

- (Object) attach_to_right_y_axis



100
101
102
# File 'lib/open_flash_chart/base.rb', line 100

def attach_to_right_y_axis
  @axis = 'right'
end

- (Object) render Also known as: to_s

same as to_s but won't stack overflow ... use this instead of to_s



14
15
16
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
47
# File 'lib/open_flash_chart/base.rb', line 14

def render
  # need to return the following like this
  # 1) font_size as font-size 
  # 2) dot_size as dot-size
  # 3) outline_colour as outline-colour
  # 4) halo_size as halo-size
  # 5) start_angle as start-angle
  # 6) tick_height as tick-height
  # 7) grid_colour as grid-colour
  # 8) threed as 3d
  # 9) tick_length as tick-length
  # 10) visible_steps as visible-steps
  # 11) key_on_click as key-on-click
  # 12) barb_length as barb-length
  # 13) on_show as on-show
  # 14) negative_colour as negative-colour
  # 15) line_style as line-style
  # 16) on_click as on-click
  # 17) javascript_function_name as javascript-function-name
  # 18) pad_x to pad-x
  # 19) pad_y to pad-y
  # 20) align_x to align-x
  # 21) align_y to align-y
  # 22) dot_style to dot-style
  # 23) hollow_dot to hollow-dot
  # 24) default_dot_style to dot-style
  self.to_json2.tap do |output|
    output.gsub!("threed","3d")
    output.gsub!("default_dot_style","dot-style")
    %w(font_size dot_size outline_colour halo_size start_angle tick_height grid_colour tick_length no_labels label_colour gradient_fill fill_alpha on_click spoke_labels visible_steps key_on_click barb_length on_show negative_colour line_style javascript_function_name pad_x pad_y align_x align_y dot_style hollow_dot).each do |replace|
      output.gsub!(replace, replace.gsub("_", "-"))
    end
  end
end

- (Object) set_colours(colours, grid_colour)



84
85
86
87
# File 'lib/open_flash_chart/base.rb', line 84

def set_colours(colours, grid_colour)
  @colours     = colours
  @grid_colour = grid_colour
end

- (Object) set_key(text, size)



64
65
66
67
# File 'lib/open_flash_chart/base.rb', line 64

def set_key(text, size)
  @text      = text
  @font_size = size
end

- (Object) set_offset(v)



80
81
82
# File 'lib/open_flash_chart/base.rb', line 80

def set_offset(v)
  @offset = v ? true : false
end

- (Object) set_range(min, max, steps = 1)



74
75
76
77
78
# File 'lib/open_flash_chart/base.rb', line 74

def set_range(min,max,steps=1)
  @min   = min
  @max   = max
  @steps = steps
end

- (Object) set_tooltip(tip) Also known as: tooltip=



89
90
91
92
93
94
95
96
97
# File 'lib/open_flash_chart/base.rb', line 89

def set_tooltip(tip)
  if tip.is_a?(Tooltip)
    #we have a style for our chart's tooltips
    @tooltip = tip
  else
    # the user could just use set_tip(tip) or tip=(tip) to just set the text of the tooltip
    @tip = tip
  end
end

- (Object) to_json2



49
50
51
# File 'lib/open_flash_chart/base.rb', line 49

def to_json2
  self.instance_values.to_json
end