pill_chart 0.1.4 → 0.1.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.
- checksums.yaml +4 -4
- data/lib/pill_chart.rb +5 -1
- data/lib/pill_chart/railtie.rb +2 -10
- data/lib/pill_chart/simple_pill_chart.rb +95 -93
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e5ea7ba334f4e04bac991d069a5d6beddb641e5
|
4
|
+
data.tar.gz: 085fa73b70f03683b51e71f373c4fb1cd8659bb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32940adc45dee3b88ca0d5dce624d23daf6e8c186fb4a74d11650e8afdf5c788f8b3b7edd57fa42eb44166305014fed4cc5baca19b5cb905e1cd5b57037315cc
|
7
|
+
data.tar.gz: c9fdd31185bc5e556c546d9e02f84623c32945ed1e9e49f3bd0ee009455e8089d7d72840a50d878f6b9222376d53d6b0e930ebb57c1f5b06119663b2bf146c30
|
data/lib/pill_chart.rb
CHANGED
data/lib/pill_chart/railtie.rb
CHANGED
@@ -1,12 +1,4 @@
|
|
1
1
|
require "pill_chart/simple_pill_chart"
|
2
2
|
|
3
|
-
|
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
|
3
|
+
ActionView::Base.send :include, PillChart
|
4
|
+
ActionView::Base.send :include, PillChart::SimplePillChart
|
@@ -1,110 +1,112 @@
|
|
1
1
|
module PillChart
|
2
|
-
module SimplePillChart
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
def pill_chart_here
|
4
|
+
"Hey, i'm here !"
|
5
|
+
end
|
6
|
+
|
7
|
+
def draw_pill_chart(height: 10, width: 60, value: 33, max: 100, colors: {
|
8
|
+
"background" => "#eee",
|
9
|
+
"foreground" => "#999"})
|
10
|
+
elt = PillChart::SimplePillChart.new(height, width, value, max, colors)
|
11
|
+
elt.pill
|
12
|
+
end
|
13
|
+
|
14
|
+
class SimplePillChart
|
15
|
+
|
16
|
+
# constructor method
|
17
|
+
def initialize(height = 10, width = 60, value = 33, max = 100, colors = {})
|
18
|
+
@width, @height = width, height
|
19
|
+
@paths = []
|
20
|
+
@valueWidth = Integer((value * @width) / 100)
|
21
|
+
@config = {
|
22
|
+
"background" => "#eee",
|
23
|
+
"foreground" => "#999"
|
24
|
+
}
|
9
25
|
end
|
10
26
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
27
|
+
def pill
|
28
|
+
self.drawBackgroundPath
|
29
|
+
self.drawForegroundPath
|
30
|
+
self.toSvg
|
31
|
+
end
|
32
|
+
|
33
|
+
# define accessor methods
|
34
|
+
def getWidth
|
35
|
+
@width
|
36
|
+
end
|
37
|
+
|
38
|
+
def getHeight
|
39
|
+
@height
|
40
|
+
end
|
23
41
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
42
|
+
# define to_s method
|
43
|
+
def to_s
|
44
|
+
self.pill
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
|
49
|
+
def drawBackgroundPath
|
50
|
+
render = []
|
51
|
+
render << "<rect"
|
52
|
+
render << "id=\"background\" x=\"0\" cy=\"0\" height=\"20\" width=\"60\""
|
53
|
+
render << "style=\"fill: #{@config['background']}; mask: url(#pill-base)\""
|
54
|
+
render << "/>"
|
55
|
+
@paths.push([:background], render.join(" "))
|
28
56
|
end
|
29
57
|
|
30
|
-
|
31
|
-
|
32
|
-
|
58
|
+
|
59
|
+
# <rect id="background" x="0" cy="0" height="20" width="60" style="fill: red; mask: url(#pill-base)"/>
|
60
|
+
# <rect id="progress" x="0" cy="0" height="20" width="30" style="fill: green; mask: url(#pill-base)"/>
|
61
|
+
|
62
|
+
def drawForegroundPath
|
63
|
+
render = []
|
64
|
+
render << "<rect"
|
65
|
+
render << "id=\"foreground\" x=\"0\" cy=\"0\" height=\"20\" width=\"#{@valueWidth}\""
|
66
|
+
render << "style=\"fill: #{@config['foreground']}; mask: url(#pill-base)\""
|
67
|
+
render << "/>"
|
68
|
+
@paths.push([:foreground], render.join(" "))
|
33
69
|
end
|
34
70
|
|
35
|
-
|
36
|
-
|
71
|
+
|
72
|
+
# <mask id="pill-base" x="0" y="0" width="60" height="20" style="fill: #ffffff" >
|
73
|
+
# <circle cx="10" cy="10" r="10"/>
|
74
|
+
# <circle cx="50" cy="10" r="10"/>
|
75
|
+
# <rect x="10" cy="0" height="20" width="40"/>
|
76
|
+
# </mask>
|
77
|
+
|
78
|
+
def generateMask
|
79
|
+
ray = @height / 2
|
80
|
+
generated = []
|
81
|
+
generated << "<mask"
|
82
|
+
generated << "id=\"pill-base\""
|
83
|
+
generated << "x=\"0\" y=\"0\" width=\"#{@width}\" height=\"#{@height}\" style=\"fill: #ffffff\""
|
84
|
+
generated << ">"
|
85
|
+
generated << "<circle cx=\"#{ray}\" cy=\"#{ray}\" r=\"#{ray}\"/>"
|
86
|
+
generated << "<circle cx=\"#{@width - ray}\" cy=\"#{ray}\" r=\"#{ray}\"/>"
|
87
|
+
generated << "<rect"
|
88
|
+
generated << "x=\"#{ray}\" y=\"0\" width=\"#{@width - (2 * ray)}\" height=\"#{@height}\"/>"
|
89
|
+
generated << "</mask>"
|
90
|
+
"<defs>" + generated.join(" ") + "</defs>"
|
37
91
|
end
|
38
92
|
|
39
|
-
|
40
|
-
|
41
|
-
self.pill
|
93
|
+
def getSvgHeader
|
94
|
+
"<svg width=\"#{@width}\" height=\"#{@height}\">"
|
42
95
|
end
|
43
96
|
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
97
|
+
def getSvgFooter
|
98
|
+
'</svg>'
|
99
|
+
end
|
107
100
|
|
101
|
+
def toSvg
|
102
|
+
finalSvg = []
|
103
|
+
finalSvg.push self.getSvgHeader
|
104
|
+
finalSvg.push self.generateMask
|
105
|
+
finalSvg.push @paths.join("\n")
|
106
|
+
finalSvg.push self.getSvgFooter
|
107
|
+
finalSvg.join
|
108
|
+
end
|
108
109
|
end
|
110
|
+
|
109
111
|
end
|
110
112
|
|