igs_pie_chart 0.0.11 → 0.0.12

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/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ test.output.*
2
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - rbx-19mode
6
+
7
+ before_script: "sudo ntpdate -ub ntp.ubuntu.com pool.ntp.org; true"
8
+ script: "bundle exec rake test"
9
+
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'd3_rails', '>= 3.1.10'
data/Gemfile.lock ADDED
@@ -0,0 +1,58 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionpack (3.2.13)
5
+ activemodel (= 3.2.13)
6
+ activesupport (= 3.2.13)
7
+ builder (~> 3.0.0)
8
+ erubis (~> 2.7.0)
9
+ journey (~> 1.0.4)
10
+ rack (~> 1.4.5)
11
+ rack-cache (~> 1.2)
12
+ rack-test (~> 0.6.1)
13
+ sprockets (~> 2.2.1)
14
+ activemodel (3.2.13)
15
+ activesupport (= 3.2.13)
16
+ builder (~> 3.0.0)
17
+ activesupport (3.2.13)
18
+ i18n (= 0.6.1)
19
+ multi_json (~> 1.0)
20
+ builder (3.0.4)
21
+ d3_rails (3.1.10)
22
+ railties (>= 3.1.0)
23
+ erubis (2.7.0)
24
+ hike (1.2.3)
25
+ i18n (0.6.1)
26
+ journey (1.0.4)
27
+ json (1.8.0)
28
+ multi_json (1.7.6)
29
+ rack (1.4.5)
30
+ rack-cache (1.2)
31
+ rack (>= 0.4)
32
+ rack-ssl (1.3.3)
33
+ rack
34
+ rack-test (0.6.2)
35
+ rack (>= 1.0)
36
+ railties (3.2.13)
37
+ actionpack (= 3.2.13)
38
+ activesupport (= 3.2.13)
39
+ rack-ssl (~> 1.3.2)
40
+ rake (>= 0.8.7)
41
+ rdoc (~> 3.4)
42
+ thor (>= 0.14.6, < 2.0)
43
+ rake (10.0.4)
44
+ rdoc (3.12.2)
45
+ json (~> 1.4)
46
+ sprockets (2.2.2)
47
+ hike (~> 1.2)
48
+ multi_json (~> 1.0)
49
+ rack (~> 1.0)
50
+ tilt (~> 1.1, != 1.3.0)
51
+ thor (0.18.1)
52
+ tilt (1.4.1)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ d3_rails (>= 3.1.10)
data/LICENSE ADDED
@@ -0,0 +1,65 @@
1
+ <!DOCTYPE html>
2
+ <html id="home" lang="en">
3
+ <head>
4
+ <title>MIT License</title>
5
+ <meta charset=utf-8>
6
+ <meta name=viewport content="width=device-width, initial-scale=0.70;">
7
+ <!--
8
+ Welcome fellow open source developer. This project is here for you to
9
+ link to if you're like me and keep forgetting to include the
10
+ MIT-license.txt file.
11
+
12
+ Fork this project and send a pull request on:
13
+
14
+ https://github.com/remy/mit-license
15
+
16
+ By adding a new JSON file to the users directory, it will yield an
17
+ MIT License on a CNAME, for example:
18
+
19
+ { "copyright": "Remy Sharp, http://remysharp.com" }
20
+
21
+ Means visiting http://rem.mit-license.org/ shows "Remy Sharp" as the
22
+ copyright holder. Namespaces will be on a first come first serve basis,
23
+ and I'm open to folk joining the GitHub project.
24
+
25
+ For more options (including linking and license version targeting)
26
+ see the README in the github hosted project.
27
+
28
+ Hope you find this useful too!
29
+
30
+ - @rem
31
+
32
+ -->
33
+ <!-- for HTML5 el styling -->
34
+ <script>document.createElement('article');document.createElement('footer');</script>
35
+ <link rel="stylesheet" href="/themes/double-windsor.css">
36
+ </head>
37
+ <body>
38
+ <article>
39
+ <h1>The MIT License (MIT)</h1>
40
+ <p>Copyright © 2013 <a href="http://www.linkedin.com/in/martinslucas">Lucas N Martins</a></p>
41
+
42
+ <p>Permission is hereby granted, free of charge, to any person obtaining a copy
43
+ of this software and associated documentation files (the “Software”), to deal
44
+ in the Software without restriction, including without limitation the rights
45
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
46
+ copies of the Software, and to permit persons to whom the Software is
47
+ furnished to do so, subject to the following conditions:</p>
48
+
49
+ <p>The above copyright notice and this permission notice shall be included in
50
+ all copies or substantial portions of the Software.</p>
51
+
52
+ <p>THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
54
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
55
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
56
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
57
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
58
+ THE SOFTWARE.</p>
59
+ </article>
60
+ <footer>
61
+ <p><a href="https://github.com/remy/mit-license">Fork this project to create your own MIT license that you can always link to.</a></p>
62
+ </footer>
63
+ <script>var _gaq=[['_setAccount','UA-1656750-28'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)})(document,'script')</script>
64
+ </body>
65
+ </html>
data/README.md ADDED
@@ -0,0 +1,113 @@
1
+ IGS Pie Chart
2
+ =============
3
+
4
+ [![Code Climate](https://codeclimate.com/github/lucasmartins/igs_pie_chart.png)](https://codeclimate.com/github/lucasmartins/igs_pie_chart)
5
+ [![Build Status](https://secure.travis-ci.org/lucasmartins/igs_pie_chart.png?branch=master)](http://travis-ci.org/lucasmartins/igs_pie_chart) [![Dependency Status](https://gemnasium.com/lucasmartins/igs_pie_chart.png?travis)](https://gemnasium.com/lucasmartins/igs_pie_chart)
6
+
7
+
8
+ Pie Chart is a gem for pizza/donut (charts) making. It uses D3 (Data Driven Documents) to aggregate the data and render SVG awesomeness into an HTML element of your choosing.
9
+
10
+ Pie Chart is the first piece of the Innovative Graph Suite, different ways to visualize your data will be available in the near future.
11
+
12
+ Pie Chart is not production ready yet, although it works fine.
13
+
14
+ The RDoc is not available yet, but there are few files to peek and the [test](https://github.com/lucasmartins/igs_pie_chart/blob/master/test/test_igs_pie_chart.rb) shows how it works.
15
+
16
+
17
+ Requirements
18
+ ------------
19
+
20
+ ### Ruby and Rails
21
+
22
+ This gem is tested against the latest version of RoR, other versions are not our focus now.
23
+ Rails is not really needed, but apparently our main dependency 'd3_rails' requires you to install all Rails gems, we will work on that in the future.
24
+
25
+ ### D3 (Data Driven Documents)
26
+
27
+ This gem uses the awesomeness of [D3](https://github.com/mbostock/d3), a great way to work with data, and data visualization too. So, remember you need the D3 js file available.
28
+
29
+ ### SVG
30
+
31
+ The graphics generated to bring pies to life are based on SVG, all browsers should fully support SVG and its transitions but some do not, be aware of that.
32
+
33
+ Installation
34
+ ------------
35
+
36
+ IGS Pie Chart is distributed as a gem, which is how it should be used in your app.
37
+
38
+ Include the gem in your Gemfile:
39
+
40
+ ```ruby
41
+ gem "igs_pie_chart"
42
+ ```
43
+
44
+ Or, if you want to get the bleeding edge, you can get master from the main repository:
45
+
46
+ ```ruby
47
+ gem "igs_pie_chart", :git => "git://github.com/lucasmartins/igs_pie_chart.git"
48
+ ```
49
+
50
+ Usage (Rails)
51
+ -------------------
52
+
53
+ Add D3 to your Rails javascript manifest (application.js):
54
+
55
+ ```javascript
56
+ //= require d3
57
+ ```
58
+
59
+ Make your pie (controller):
60
+
61
+ ```ruby
62
+ @pie = Igs::PieChart.new('The Favorite Pizzas Chart',200,0.4,'body',{'Mussarela'=>25,'Brocolli'=>25,'Pepperoni'=>50})
63
+ ```
64
+
65
+ Savor it raw (view):
66
+
67
+ ```erb
68
+ <%= raw @pie.render %>
69
+ ```
70
+ Done!
71
+
72
+ You can also render specific parts of the @pie, like in:
73
+
74
+ ```ruby
75
+ <%= raw @pie.style #css %>
76
+ <%= raw @pie.script #javascript %>
77
+ <%= raw @pie.labels #ul+li %>
78
+ ```
79
+
80
+ Breakdown
81
+ ---------
82
+
83
+ ```ruby
84
+ Igs::PieChart.new(size,endomargin=0,target_element='body',data)
85
+ size => "Integer, Your X and Y measures"
86
+ endomargin => "Float, from 0 to 1, represents the internal margin, 0 for Pizza Pie, 0.5 for a nice Donut."
87
+ target_element => "String, the target HTML element where the chart will be rendered."
88
+ data => "Hash with the labels and floats which represents each slice of the Pizza/Donut."
89
+ ```
90
+
91
+ Contributors
92
+ -------
93
+
94
+ ![Innovit](http://innovit.com.br/logos_innovit/logo-curvas_180.png)
95
+
96
+ IGS Pie Chart was bootstrapped inside [Innovit LTDA](http://innovit.com.br)
97
+
98
+ Special thanks to [Andrik](https://github.com/andrik), for pushing the company to a more open perspective.
99
+
100
+ The names and logos for Innovit are trademarks of Innovit LTDA.
101
+
102
+ Contributing
103
+ ------------
104
+
105
+ This gem is in a very early stage.
106
+
107
+ If you'd like to contribute a feature or bugfix: Thanks! To make sure your
108
+ fix/feature has a high chance of being included, please post a new [GitHub Issue](http://github.com/lucasmartins/igs_pie_chart/issues)
109
+
110
+ License
111
+ -------
112
+
113
+ IGS Pie Chart is free software under the [MIT license](http://lucasmartins.mit-license.org).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ end
8
+
9
+ desc "Build Gem"
10
+ task :default => :build
@@ -0,0 +1,21 @@
1
+ #encoding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "igs_pie_chart/version"
4
+ require 'date'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'igs_pie_chart'
8
+ s.version = Igs::Pie::Version::STRING
9
+ s.required_ruby_version = '>= 1.9.1'
10
+ s.date = Date.today
11
+ s.summary = "Pie Chart is a gem for pizza making."
12
+ s.description = "#{s.summary} It uses D3 (Data Driven Documents) to aggregate the data and render the SVG awesomeness."
13
+ s.authors = ["Lucas N. Martins"]
14
+ s.email = 'lucasmartins@railsnapraia.com'
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.homepage = 'https://github.com/lucasmartins/igs_pie_chart'
18
+ s.license = 'MIT'
19
+ s.add_dependency 'd3_rails', '>= 3.1.10'
20
+ s.add_dependency 'i18n', '> 0.6.1'
21
+ end
data/lib/igs_pie_chart.rb CHANGED
@@ -22,7 +22,8 @@ rescue NameError
22
22
  end
23
23
 
24
24
  require 'erb'
25
- require 'igs_pie_chart/pie_chart'
25
+ require 'igs_pie_chart/chart'
26
+ require 'igs_pie_chart/version'
26
27
 
27
28
  unless "".respond_to? 'camelize'
28
29
  class String
@@ -0,0 +1,95 @@
1
+ module Igs
2
+ module Pie
3
+ class Chart
4
+ attr_reader :title,:size,:endomargin,:target_element,:data
5
+ # data=[100,299,234,55]
6
+ def initialize(title,size,endomargin=0,target_element='body',data)
7
+ @title = title
8
+ @size = size
9
+ @endomargin = endomargin
10
+ @data = data.values
11
+ @labels = data.keys
12
+ @target_element = target_element
13
+ @default_attribution=false
14
+ end
15
+
16
+ def script
17
+ return eval_erb('script.html')
18
+ end
19
+
20
+ def style
21
+ return eval_erb('style.css')
22
+ end
23
+
24
+ def labels
25
+ return eval_erb('labels.html')
26
+ end
27
+
28
+ def render
29
+ rendering = "<style>\n"
30
+ rendering+= self.style
31
+ rendering+= "</style>\n"
32
+ rendering+= self.script
33
+ rendering+= self.labels
34
+
35
+ return rendering
36
+ end
37
+
38
+ def to_s
39
+ render
40
+ end
41
+
42
+ def data=(data)
43
+ @data=data
44
+ end
45
+
46
+ def width=(width)
47
+ @width = width
48
+ end
49
+
50
+ def height=(height)
51
+ @height = height
52
+ end
53
+
54
+ private
55
+
56
+ def eval_erb(partial)
57
+ begin
58
+ default_attributions
59
+
60
+ path = File.expand_path("../../../templates/_#{partial}.erb", __FILE__)
61
+ output = ERB.new(File.read(path)).result(binding)
62
+ rescue Exception => e
63
+ STDERR.puts "Erro ao renderizar '#{partial}'! #{e}"
64
+ output = nil
65
+ end
66
+ return output
67
+ end
68
+
69
+ def default_attributions
70
+
71
+ if @default_attribution == true
72
+ return
73
+ end
74
+
75
+ @default_attribution=true
76
+ #Default value attribution
77
+ dsize = 300
78
+ @width = dsize if @width == nil
79
+ @height = dsize if @height == nil
80
+ @endomargin = 0 if @endomargin == nil
81
+ @width = @height = @size if @size!=nil
82
+
83
+ if @data==nil
84
+ @data=[1,1,1]
85
+ end
86
+
87
+ if @endomargin >= 1
88
+ @endomargin = 0
89
+ STDERR.puts "@endomargin must be less than 1"
90
+ end
91
+ end
92
+
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,10 @@
1
+ module Igs
2
+ module Pie
3
+ module Version
4
+ MAJOR = 0
5
+ MINOR = 0
6
+ PATCH = 12
7
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Innovative Graph Suite: Pie Chart</title>
5
+ <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
6
+ <style type="text/css">
7
+ body {
8
+ font: 10px sans-serif;
9
+ }
10
+ </style>
11
+ </head>
12
+ <body>
13
+
14
+ <%= @render %>
15
+
16
+ </body>
17
+ </html>
@@ -14,7 +14,7 @@ class IgsPieChartTest < Test::Unit::TestCase
14
14
  puts "Purging #{JS_TEST_OUTPUT}..."+`rm #{JS_TEST_OUTPUT}`
15
15
 
16
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})
17
+ pie = Pie::Chart.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
18
  @render = pie.render
19
19
 
20
20
  assert_not_equal nil, @render
@@ -36,8 +36,6 @@ class IgsPieChartTest < Test::Unit::TestCase
36
36
  puts "Ouch! #{e}"
37
37
  end
38
38
 
39
- `google-chrome #{HTML_TEST_OUTPUT}`
40
-
41
39
  end
42
40
 
43
41
  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.11
4
+ version: 0.0.12
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: 2013-02-21 00:00:00.000000000 Z
12
+ date: 2013-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: d3_rails
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 3.0.6
21
+ version: 3.1.10
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,23 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 3.0.6
29
+ version: 3.1.10
30
+ - !ruby/object:Gem::Dependency
31
+ name: i18n
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>'
36
+ - !ruby/object:Gem::Version
37
+ version: 0.6.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>'
44
+ - !ruby/object:Gem::Version
45
+ version: 0.6.1
30
46
  description: Pie Chart is a gem for pizza making. It uses D3 (Data Driven Documents)
31
47
  to aggregate the data and render the SVG awesomeness.
32
48
  email: lucasmartins@railsnapraia.com
@@ -34,11 +50,21 @@ executables: []
34
50
  extensions: []
35
51
  extra_rdoc_files: []
36
52
  files:
53
+ - .gitignore
54
+ - .travis.yml
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - igs_pie_chart.gemspec
37
61
  - lib/igs_pie_chart.rb
38
- - lib/igs_pie_chart/pie_chart.rb
62
+ - lib/igs_pie_chart/chart.rb
63
+ - lib/igs_pie_chart/version.rb
39
64
  - templates/_labels.html.erb
40
65
  - templates/_script.html.erb
41
66
  - templates/_style.css.erb
67
+ - templates/test_pie_chart.html.erb
42
68
  - test/test_igs_pie_chart.rb
43
69
  homepage: https://github.com/lucasmartins/igs_pie_chart
44
70
  licenses:
@@ -67,3 +93,4 @@ specification_version: 3
67
93
  summary: Pie Chart is a gem for pizza making.
68
94
  test_files:
69
95
  - test/test_igs_pie_chart.rb
96
+ has_rdoc:
@@ -1,91 +0,0 @@
1
- class Igs::PieChart
2
- attr_reader :title,:size,:endomargin,:target_element,:data
3
- # data=[100,299,234,55]
4
- def initialize(title,size,endomargin=0,target_element='body',data)
5
- @title = title
6
- @size = size
7
- @endomargin = endomargin
8
- @data = data.values
9
- @labels = data.keys
10
- @target_element = target_element
11
- @default_attribution=false
12
- end
13
-
14
- def script
15
- return eval_erb('script.html')
16
- end
17
-
18
- def style
19
- return eval_erb('style.css')
20
- end
21
-
22
- def labels
23
- return eval_erb('labels.html')
24
- end
25
-
26
- def render
27
- rendering = "<style>\n"
28
- rendering+= self.style
29
- rendering+= "</style>\n"
30
- rendering+= self.script
31
- rendering+= self.labels
32
-
33
- return rendering
34
- end
35
-
36
- def to_s
37
- render
38
- end
39
-
40
- def data=(data)
41
- @data=data
42
- end
43
-
44
- def width=(width)
45
- @width = width
46
- end
47
-
48
- def height=(height)
49
- @height = height
50
- end
51
-
52
- private
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
68
-
69
- if @default_attribution == true
70
- return
71
- end
72
-
73
- @default_attribution=true
74
- #Default value attribution
75
- dsize = 300
76
- @width = dsize if @width == nil
77
- @height = dsize if @height == nil
78
- @endomargin = 0 if @endomargin == nil
79
- @width = @height = @size if @size!=nil
80
-
81
- if @data==nil
82
- @data=[1,1,1]
83
- end
84
-
85
- if @endomargin >= 1
86
- @endomargin = 0
87
- STDERR.puts "@endomargin must be less than 1"
88
- end
89
- end
90
-
91
- end