Class: PieChart

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

Instance Method Summary collapse

Constructor Details

#initialize(group, value, params) ⇒ PieChart

  • group - a vector of String categories

  • value - a vector of Float numeric value

  • parms - an Hash whit parametrs value

Parms

This Hash contain parmas . List of key permitted .

  • :title - (default “A sample Graph”) Graph main title

  • :legend - (default false) Prints legend

  • :vertical - (default true) The orientation of the plot

  • :height - (default 1500) Graph height

  • :width - (default 800) Graph width

  • :file_name - (default sample.jpg) Graph File Name/Path to save plot. You can chose jpg or pdf

Examples

Class Usage:

categories = ["uman","elf","dwarfs"]
values = [1.0,2.0,3.0]
params = {"title" => "Popolation of middle heart","x_label"=>"Popolation","y_label"=>"greed"}
plot = PieChart.new(categories,values,params)
#To view
plot.view 
#to save
plot.save


35
36
37
38
39
# File 'lib/pie_chart/pie_chart.rb', line 35

def initialize(group,value,params)
	@group=check_grp(group)
	@value=check_val(value)
	@params=self.check_par(params)
end

Instance Method Details

#check_par(params) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pie_chart/pie_chart.rb', line 41

def check_par(params)
       	hash = Hash.new
	permitted = ["title","vertical","legend","width","height","file_name"]
       	keys = params.keys
       	keys.each{ |key|
               	 if permitted.include?(key)==false
                       	raise "Error : Permitted key are title,vertical,legend,width,height"
                	end
       	}
	
	if params["title"]==nil
               	hash["title"]="A sample Graph"
       	else
               	 hash["title"]=params["title"]
       	end

	if params["vertical"]==nil
               	hash["vertical"]=false
      		else
               	hash["vertical"]=params["vertical"]
       	end

 	if params["legend"]==nil
       	        hash["legend"]=false
     		else
               	hash["legend"]=params["legend"]
       	end

	if params["width"]==nil
               	hash["width"]=1500
       	else
               	hash["width"]=params["width"]
       	end

	if params["height"]==nil
               	hash["height"]=800
       	else
               	hash["height"]=params["height"]
       	end

       	if params["file_name"]==nil
               	hash["file_name"]="sample.jpg"
       	else
               	hash["file_name"]=params["file_name"]
      		end

	params_map = HashMap.new(hash)
       	return params_map
end

#getGroupObject



91
92
93
# File 'lib/pie_chart/pie_chart.rb', line 91

def getGroup
	@group
end

#getParamsObject



99
100
101
# File 'lib/pie_chart/pie_chart.rb', line 99

def getParams
        @params
end

#getValueObject



95
96
97
# File 'lib/pie_chart/pie_chart.rb', line 95

def getValue
	@value 
end

#saveObject



104
105
106
107
108
109
110
# File 'lib/pie_chart/pie_chart.rb', line 104

def save
	begin
       		a = Java::ComDomain::clocomics
      			a.save_pie(self.getGroup,self.getValue,self.getParams)
	rescue Exception => ex
	end
end

#viewObject



111
112
113
114
115
116
117
118
119
# File 'lib/pie_chart/pie_chart.rb', line 111

def view
	 begin
                       a = Java::ComDomain::clocomics
                       a.view_pie(self.getGroup,self.getValue,self.getParams)
               rescue Exception => ex
               end


end