minichart 0.3.1 → 0.3.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
  SHA256:
3
- metadata.gz: 133646d3a37d8994e640a03eebd3a631f608e1decfd7c5666271dc07c4acbbc0
4
- data.tar.gz: b4dd484bd550a26b8ef2f7be811a79a1cefe79dd0c6b13e5ebbe5d13a2bc1f63
3
+ metadata.gz: 3c2af3f30a91b6f557ec75c02d6250153919290dd962c318bd58008600068b22
4
+ data.tar.gz: b00bd9ad950b213a7430178d55673aed0b9f4ee80b3b82f20a456d16f2d91b5d
5
5
  SHA512:
6
- metadata.gz: 3f7e5d813fc8cccf069494ef14ac4b4c0db59147b3f1467e064b33d411833387da6589484a7bbba578846e632161a944063ce87f5f1225ee020629473b89ec2f
7
- data.tar.gz: 37cc2233dae92905239c27ee4ae70c6d18b15b9fd0813f0ee9d6d99a894553cb501da3f3f321dbbcfa032d1e2c0e4442bba72fe87d42c7c0c5aebc06560366f6
6
+ metadata.gz: e183bdd8e7876c9f58503a3edcc80ffaf1fa1d03fde54d400de153e894bb3e51012f30d7b87683c887c2f482cedc331d57ea14fc5ddc4ae4f5c318e2bdc30a22
7
+ data.tar.gz: fbca221fb51fa31ee37b1532c2a4d0d7f28b44d94aeaf3c47b7c8744d68dc0188a44341fc265ba286c84eea479350be3d0be4b45d32a5b2dd5152917677f3ce1
data/README.md CHANGED
@@ -28,7 +28,6 @@ Create SVG mini charts with Ruby
28
28
  * [Leds Options](#leds-options)
29
29
  * [Examples](#examples)
30
30
 
31
-
32
31
  ---
33
32
 
34
33
  ## Install
@@ -212,92 +211,40 @@ chart.options[:background] = 'yellow'
212
211
 
213
212
  ### Basic Options
214
213
 
215
- #### background
216
-
217
- Chart background color.
218
-
219
- #### color
220
-
221
- Chart color.
222
-
223
- #### height
224
-
225
- Chart height in pixels.
226
-
227
- #### width
228
-
229
- Chart width in pixels.
230
-
231
- #### stroke
232
-
233
- Line stroke width. This has a different effect in different chart types.
234
-
235
- #### style
236
-
237
- CSS Style hash to apply to the entire SVG.
238
-
239
- #### padding
240
-
241
- Chart padding in pixels.
242
-
214
+ - **background**: Chart background color.
215
+ - **color**: Chart color.
216
+ - **height**: Chart height in pixels.
217
+ - **width**: Chart width in pixels.
218
+ - **stroke**: Line stroke width. This has a different effect in different chart types.
219
+ - **style**: CSS Style hash to apply to the entire SVG.
220
+ - **padding**: Chart padding in pixels.
243
221
 
244
222
  ### Meter Options
245
223
 
246
224
  Meter charts support these options in additon to the basic options:
247
225
 
248
- #### mode
249
-
250
- Display mode. Can be `:positive`, `:negative`, `:dual` or `:auto` (default).
251
-
252
- The `:auto` mode will switch between `:positive` and `:negative` based on the
253
- value.
254
-
255
- #### max
256
-
257
- The absolute maximum value. This number should be positive even for negative
258
- charts.
259
-
260
- #### notches
261
-
262
- An array of one or more levels to place a notch marker. Use positive values
263
- only.
264
-
265
- #### notch_thickness
266
-
267
- Thickness of the notch markers.
268
-
269
- #### notch_color
270
-
271
- Color of the notch markers.
272
-
273
- #### clipping_indicator
274
-
275
- If true, show a marker when the value exceeds the range.
276
-
277
- #### clipping_indicator_thickness
278
-
279
- Thickness of the clipping indicator.
280
-
281
- #### clipping_indicator_color
282
-
283
- Color of the clipping indicator.
226
+ - **mode**: Display mode. Can be `:positive`, `:negative`, `:dual` or `:auto` (default).
227
+ The `:auto` mode will switch between `:positive` and `:negative` based on the
228
+ value.
229
+ - **max**: The absolute maximum value. This number should be positive even for negative
230
+ charts.
231
+ - **notches**: An array of one or more levels to place a notch marker. Use positive values
232
+ only.
233
+ - **notch_thickness**: Thickness of the notch markers.
234
+ - **notch_color**: Color of the notch markers.
235
+ - **clipping_indicator**: If true, show a marker when the value exceeds the range.
236
+ - **clipping_indicator_thickness**: Thickness of the clipping indicator.
237
+ - **clipping_indicator_color**: Color of the clipping indicator.
284
238
 
285
239
  ### Leds Options
286
240
 
287
- Leds charts support these options in additon to the basic options (excluding
241
+ Led charts support these options in additon to the basic options (excluding
288
242
  the `color` option):
289
243
 
290
- #### positive_color
291
-
292
- Color to use when the value is greater than 0.
293
-
294
- #### negative_color
295
-
296
- Color to use when the value is less than 0.
297
-
298
- #### neutral_color
299
-
300
- Color to use when the value is 0 or nil.
244
+ - **positive_color**: Color to use when the value is greater than 0.
245
+ - **negative_color**: Color to use when the value is less than 0.
246
+ - **neutral_color**: Color to use when the value is 0 or nil.
247
+ - **min_opacity**: A value between 0 and 1 representing the minimum opacity that will be applied to values when they are lower than the maximum range.
301
248
 
302
249
  ## Examples
303
250
 
@@ -15,7 +15,7 @@ module Minichart
15
15
  protected
16
16
 
17
17
  def bar_width
18
- @bar_width ||= options[:width] / data.size
18
+ @bar_width ||= options[:width] / data.size.to_f
19
19
  end
20
20
 
21
21
  def bar_options(value, i)
@@ -33,6 +33,7 @@ module Minichart
33
33
  width: bar_width,
34
34
  height: options[:height],
35
35
  style: {
36
+ opacity: opacity(value),
36
37
  fill: options[color],
37
38
  stroke_width: options[:stroke],
38
39
  stroke: options[:background]
@@ -1,17 +1,31 @@
1
1
  module Minichart
2
2
  # Base class for led charts
3
3
  class Leds < Base
4
-
5
4
  class << self
6
5
  def leds_defaults
7
6
  @meter_defaults ||= {
8
7
  positive_color: '#6f6',
9
8
  negative_color: '#f66',
10
9
  neutral_color: '#eee',
10
+ min_opacity: 1,
11
11
  padding: 2,
12
12
  }
13
13
  end
14
14
  end
15
15
 
16
+ protected
17
+
18
+ # Returns opacith level for a given value
19
+ def opacity(value)
20
+ return 1 if !value or value == 0
21
+ value.abs * ((1 - options[:min_opacity]) / max) + options[:min_opacity]
22
+ end
23
+
24
+ # Returns the absolute highest or loest value.
25
+ # Used to define the availble range of values
26
+ def max
27
+ @max ||= [data.compact.max, data.compact.min.abs].max.to_f
28
+ end
29
+
16
30
  end
17
31
  end
@@ -19,7 +19,7 @@ module Minichart
19
19
  end
20
20
 
21
21
  def bar_height
22
- @bar_height ||= options[:height] / points
22
+ @bar_height ||= options[:height] / points.to_f
23
23
  end
24
24
 
25
25
  def bar_options(value, i)
@@ -39,6 +39,7 @@ module Minichart
39
39
  width: options[:width],
40
40
  height: bar_height,
41
41
  style: {
42
+ opacity: opacity(value),
42
43
  fill: options[color],
43
44
  stroke_width: options[:stroke],
44
45
  stroke: options[:background]
@@ -1,3 +1,3 @@
1
1
  module Minichart
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minichart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-06 00:00:00.000000000 Z
11
+ date: 2020-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: victor