Class: Igs::PieChart

Inherits:
Object
  • Object
show all
Defined in:
lib/igs_pie_chart/pie_chart.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, size, endomargin = 0, target_element = 'body', data) ⇒ PieChart



4
5
6
7
8
9
10
11
12
# File 'lib/igs_pie_chart/pie_chart.rb', line 4

def initialize(title,size,endomargin=0,target_element='body',data)
  @title = title
  @size = size
  @endomargin = endomargin
  @data = data.values
  @labels = data.keys
  @target_element = target_element
  @default_attribution=false
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



2
3
4
# File 'lib/igs_pie_chart/pie_chart.rb', line 2

def data
  @data
end

#endomarginObject (readonly)

Returns the value of attribute endomargin.



2
3
4
# File 'lib/igs_pie_chart/pie_chart.rb', line 2

def endomargin
  @endomargin
end

#sizeObject (readonly)

Returns the value of attribute size.



2
3
4
# File 'lib/igs_pie_chart/pie_chart.rb', line 2

def size
  @size
end

#target_elementObject (readonly)

Returns the value of attribute target_element.



2
3
4
# File 'lib/igs_pie_chart/pie_chart.rb', line 2

def target_element
  @target_element
end

#titleObject (readonly)

Returns the value of attribute title.



2
3
4
# File 'lib/igs_pie_chart/pie_chart.rb', line 2

def title
  @title
end

Instance Method Details

#height=(height) ⇒ Object



75
76
77
# File 'lib/igs_pie_chart/pie_chart.rb', line 75

def height=(height)
  @height = height
end

#labelsObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/igs_pie_chart/pie_chart.rb', line 40

def labels
  begin
    default_attribution

    path = File.expand_path("../../../templates/_labels.html.erb", __FILE__)  
    output = ERB.new(File.read(path)).result(binding)
  rescue Exception => e
    STDERR.puts "Erro ao renderizar Labels! #{e}"
    output = nil
  end
  return output
end

#renderObject



53
54
55
56
57
58
59
60
61
# File 'lib/igs_pie_chart/pie_chart.rb', line 53

def render
  rendering = '<style>'
  rendering+= self.style
  rendering+= '</style>'
  rendering+= self.script
  rendering+= self.labels
  
  return rendering
end

#scriptObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/igs_pie_chart/pie_chart.rb', line 14

def script
  begin
    default_attribution

    path = File.expand_path("../../../templates/_script.html.erb", __FILE__)  
    output = ERB.new(File.read(path)).result(binding)
  rescue Exception => e
    STDERR.puts "Erro ao renderizar JavaScript! #{e}"
    output = nil
  end
  return output
end

#styleObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/igs_pie_chart/pie_chart.rb', line 27

def style
  begin
    default_attribution

    path = File.expand_path("../../../templates/_style.css.erb", __FILE__)  
    output = ERB.new(File.read(path)).result(binding)
  rescue Exception => e
    STDERR.puts "Erro ao renderizar CSS! #{e}"
    output = nil
  end
  return output
end

#to_sObject



63
64
65
# File 'lib/igs_pie_chart/pie_chart.rb', line 63

def to_s
  render
end

#width=(width) ⇒ Object



71
72
73
# File 'lib/igs_pie_chart/pie_chart.rb', line 71

def width=(width)
  @width = width
end