pill_chart 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f03ab735066266ee3cabb18cce4c333f3adad0ab
4
- data.tar.gz: f48f1ef652e58422e54fc237cc5bb0a48d46076e
3
+ metadata.gz: 9e5ea7ba334f4e04bac991d069a5d6beddb641e5
4
+ data.tar.gz: 085fa73b70f03683b51e71f373c4fb1cd8659bb4
5
5
  SHA512:
6
- metadata.gz: a815e53a8c2027e395c5f028aff496b12e5057441b1ecba20279a5a3fdc9efe7bfdbef46c1d7561361815aae71ab296cd1dbf95d50ae3b5a084fb8d3bd47533b
7
- data.tar.gz: f291e9f9fd57aee31ae1cc9ea71f15624cee68014a21baa49ddd9bfa40f579aea4988223f5650c15810431deeb1f2b1814472dc24f4365d96a4e070e1c2a451b
6
+ metadata.gz: 32940adc45dee3b88ca0d5dce624d23daf6e8c186fb4a74d11650e8afdf5c788f8b3b7edd57fa42eb44166305014fed4cc5baca19b5cb905e1cd5b57037315cc
7
+ data.tar.gz: c9fdd31185bc5e556c546d9e02f84623c32945ed1e9e49f3bd0ee009455e8089d7d72840a50d878f6b9222376d53d6b0e930ebb57c1f5b06119663b2bf146c30
data/lib/pill_chart.rb CHANGED
@@ -1 +1,5 @@
1
- require 'pill_chart/railtie' if defined? Rails
1
+ if defined? Rails
2
+ require 'pill_chart/railtie'
3
+ else
4
+ require 'pill_chart/simple_pill_chart'
5
+ end
@@ -1,12 +1,4 @@
1
1
  require "pill_chart/simple_pill_chart"
2
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
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
- 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
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
- 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
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
- def pill
25
- self.drawBackgroundPath
26
- self.drawForegroundPath
27
- self.toSvg
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
- # define accessor methods
31
- def getWidth
32
- @width
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
- def getHeight
36
- @height
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
- # define to_s method
40
- def to_s
41
- self.pill
93
+ def getSvgHeader
94
+ "<svg width=\"#{@width}\" height=\"#{@height}\">"
42
95
  end
43
96
 
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
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
 
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
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Aubin