igs_pie_chart 0.0.8 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/igs_pie_chart/pie_chart.rb +20 -33
- data/lib/igs_pie_chart.rb +4 -1
- data/templates/_script.html.erb +4 -0
- data/test/test_igs_pie_chart.rb +43 -0
- metadata +11 -17
@@ -12,48 +12,21 @@ class Igs::PieChart
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def script
|
15
|
-
|
16
|
-
default_attribution
|
17
|
-
|
18
|
-
path = File.expand_path("../../../templates/_script.html.erb", __FILE__)
|
19
|
-
output = ERB.new(File.read(path)).result(binding)
|
20
|
-
rescue Exception => e
|
21
|
-
STDERR.puts "Erro ao renderizar JavaScript! #{e}"
|
22
|
-
output = nil
|
23
|
-
end
|
24
|
-
return output
|
15
|
+
return eval_erb('script.html')
|
25
16
|
end
|
26
17
|
|
27
18
|
def style
|
28
|
-
|
29
|
-
default_attribution
|
30
|
-
|
31
|
-
path = File.expand_path("../../../templates/_style.css.erb", __FILE__)
|
32
|
-
output = ERB.new(File.read(path)).result(binding)
|
33
|
-
rescue Exception => e
|
34
|
-
STDERR.puts "Erro ao renderizar CSS! #{e}"
|
35
|
-
output = nil
|
36
|
-
end
|
37
|
-
return output
|
19
|
+
return eval_erb('style.css')
|
38
20
|
end
|
39
21
|
|
40
22
|
def labels
|
41
|
-
|
42
|
-
default_attribution
|
43
|
-
|
44
|
-
path = File.expand_path("../../../templates/_labels.html.erb", __FILE__)
|
45
|
-
output = ERB.new(File.read(path)).result(binding)
|
46
|
-
rescue Exception => e
|
47
|
-
STDERR.puts "Erro ao renderizar Labels! #{e}"
|
48
|
-
output = nil
|
49
|
-
end
|
50
|
-
return output
|
23
|
+
return eval_erb('labels.html')
|
51
24
|
end
|
52
25
|
|
53
26
|
def render
|
54
|
-
rendering =
|
27
|
+
rendering = "<style>\n"
|
55
28
|
rendering+= self.style
|
56
|
-
rendering+=
|
29
|
+
rendering+= "</style>\n"
|
57
30
|
rendering+= self.script
|
58
31
|
rendering+= self.labels
|
59
32
|
|
@@ -77,7 +50,21 @@ class Igs::PieChart
|
|
77
50
|
end
|
78
51
|
|
79
52
|
private
|
80
|
-
|
53
|
+
|
54
|
+
def eval_erb(partial)
|
55
|
+
begin
|
56
|
+
default_attributions
|
57
|
+
|
58
|
+
path = File.expand_path("../../../templates/_#{partial}.erb", __FILE__)
|
59
|
+
output = ERB.new(File.read(path)).result(binding)
|
60
|
+
rescue Exception => e
|
61
|
+
STDERR.puts "Erro ao renderizar '#{partial}'! #{e}"
|
62
|
+
output = nil
|
63
|
+
end
|
64
|
+
return output
|
65
|
+
end
|
66
|
+
|
67
|
+
def default_attributions
|
81
68
|
|
82
69
|
if @default_attribution == true
|
83
70
|
return
|
data/lib/igs_pie_chart.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
1
3
|
begin
|
2
4
|
mod = Required::Module::const_get "Igs"
|
3
5
|
#It exists
|
@@ -15,9 +17,10 @@ begin
|
|
15
17
|
rescue NameError
|
16
18
|
#TODO: change this to use a logging api
|
17
19
|
puts "Not a Rails application, nothing to do here!"
|
20
|
+
puts " . . "
|
21
|
+
puts " ____ \n\n"
|
18
22
|
end
|
19
23
|
|
20
|
-
#encoding: utf-8
|
21
24
|
require 'erb'
|
22
25
|
require 'igs_pie_chart/pie_chart'
|
23
26
|
|
data/templates/_script.html.erb
CHANGED
@@ -18,6 +18,10 @@ var arcs = vis.selectAll("g.arc")
|
|
18
18
|
.data(donut)
|
19
19
|
.enter().append("g")
|
20
20
|
.attr("class", "arc")
|
21
|
+
/*.attr("onmouseover","evt.target.setAttribute('opacity', '0.5');")
|
22
|
+
.attr("onmouseout","evt.target.setAttribute('opacity', '1');")*/
|
23
|
+
.attr("onmouseover","evt.target.setAttribute('opacity', '0.5');")
|
24
|
+
.attr("onmouseout","evt.target.setAttribute('opacity', '1');")
|
21
25
|
.attr("transform", "translate(" + outerRadius + "," + outerRadius + ")");
|
22
26
|
|
23
27
|
arcs.append("path")
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'igs_pie_chart'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
class IgsPieChartTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Igs
|
8
|
+
|
9
|
+
HTML_TEST_OUTPUT='test.output.html'
|
10
|
+
JS_TEST_OUTPUT='test.output.js'
|
11
|
+
|
12
|
+
def test_pie_chart_rendering
|
13
|
+
puts "Purging #{HTML_TEST_OUTPUT}..."+`rm #{HTML_TEST_OUTPUT}`
|
14
|
+
puts "Purging #{JS_TEST_OUTPUT}..."+`rm #{JS_TEST_OUTPUT}`
|
15
|
+
|
16
|
+
#these two lines does the trick!
|
17
|
+
pie = PieChart.new('My colorful chart',200,0.4,'body',{'one'=>1.1,'two'=>2.2,'tree'=>3.3,'five'=>5.5,'eight'=>8.8,'thirteen'=>13.13,'twenty_one'=>21.21,'thirty_four'=>34.34,'fifty_five'=>55.55,'eighty_nine'=>89.89,'a_hundread_forty_four'=>144.144})
|
18
|
+
@render = pie.render
|
19
|
+
|
20
|
+
assert_not_equal nil, @render
|
21
|
+
|
22
|
+
File.open('test.output.js', 'w') do |f|
|
23
|
+
f.write @render
|
24
|
+
end
|
25
|
+
|
26
|
+
path = File.expand_path("../../templates/test_pie_chart.html.erb", __FILE__)
|
27
|
+
html_render = ERB.new(File.read(path)).result(binding)
|
28
|
+
|
29
|
+
File.open(HTML_TEST_OUTPUT, 'w') do |f|
|
30
|
+
f.write html_render
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
`open #{HTML_TEST_OUTPUT}`
|
35
|
+
rescue Exception => e
|
36
|
+
puts "Ouch! #{e}"
|
37
|
+
end
|
38
|
+
|
39
|
+
`google-chrome #{HTML_TEST_OUTPUT}`
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: igs_pie_chart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: d3_rails
|
@@ -18,10 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
- - <
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: '3.0'
|
21
|
+
version: 3.0.6
|
25
22
|
type: :runtime
|
26
23
|
prerelease: false
|
27
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,13 +26,10 @@ dependencies:
|
|
29
26
|
requirements:
|
30
27
|
- - ! '>='
|
31
28
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
33
|
-
- - <
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: '3.0'
|
29
|
+
version: 3.0.6
|
36
30
|
description: Pie Chart is a gem for pizza making. It uses D3 (Data Driven Documents)
|
37
31
|
to aggregate the data and render the SVG awesomeness.
|
38
|
-
email:
|
32
|
+
email: lucasmartins@railsnapraia.com
|
39
33
|
executables: []
|
40
34
|
extensions: []
|
41
35
|
extra_rdoc_files: []
|
@@ -45,8 +39,10 @@ files:
|
|
45
39
|
- templates/_labels.html.erb
|
46
40
|
- templates/_script.html.erb
|
47
41
|
- templates/_style.css.erb
|
42
|
+
- test/test_igs_pie_chart.rb
|
48
43
|
homepage: https://github.com/lucasmartins/igs_pie_chart
|
49
|
-
licenses:
|
44
|
+
licenses:
|
45
|
+
- MIT
|
50
46
|
post_install_message:
|
51
47
|
rdoc_options: []
|
52
48
|
require_paths:
|
@@ -56,10 +52,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
52
|
requirements:
|
57
53
|
- - ! '>='
|
58
54
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
60
|
-
segments:
|
61
|
-
- 0
|
62
|
-
hash: 427138969806614625
|
55
|
+
version: 1.9.1
|
63
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
57
|
none: false
|
65
58
|
requirements:
|
@@ -72,4 +65,5 @@ rubygems_version: 1.8.23
|
|
72
65
|
signing_key:
|
73
66
|
specification_version: 3
|
74
67
|
summary: Pie Chart is a gem for pizza making.
|
75
|
-
test_files:
|
68
|
+
test_files:
|
69
|
+
- test/test_igs_pie_chart.rb
|