pill_chart 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1c84bf7b74c7321af87b05481af8f282dca9a8d
4
- data.tar.gz: 6efba9bfd9256b6b5c4d54aca90428f099adf20a
3
+ metadata.gz: c061822a954d3dcc457d6ee90e0795ce5a542c76
4
+ data.tar.gz: 5e42a9ff3fd2c601b9f7cb2a30550b5be873d27a
5
5
  SHA512:
6
- metadata.gz: 3b94436f28050d4b3e6fa2edfef336fdbee7eacfa274c1046b60738cfdf8d93728d63b63ad551369859940608689358998b4c991f0ebf489adfe8a698c023c6c
7
- data.tar.gz: 12b8f5cf42d9a60a5aee08e06664eda0ce7139b06a7c3eb25794f238116a35279e6999f97b32f757b41b7f6287a03ebcee8dd78c3149fe5008d13737094909b5
6
+ metadata.gz: b9fb01566736261f094166010537cf6a296c30871845baa6b7a2c61edd85d33b3fb49414e2d2f85a5926644dbb72f9ea3b33ce4bd2745e5b5f09e63447c40241
7
+ data.tar.gz: ce1d7e005b274689eab049f88d39e45455d75ec74cd90c7b4d625dfe814354712ab40d075641105e28ba09f0985e770a0714b5081cc0518a7521a1c62cec7894
@@ -0,0 +1,99 @@
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
+
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Aubin
@@ -17,6 +17,7 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/pill_chart.rb
20
+ - lib/simple/simple_pill_chart.rb
20
21
  homepage: https://github.com/lambdaweb/pillchart
21
22
  licenses:
22
23
  - Apache2