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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a41df7f92ab1191a4c26dc21f851fe28f6d2c54
4
- data.tar.gz: b72f8ac66dd089364ed7d4b89501ee44bb7b3cf6
3
+ metadata.gz: ff53e9a4fdf5e64b598c496c508b36d0244623ff
4
+ data.tar.gz: c4e1da88510ff654b8849e056dbc5c67a607a882
5
5
  SHA512:
6
- metadata.gz: 88d7667b15f0299df0cab6c06e4ad55ca25a3fbf5a9f159cfbb2fc7359ca1400d67df23f9397f363a4008872cbe34dad0152177eea829546c065f9f0c5f2288b
7
- data.tar.gz: 4976f119b3ea5a2481ef271c7451b8d68d482a2a8330d17079ac45f1f76908ae459c1a3983c6b09030f64207c2ae04609ca1a6af061f71525f1d55c54374c4fc
6
+ metadata.gz: 86e652bde2be5c0c1c7e6c28d2c25b1ab1e52f2c1d3d63eab8992a031e6a6ef45d9c318a0a10926bb860a0baf783d43afe886ea2d02c414054239f832a00fea9
7
+ data.tar.gz: 21fa4f7a0cc505e278ca50dc59c591f07b4c16f9794ea4a2cd7692d927ab70a2377443261135a21ed33e8bb4cf4e90d9f45af3f689eb5b93ca732e73d619edf0
@@ -1,32 +1,45 @@
1
1
  module PillChart
2
2
 
3
- def pill_chart_here
4
- "Hey, i'm here !"
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 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)
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, max = 100, colors = {})
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
- @config = {
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
- self.drawForegroundPath
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 drawForegroundPath
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"/>
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.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Aubin