simple_charts 0.0.5 → 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.
@@ -1,3 +1,3 @@
1
1
  module SimpleCharts
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
data/lib/simple_charts.rb CHANGED
@@ -3,16 +3,11 @@ require 'simple_charts/version'
3
3
  module SimpleCharts
4
4
  class Chart
5
5
 
6
- def calculate_pie_segments(data)
7
- total = data.inject(:+)
8
- data.map{ |val| 360 * val / total}
9
- end
10
-
11
6
  def create_pie_paths(data, opts)
12
7
 
13
8
  total = data.inject(:+)
14
9
  segments = data.map{ |val| 360 * val / total }
15
- centroid = opts[:width / 2]
10
+ centroid = opts[:width] / 2
16
11
  centroid_padding = 5
17
12
  radius = centroid - centroid_padding
18
13
 
@@ -23,28 +18,30 @@ module SimpleCharts
23
18
  start_angle = end_angle
24
19
  end_angle = start_angle + segment
25
20
 
26
- x1 = (centroid + (radius) * Math.cos(Math::PI * start_angle / 180)).round.to_s
27
- y1 = (centroid + (radius) * Math.sin(Math::PI * start_angle / 180)).round.to_s
28
- x2 = (centroid + (radius) * Math.cos(Math::PI * end_angle / 180)).round.to_s
29
- y2 = (centroid + (radius) * Math.sin(Math::PI * end_angle / 180)).round.to_s
21
+ x1 = (centroid + radius * Math.cos(Math::PI * start_angle / 180)).round.to_s
22
+ y1 = (centroid + radius * Math.sin(Math::PI * start_angle / 180)).round.to_s
23
+ x2 = (centroid + radius * Math.cos(Math::PI * end_angle / 180)).round.to_s
24
+ y2 = (centroid + radius * Math.sin(Math::PI * end_angle / 180)).round.to_s
30
25
 
31
- paths << 'M' + centroid + ',' + centroid + ' L' + x1 + ',' + y1 + ' A' + radius + ',' + radius + ' 0 ' + ((end_angle - start_angle > 180) ? '1' : '0') + ',1 ' + x2 + ',' + y2 + ' z'
26
+ paths << 'M' + centroid.to_s + ',' + centroid.to_s + ' L' + x1 + ',' + y1 + ' A' + radius.to_s + ',' + radius.to_s + ' 0 ' + ((end_angle - start_angle > 180) ? '1' : '0') + ',1 ' + x2 + ',' + y2 + ' z'
32
27
  end
33
28
 
34
29
  paths
35
30
  end
36
31
 
37
32
  def render(type, data, opts)
38
- paths = create_pie_paths(data, opts)
39
-
40
33
  svg = "<svg width='#{opts[:width]}' height='#{opts[:height]}' id='#{opts[:id]}' xmlns='http://www.w3.org/2000/svg'>"
41
34
 
42
- paths.each_with_index do |path, index|
43
- svg += "<path d='#{path}' id='#{opts[:id]}-path-#{index}'></path>"
35
+ case type
36
+ when 'pie'
37
+ create_pie_paths(data, opts).each_with_index do |path, index|
38
+ svg += "<path d='#{path}' id='#{opts[:id]}-path-#{index}'></path>"
39
+ end
40
+ else
41
+ # error
44
42
  end
45
43
 
46
44
  svg + '</svg>'
47
-
48
45
  end
49
46
 
50
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_charts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -69,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
69
  version: '0'
70
70
  segments:
71
71
  - 0
72
- hash: 2391248188697326366
72
+ hash: -3323566945862839880
73
73
  required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  version: '0'
79
79
  segments:
80
80
  - 0
81
- hash: 2391248188697326366
81
+ hash: -3323566945862839880
82
82
  requirements: []
83
83
  rubyforge_project:
84
84
  rubygems_version: 1.8.24