svg_data_plotter_gem 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/svg_data_plotter/circle.rb +70 -0
- data/lib/svg_data_plotter/gauge.rb +73 -0
- data/lib/svg_data_plotter_gem.rb +4 -68
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2421de1c5ca6816577e69b8092319f8ae5fd7f0f
|
4
|
+
data.tar.gz: d7bf99429bc37ac2f773eb7817f92a83142dea99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a7011e7c7c3da35c756a8ac3af73d2a0bf26b6e78abe9303f0fa7f3140a7eae4e4aa38ec8110781168f737e3759f3a8a2d7a716522540b1700ac209d85aefe0
|
7
|
+
data.tar.gz: 919dfef0d00af2396686826a8d7ee673fd92eb6fe139fd016daa542a68dfacd8b92b468977773ffa9442d8f2d1937a138e48d9895a4b113eea149a58b7fcee41
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module SvgDataPlotterGem
|
2
|
+
class Circle
|
3
|
+
attr_reader :score, :total, :size
|
4
|
+
|
5
|
+
def initialize(options)
|
6
|
+
validation options, [:score, :total, :size]
|
7
|
+
|
8
|
+
@score = options[:score]
|
9
|
+
@total = options[:total]
|
10
|
+
@size = options[:size]
|
11
|
+
end
|
12
|
+
|
13
|
+
def percentage
|
14
|
+
(score / total.to_f) * 100
|
15
|
+
end
|
16
|
+
|
17
|
+
def center
|
18
|
+
size / 2.0
|
19
|
+
end
|
20
|
+
|
21
|
+
def radius
|
22
|
+
center - 5.0
|
23
|
+
end
|
24
|
+
|
25
|
+
def circumference
|
26
|
+
radius * 2 * Math::PI
|
27
|
+
end
|
28
|
+
|
29
|
+
def percentage_adj
|
30
|
+
(score / total.to_f) * circumference
|
31
|
+
end
|
32
|
+
|
33
|
+
def radians(degrees)
|
34
|
+
degrees * Math::PI / 180
|
35
|
+
end
|
36
|
+
|
37
|
+
def x_co_ord(angle)
|
38
|
+
rad = radians(angle)
|
39
|
+
x = radius * Math.cos(rad)
|
40
|
+
center + x
|
41
|
+
end
|
42
|
+
|
43
|
+
def y_co_ord(angle)
|
44
|
+
rad = radians(angle)
|
45
|
+
y = radius * Math.sin(rad)
|
46
|
+
center - y
|
47
|
+
end
|
48
|
+
|
49
|
+
def arc_start
|
50
|
+
"#{x_co_ord(90)} #{y_co_ord(90)}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def arc_end_rhs
|
54
|
+
"#{x_co_ord(270)} #{y_co_ord(270)}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def arc_end_lhs
|
58
|
+
"#{x_co_ord(90)} #{y_co_ord(90)}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def validation(options, params)
|
62
|
+
raise ArgumentError if options.empty?
|
63
|
+
|
64
|
+
params.each do |key|
|
65
|
+
raise ArgumentError unless options.has_key?(key)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module SvgDataPlotterGem
|
2
|
+
class Gauge
|
3
|
+
attr_reader :score, :total, :size
|
4
|
+
|
5
|
+
def initialize(options)
|
6
|
+
validation options, [:score, :total, :size]
|
7
|
+
|
8
|
+
@score = options[:score]
|
9
|
+
@total = options[:total]
|
10
|
+
@size = options[:size]
|
11
|
+
end
|
12
|
+
|
13
|
+
def height
|
14
|
+
(size / 2.0) + 15.0
|
15
|
+
end
|
16
|
+
|
17
|
+
def percentage
|
18
|
+
(score / total.to_f) * 100
|
19
|
+
end
|
20
|
+
|
21
|
+
def center
|
22
|
+
size / 2.0
|
23
|
+
end
|
24
|
+
|
25
|
+
def radius
|
26
|
+
center - 10.0
|
27
|
+
end
|
28
|
+
|
29
|
+
def semi_circle
|
30
|
+
radius * Math::PI
|
31
|
+
end
|
32
|
+
|
33
|
+
def percentage_adj
|
34
|
+
(score / total.to_f) * semi_circle
|
35
|
+
end
|
36
|
+
|
37
|
+
def offset
|
38
|
+
percentage_adj - semi_circle
|
39
|
+
end
|
40
|
+
|
41
|
+
def radians(degrees)
|
42
|
+
degrees * Math::PI / 180
|
43
|
+
end
|
44
|
+
|
45
|
+
def x_co_ord(angle)
|
46
|
+
rad = radians(angle)
|
47
|
+
x = radius * Math.cos(rad)
|
48
|
+
center + x
|
49
|
+
end
|
50
|
+
|
51
|
+
def y_co_ord(angle)
|
52
|
+
rad = radians(angle)
|
53
|
+
y = radius * Math.sin(rad)
|
54
|
+
center - y
|
55
|
+
end
|
56
|
+
|
57
|
+
def arc_start
|
58
|
+
"#{x_co_ord(0)} #{y_co_ord(0)}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def arc_end
|
62
|
+
"#{x_co_ord(180)} #{y_co_ord(180)}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def validation(options, params)
|
66
|
+
raise ArgumentError if options.empty?
|
67
|
+
|
68
|
+
params.each do |key|
|
69
|
+
raise ArgumentError unless options.has_key?(key)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/svg_data_plotter_gem.rb
CHANGED
@@ -1,70 +1,6 @@
|
|
1
1
|
module SvgDataPlotterGem
|
2
|
-
|
3
|
-
attr_reader :score, :total, :size
|
4
|
-
|
5
|
-
def initialize(options)
|
6
|
-
validation options, [:score, :total, :size]
|
7
|
-
|
8
|
-
@score = options[:score]
|
9
|
-
@total = options[:total]
|
10
|
-
@size = options[:size]
|
11
|
-
end
|
12
|
-
|
13
|
-
def percentage
|
14
|
-
(score / total.to_f) * 100
|
15
|
-
end
|
16
|
-
|
17
|
-
def center
|
18
|
-
size / 2.0
|
19
|
-
end
|
20
|
-
|
21
|
-
def radius
|
22
|
-
center - 5.0
|
23
|
-
end
|
24
|
-
|
25
|
-
def circumference
|
26
|
-
radius * 2 * Math::PI
|
27
|
-
end
|
28
|
-
|
29
|
-
def percentage_adj
|
30
|
-
(score / total.to_f) * circumference
|
31
|
-
end
|
32
|
-
|
33
|
-
def radians(degrees)
|
34
|
-
degrees * Math::PI / 180
|
35
|
-
end
|
36
|
-
|
37
|
-
def x_co_ord(angle)
|
38
|
-
rad = radians(angle)
|
39
|
-
x = radius * Math.cos(rad)
|
40
|
-
center + x
|
41
|
-
end
|
42
|
-
|
43
|
-
def y_co_ord(angle)
|
44
|
-
rad = radians(angle)
|
45
|
-
y = radius * Math.sin(rad)
|
46
|
-
center - y
|
47
|
-
end
|
48
|
-
|
49
|
-
def arc_start
|
50
|
-
"#{x_co_ord(90)} #{y_co_ord(90)}"
|
51
|
-
end
|
52
|
-
|
53
|
-
def arc_end_rhs
|
54
|
-
"#{x_co_ord(270)} #{y_co_ord(270)}"
|
55
|
-
end
|
56
|
-
|
57
|
-
def arc_end_lhs
|
58
|
-
"#{x_co_ord(90)} #{y_co_ord(90)}"
|
59
|
-
end
|
60
|
-
|
61
|
-
def validation(options, params)
|
62
|
-
raise ArgumentError if options.empty?
|
63
|
-
|
64
|
-
params.each do |key|
|
65
|
-
raise ArgumentError unless options.has_key?(key)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
2
|
+
VERSION = '0.0.4'
|
70
3
|
end
|
4
|
+
|
5
|
+
require 'svg_data_plotter/circle'
|
6
|
+
require 'svg_data_plotter/gauge'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svg_data_plotter_gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rhiana Heath
|
@@ -16,6 +16,8 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- lib/svg_data_plotter/circle.rb
|
20
|
+
- lib/svg_data_plotter/gauge.rb
|
19
21
|
- lib/svg_data_plotter_gem.rb
|
20
22
|
homepage: https://svg-graphs-on-rails.herokuapp.com/
|
21
23
|
licenses:
|