simple_charts 0.0.3 → 0.0.5
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/simple_charts/version.rb +1 -1
- data/lib/simple_charts.rb +16 -9
- metadata +4 -4
data/lib/simple_charts.rb
CHANGED
@@ -8,27 +8,34 @@ module SimpleCharts
|
|
8
8
|
data.map{ |val| 360 * val / total}
|
9
9
|
end
|
10
10
|
|
11
|
-
def create_pie_paths(
|
11
|
+
def create_pie_paths(data, opts)
|
12
|
+
|
13
|
+
total = data.inject(:+)
|
14
|
+
segments = data.map{ |val| 360 * val / total }
|
15
|
+
centroid = opts[:width / 2]
|
16
|
+
centroid_padding = 5
|
17
|
+
radius = centroid - centroid_padding
|
18
|
+
|
12
19
|
end_angle = 0
|
13
20
|
paths = []
|
14
21
|
|
15
22
|
segments.each do |segment|
|
16
23
|
start_angle = end_angle
|
17
24
|
end_angle = start_angle + segment
|
18
|
-
x1 = (200 + 195 * Math.cos(Math::PI * start_angle / 180)).round.to_s
|
19
|
-
y1 = (200 + 195 * Math.sin(Math::PI * start_angle / 180)).round.to_s
|
20
|
-
x2 = (200 + 195 * Math.cos(Math::PI * end_angle / 180)).round.to_s
|
21
|
-
y2 = (200 + 195 * Math.sin(Math::PI * end_angle / 180)).round.to_s
|
22
25
|
|
23
|
-
|
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
|
24
30
|
|
31
|
+
paths << 'M' + centroid + ',' + centroid + ' L' + x1 + ',' + y1 + ' A' + radius + ',' + radius + ' 0 ' + ((end_angle - start_angle > 180) ? '1' : '0') + ',1 ' + x2 + ',' + y2 + ' z'
|
25
32
|
end
|
33
|
+
|
26
34
|
paths
|
27
35
|
end
|
28
36
|
|
29
|
-
def render(type, data, opts
|
30
|
-
|
31
|
-
paths = create_pie_paths(segments)
|
37
|
+
def render(type, data, opts)
|
38
|
+
paths = create_pie_paths(data, opts)
|
32
39
|
|
33
40
|
svg = "<svg width='#{opts[:width]}' height='#{opts[:height]}' id='#{opts[:id]}' xmlns='http://www.w3.org/2000/svg'>"
|
34
41
|
|
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.
|
4
|
+
version: 0.0.5
|
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-07-
|
12
|
+
date: 2013-07-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sqlite3
|
@@ -69,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
69
|
version: '0'
|
70
70
|
segments:
|
71
71
|
- 0
|
72
|
-
hash:
|
72
|
+
hash: 2391248188697326366
|
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:
|
81
|
+
hash: 2391248188697326366
|
82
82
|
requirements: []
|
83
83
|
rubyforge_project:
|
84
84
|
rubygems_version: 1.8.24
|