igs_pie_chart 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/igs_pie_chart.rb +42 -0
- data/templates/pie_chart.html.erb +55 -0
- metadata +69 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
class IgsPieChart
|
5
|
+
|
6
|
+
# data=[100,299,234,55]
|
7
|
+
def initialize(size,endomargin=0,target_element='body',data)
|
8
|
+
@size = size
|
9
|
+
@endomargin = endomargin
|
10
|
+
@data = data.values
|
11
|
+
@labels = data.keys
|
12
|
+
@target_element = target_element
|
13
|
+
end
|
14
|
+
|
15
|
+
def render
|
16
|
+
begin
|
17
|
+
path = File.expand_path("../../templates/pie_chart.html.erb", __FILE__)
|
18
|
+
rendering = ERB.new(File.read(path)).result(binding)
|
19
|
+
rescue Exception => e
|
20
|
+
STDERR.puts "Erro ao renderizar JavaScript! #{e}"
|
21
|
+
rendering = nil
|
22
|
+
end
|
23
|
+
return rendering
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
render
|
28
|
+
end
|
29
|
+
|
30
|
+
def data=(data)
|
31
|
+
@data=data
|
32
|
+
end
|
33
|
+
|
34
|
+
def width=(width)
|
35
|
+
@width = width
|
36
|
+
end
|
37
|
+
|
38
|
+
def height=(height)
|
39
|
+
@height = height
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
<%
|
2
|
+
#Default value attribution
|
3
|
+
dsize = 300
|
4
|
+
@width = dsize if @width == nil
|
5
|
+
@height = dsize if @height == nil
|
6
|
+
@endomargin = 0 if @endomargin == nil
|
7
|
+
@width = @height = @size if @size!=nil
|
8
|
+
|
9
|
+
if @data==nil
|
10
|
+
@data=[1,1,1]
|
11
|
+
end
|
12
|
+
|
13
|
+
if @endomargin >= 1
|
14
|
+
@endomargin = 0
|
15
|
+
puts "@endomargin deve ser menor que 1"
|
16
|
+
end
|
17
|
+
|
18
|
+
@endomargin = 0.3
|
19
|
+
|
20
|
+
%>
|
21
|
+
<script type="text/javascript">
|
22
|
+
|
23
|
+
var width = <%=@width%>,height = <%=@height%>,
|
24
|
+
outerRadius = Math.min(width, height) / 2,
|
25
|
+
innerRadius = outerRadius * <%= @endomargin%>,
|
26
|
+
data = <%=@data%>,
|
27
|
+
color = d3.scale.category20(),
|
28
|
+
donut = d3.layout.pie(),
|
29
|
+
arc = d3.svg.arc().innerRadius(innerRadius).outerRadius(outerRadius);
|
30
|
+
|
31
|
+
var vis = d3.select("<%=@target_element%>")
|
32
|
+
.append("svg")
|
33
|
+
.data([data])
|
34
|
+
.attr("width", width)
|
35
|
+
.attr("height", height);
|
36
|
+
|
37
|
+
var arcs = vis.selectAll("g.arc")
|
38
|
+
.data(donut)
|
39
|
+
.enter().append("g")
|
40
|
+
.attr("class", "arc")
|
41
|
+
.attr("transform", "translate(" + outerRadius + "," + outerRadius + ")");
|
42
|
+
|
43
|
+
arcs.append("path")
|
44
|
+
.attr("fill", function(d, i) { return color(i); })
|
45
|
+
.attr("d", arc);
|
46
|
+
|
47
|
+
arcs.append("text")
|
48
|
+
.attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; })
|
49
|
+
.attr("dy", ".35em")
|
50
|
+
.attr("class", "pie-chart-text-label")
|
51
|
+
.attr("text-anchor", "middle")
|
52
|
+
.attr("display", function(d) { return d.value > .15 ? null : "none"; })
|
53
|
+
.text(function(d, i) { return d.value.toFixed(2); });
|
54
|
+
|
55
|
+
</script>
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: igs_pie_chart
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lucas N. Martins
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: d3_rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.10'
|
22
|
+
- - <
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '3.0'
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.10'
|
33
|
+
- - <
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '3.0'
|
36
|
+
description: ! 'Pie Chart: uma GEM super cool pra gerar pizzas. Amplamente utilizado
|
37
|
+
pelas Camaras, Tribunais, e Palacios brasileiros e aclamado pela populacao.'
|
38
|
+
email: lucas.martins@innovit.com.br
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- lib/igs_pie_chart.rb
|
44
|
+
- templates/pie_chart.html.erb
|
45
|
+
homepage: http://gitlab.lan.innovit.com.br/igs_pie_chart/wikis/index
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.23
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: ! 'Pie Chart: uma GEM super cool pra gerar pizzas.'
|
69
|
+
test_files: []
|