pill_chart 0.1.6 → 1.0.0
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/simple_pill_chart.rb +42 -11
- 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: ff53e9a4fdf5e64b598c496c508b36d0244623ff
|
4
|
+
data.tar.gz: c4e1da88510ff654b8849e056dbc5c67a607a882
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86e652bde2be5c0c1c7e6c28d2c25b1ab1e52f2c1d3d63eab8992a031e6a6ef45d9c318a0a10926bb860a0baf783d43afe886ea2d02c414054239f832a00fea9
|
7
|
+
data.tar.gz: 21fa4f7a0cc505e278ca50dc59c591f07b4c16f9794ea4a2cd7692d927ab70a2377443261135a21ed33e8bb4cf4e90d9f45af3f689eb5b93ca732e73d619edf0
|
@@ -1,32 +1,45 @@
|
|
1
1
|
module PillChart
|
2
2
|
|
3
|
-
def
|
4
|
-
|
3
|
+
def draw_pill_chart(height: 10, width: 60, value: 33, max: 100, colors: {})
|
4
|
+
elt = PillChart::SimplePillChart.new(height, width, value,
|
5
|
+
max, :simple, colors)
|
6
|
+
elt.pill
|
5
7
|
end
|
6
8
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def draw_state_pill_chart(height: 10, width: 60,
|
10
|
+
value: 33, max: 100, colors: {})
|
11
|
+
elt = PillChart::SimplePillChart.new(height, width, value,
|
12
|
+
max, :state, colors)
|
11
13
|
elt.pill
|
12
14
|
end
|
13
15
|
|
14
16
|
class SimplePillChart
|
15
17
|
|
16
18
|
# constructor method
|
17
|
-
def initialize(height = 10, width = 60, value = 33,
|
19
|
+
def initialize(height = 10, width = 60, value = 33,
|
20
|
+
max = 100, type = :simple, colors = {})
|
18
21
|
@width, @height = width, height
|
19
22
|
@paths = []
|
23
|
+
@type = type
|
20
24
|
@valueWidth = Integer((value * @width) / 100)
|
21
|
-
|
25
|
+
baseConfig = {
|
22
26
|
"background" => "#eee",
|
23
|
-
"foreground" => "#999"
|
27
|
+
"foreground" => "#999",
|
28
|
+
"low" => "#AD6D6D",
|
29
|
+
"medium" => "#C59663",
|
30
|
+
"high" => "#ADC563",
|
31
|
+
"full" => "#92C447"
|
24
32
|
}
|
33
|
+
@config = baseConfig.merge(colors)
|
25
34
|
end
|
26
35
|
|
27
36
|
def pill
|
28
37
|
self.drawBackgroundPath
|
29
|
-
|
38
|
+
if @type == :simple
|
39
|
+
self.drawSimpleForegroundPath
|
40
|
+
elsif @type == :state
|
41
|
+
self.drawStateForegroundPath
|
42
|
+
end
|
30
43
|
self.toSvg
|
31
44
|
end
|
32
45
|
|
@@ -59,7 +72,7 @@ module PillChart
|
|
59
72
|
# <rect id="background" x="0" cy="0" height="20" width="60" style="fill: red; mask: url(#pill-base)"/>
|
60
73
|
# <rect id="progress" x="0" cy="0" height="20" width="30" style="fill: green; mask: url(#pill-base)"/>
|
61
74
|
|
62
|
-
def
|
75
|
+
def drawSimpleForegroundPath
|
63
76
|
render = []
|
64
77
|
render << "<rect"
|
65
78
|
render << "id=\"foreground\" x=\"0\" cy=\"0\" height=\"20\" width=\"#{@valueWidth}\""
|
@@ -68,6 +81,24 @@ module PillChart
|
|
68
81
|
@paths.push([:foreground], render.join(" "))
|
69
82
|
end
|
70
83
|
|
84
|
+
def drawStateForegroundPath
|
85
|
+
if @valueWidth < 20
|
86
|
+
barColor = @config["low"]
|
87
|
+
elsif @valueWidth < 50
|
88
|
+
barColor = @config["medium"]
|
89
|
+
elsif @valueWidth < 80
|
90
|
+
barColor = @config["high"]
|
91
|
+
else
|
92
|
+
barColor = @config["full"]
|
93
|
+
end
|
94
|
+
render = []
|
95
|
+
render << "<rect"
|
96
|
+
render << "id=\"foreground\" x=\"0\" cy=\"0\" height=\"20\" width=\"#{@valueWidth}\""
|
97
|
+
render << "style=\"fill: #{barColor}; mask: url(#pill-base)\""
|
98
|
+
render << "/>"
|
99
|
+
@paths.push([:foreground], render.join(" "))
|
100
|
+
end
|
101
|
+
|
71
102
|
|
72
103
|
# <mask id="pill-base" x="0" y="0" width="60" height="20" style="fill: #ffffff" >
|
73
104
|
# <circle cx="10" cy="10" r="10"/>
|