pill_chart 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pill_chart.rb +1 -12
- data/lib/pill_chart/railtie.rb +12 -0
- data/lib/pill_chart/simple_pill_chart.rb +110 -0
- metadata +3 -2
- data/lib/simple/simple_pill_chart.rb +0 -99
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f03ab735066266ee3cabb18cce4c333f3adad0ab
|
4
|
+
data.tar.gz: f48f1ef652e58422e54fc237cc5bb0a48d46076e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a815e53a8c2027e395c5f028aff496b12e5057441b1ecba20279a5a3fdc9efe7bfdbef46c1d7561361815aae71ab296cd1dbf95d50ae3b5a084fb8d3bd47533b
|
7
|
+
data.tar.gz: f291e9f9fd57aee31ae1cc9ea71f15624cee68014a21baa49ddd9bfa40f579aea4988223f5650c15810431deeb1f2b1814472dc24f4365d96a4e070e1c2a451b
|
data/lib/pill_chart.rb
CHANGED
@@ -1,12 +1 @@
|
|
1
|
-
|
2
|
-
autoload :SimplePillChart, "simple/simple_pill_chart"
|
3
|
-
|
4
|
-
def PillChart.draw_pill_chart(height: 10, width: 60, value: 33, max: 100, colors: {
|
5
|
-
"background" => "#eee",
|
6
|
-
"foreground" => "#999"})
|
7
|
-
elt = SimplePillChart.new(height, width, value, max, colors)
|
8
|
-
elt.pill
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
ActionView::Base.send :include, PillChart if defined?(ActionView)
|
1
|
+
require 'pill_chart/railtie' if defined? Rails
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "pill_chart/simple_pill_chart"
|
2
|
+
|
3
|
+
require 'pill_chart/railtie' if defined? Rails
|
4
|
+
|
5
|
+
module PillChart
|
6
|
+
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
initializer "pill_chart.view_helpers" do |app|
|
9
|
+
ActionView::Base.send :include, SimplePillChart
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module PillChart
|
2
|
+
module SimplePillChart
|
3
|
+
|
4
|
+
def draw_pill_chart(height: 10, width: 60, value: 33, max: 100, colors: {
|
5
|
+
"background" => "#eee",
|
6
|
+
"foreground" => "#999"})
|
7
|
+
elt = PillChart::SimplePillChart::SimplePillChart.new(height, width, value, max, colors)
|
8
|
+
elt.pill
|
9
|
+
end
|
10
|
+
|
11
|
+
class SimplePillChart
|
12
|
+
|
13
|
+
# constructor method
|
14
|
+
def initialize(height = 10, width = 60, value = 33, max = 100, colors = {})
|
15
|
+
@width, @height = width, height
|
16
|
+
@paths = []
|
17
|
+
@valueWidth = Integer((value * @width) / 100)
|
18
|
+
@config = {
|
19
|
+
"background" => "#eee",
|
20
|
+
"foreground" => "#999"
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def pill
|
25
|
+
self.drawBackgroundPath
|
26
|
+
self.drawForegroundPath
|
27
|
+
self.toSvg
|
28
|
+
end
|
29
|
+
|
30
|
+
# define accessor methods
|
31
|
+
def getWidth
|
32
|
+
@width
|
33
|
+
end
|
34
|
+
|
35
|
+
def getHeight
|
36
|
+
@height
|
37
|
+
end
|
38
|
+
|
39
|
+
# define to_s method
|
40
|
+
def to_s
|
41
|
+
self.pill
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def drawBackgroundPath
|
47
|
+
render = []
|
48
|
+
render << "<rect"
|
49
|
+
render << "id=\"background\" x=\"0\" cy=\"0\" height=\"20\" width=\"60\""
|
50
|
+
render << "style=\"fill: #{@config['background']}; mask: url(#pill-base)\""
|
51
|
+
render << "/>"
|
52
|
+
@paths.push([:background], render.join(" "))
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# <rect id="background" x="0" cy="0" height="20" width="60" style="fill: red; mask: url(#pill-base)"/>
|
57
|
+
# <rect id="progress" x="0" cy="0" height="20" width="30" style="fill: green; mask: url(#pill-base)"/>
|
58
|
+
|
59
|
+
def drawForegroundPath
|
60
|
+
render = []
|
61
|
+
render << "<rect"
|
62
|
+
render << "id=\"foreground\" x=\"0\" cy=\"0\" height=\"20\" width=\"#{@valueWidth}\""
|
63
|
+
render << "style=\"fill: #{@config['foreground']}; mask: url(#pill-base)\""
|
64
|
+
render << "/>"
|
65
|
+
@paths.push([:foreground], render.join(" "))
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
# <mask id="pill-base" x="0" y="0" width="60" height="20" style="fill: #ffffff" >
|
70
|
+
# <circle cx="10" cy="10" r="10"/>
|
71
|
+
# <circle cx="50" cy="10" r="10"/>
|
72
|
+
# <rect x="10" cy="0" height="20" width="40"/>
|
73
|
+
# </mask>
|
74
|
+
|
75
|
+
def generateMask
|
76
|
+
ray = @height / 2
|
77
|
+
generated = []
|
78
|
+
generated << "<mask"
|
79
|
+
generated << "id=\"pill-base\""
|
80
|
+
generated << "x=\"0\" y=\"0\" width=\"#{@width}\" height=\"#{@height}\" style=\"fill: #ffffff\""
|
81
|
+
generated << ">"
|
82
|
+
generated << "<circle cx=\"#{ray}\" cy=\"#{ray}\" r=\"#{ray}\"/>"
|
83
|
+
generated << "<circle cx=\"#{@width - ray}\" cy=\"#{ray}\" r=\"#{ray}\"/>"
|
84
|
+
generated << "<rect"
|
85
|
+
generated << "x=\"#{ray}\" y=\"0\" width=\"#{@width - (2 * ray)}\" height=\"#{@height}\"/>"
|
86
|
+
generated << "</mask>"
|
87
|
+
"<defs>" + generated.join(" ") + "</defs>"
|
88
|
+
end
|
89
|
+
|
90
|
+
def getSvgHeader
|
91
|
+
"<svg width=\"#{@width}\" height=\"#{@height}\">"
|
92
|
+
end
|
93
|
+
|
94
|
+
def getSvgFooter
|
95
|
+
'</svg>'
|
96
|
+
end
|
97
|
+
|
98
|
+
def toSvg
|
99
|
+
finalSvg = []
|
100
|
+
finalSvg.push self.getSvgHeader
|
101
|
+
finalSvg.push self.generateMask
|
102
|
+
finalSvg.push @paths.join("\n")
|
103
|
+
finalSvg.push self.getSvgFooter
|
104
|
+
finalSvg.join
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pill_chart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- André Aubin
|
@@ -17,7 +17,8 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/pill_chart.rb
|
20
|
-
- lib/
|
20
|
+
- lib/pill_chart/railtie.rb
|
21
|
+
- lib/pill_chart/simple_pill_chart.rb
|
21
22
|
homepage: https://github.com/lambdaweb/pillchart
|
22
23
|
licenses:
|
23
24
|
- Apache2
|
@@ -1,99 +0,0 @@
|
|
1
|
-
module PillChart
|
2
|
-
class SimplePillChart
|
3
|
-
|
4
|
-
# constructor method
|
5
|
-
def initialize(height = 10, width = 60, value = 33, max = 100, colors = {})
|
6
|
-
@width, @height = width, height
|
7
|
-
@paths = []
|
8
|
-
@valueWidth = Integer((value * @width) / 100)
|
9
|
-
@config = {
|
10
|
-
"background" => "#eee",
|
11
|
-
"foreground" => "#999"
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
def pill
|
16
|
-
self.drawBackgroundPath
|
17
|
-
self.drawForegroundPath
|
18
|
-
self.toSvg
|
19
|
-
end
|
20
|
-
|
21
|
-
# define accessor methods
|
22
|
-
def getWidth
|
23
|
-
@width
|
24
|
-
end
|
25
|
-
|
26
|
-
def getHeight
|
27
|
-
@height
|
28
|
-
end
|
29
|
-
|
30
|
-
# define to_s method
|
31
|
-
def to_s
|
32
|
-
self.pill
|
33
|
-
end
|
34
|
-
|
35
|
-
protected
|
36
|
-
|
37
|
-
def drawBackgroundPath
|
38
|
-
render = []
|
39
|
-
render << "<rect"
|
40
|
-
render << "id=\"background\" x=\"0\" cy=\"0\" height=\"20\" width=\"60\""
|
41
|
-
render << "style=\"fill: #{@config['background']}; mask: url(#pill-base)\""
|
42
|
-
render << "/>"
|
43
|
-
@paths.push([:background], render.join(" "))
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
# <rect id="background" x="0" cy="0" height="20" width="60" style="fill: red; mask: url(#pill-base)"/>
|
48
|
-
# <rect id="progress" x="0" cy="0" height="20" width="30" style="fill: green; mask: url(#pill-base)"/>
|
49
|
-
|
50
|
-
def drawForegroundPath
|
51
|
-
render = []
|
52
|
-
render << "<rect"
|
53
|
-
render << "id=\"foreground\" x=\"0\" cy=\"0\" height=\"20\" width=\"#{@valueWidth}\""
|
54
|
-
render << "style=\"fill: #{@config['foreground']}; mask: url(#pill-base)\""
|
55
|
-
render << "/>"
|
56
|
-
@paths.push([:foreground], render.join(" "))
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
# <mask id="pill-base" x="0" y="0" width="60" height="20" style="fill: #ffffff" >
|
61
|
-
# <circle cx="10" cy="10" r="10"/>
|
62
|
-
# <circle cx="50" cy="10" r="10"/>
|
63
|
-
# <rect x="10" cy="0" height="20" width="40"/>
|
64
|
-
# </mask>
|
65
|
-
|
66
|
-
def generateMask
|
67
|
-
ray = @height / 2
|
68
|
-
generated = []
|
69
|
-
generated << "<mask"
|
70
|
-
generated << "id=\"pill-base\""
|
71
|
-
generated << "x=\"0\" y=\"0\" width=\"#{@width}\" height=\"#{@height}\" style=\"fill: #ffffff\""
|
72
|
-
generated << ">"
|
73
|
-
generated << "<circle cx=\"#{ray}\" cy=\"#{ray}\" r=\"#{ray}\"/>"
|
74
|
-
generated << "<circle cx=\"#{@width - ray}\" cy=\"#{ray}\" r=\"#{ray}\"/>"
|
75
|
-
generated << "<rect"
|
76
|
-
generated << "x=\"#{ray}\" y=\"0\" width=\"#{@width - (2 * ray)}\" height=\"#{@height}\"/>"
|
77
|
-
generated << "</mask>"
|
78
|
-
"<defs>" + generated.join(" ") + "</defs>"
|
79
|
-
end
|
80
|
-
|
81
|
-
def getSvgHeader
|
82
|
-
"<svg width=\"#{@width}\" height=\"#{@height}\">"
|
83
|
-
end
|
84
|
-
|
85
|
-
def getSvgFooter
|
86
|
-
'</svg>'
|
87
|
-
end
|
88
|
-
|
89
|
-
def toSvg
|
90
|
-
finalSvg = []
|
91
|
-
finalSvg.push self.getSvgHeader
|
92
|
-
finalSvg.push self.generateMask
|
93
|
-
finalSvg.push @paths.join("\n")
|
94
|
-
finalSvg.push self.getSvgFooter
|
95
|
-
finalSvg.join
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|