thecore_ui_commons 3.1.11 → 3.2.1

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
  SHA256:
3
- metadata.gz: d48077f03d2d041281628169859bf330330d00d12ca3fc8d214f5229b4cd58a6
4
- data.tar.gz: 3677d2f9517ce5231e169b1ec2a95f325625550d231436633a06da399a040358
3
+ metadata.gz: fdff559b019de14881d80b1c3eb160d18f2b947122d553fb3aa46c9a4d84024d
4
+ data.tar.gz: b2681fdf1a5a18ccc2675cd317a74e4c5d564915fd24e73275273b476f3f21da
5
5
  SHA512:
6
- metadata.gz: ed4fb24b2e10dce5fe185929435625f2c38fc97f1a257dc7ec3234a777de1372339980b3db3415435488a773117c1670e854567b1f36824bcd11b46115bef93d
7
- data.tar.gz: a779d10772aa10462458acf09f392da100d130eee8a407f22e3b61c8bdca450fe7ea8e209e6e57aaec1957b1188e103bbe58051343a2da66fd3fb3692aa82492
6
+ metadata.gz: 44db9e1a31c3990ef5624174e423b9c03d8acfa308758d602794f94e129355446369c4258d9d870910e3d7d7a586c5db86edf62e5afa547aa32bf582100f4805
7
+ data.tar.gz: 8be6bd95516a7fcbafcab3f3606abbcfd68c1196df9812804b7ce9785ef81ea1eef05a115d07f5f6f746902c276557085b7f5360c1a07293ba17be1308e4856c
@@ -0,0 +1,168 @@
1
+
2
+ module Echarts
3
+ module Speedometer
4
+ # Computes the percentage of a value within a given range.
5
+ #
6
+ # @param value [Numeric] The value to compute the percentage for.
7
+ # @param lower_bound [Numeric] The lower bound of the range.
8
+ # @param upper_bound [Numeric] The upper bound of the range.
9
+ # @return [Float] The percentage of the value within the range.
10
+ def self.compute_percentage(value, lower_bound, upper_bound)
11
+ (value - lower_bound) / (upper_bound - lower_bound)
12
+ end
13
+
14
+ # Computes the angle for a given value.
15
+ #
16
+ # @param value [Float] The value to compute the angle for.
17
+ # @return [Float] The angle in degrees.
18
+ def self.compute_angle(value)
19
+ # Compute the angles from the percentages knowing that the startAngle = 225 and the endAngle = -45 clockwise
20
+ 225 - (value * 270)
21
+ end
22
+
23
+ # Computes the angles for a given value and the minimum and maximum values in percentage.
24
+ #
25
+ # @param value_in_percentage [Float] The value in percentage.
26
+ # @param min_in_percentage [Float] The minimum value in percentage.
27
+ # @param max_in_percentage [Float] The maximum value in percentage.
28
+ # @return [Array<Float>] The minimum angle, maximum angle, and value angle in degrees.
29
+ def self.compute_angles(value_in_percentage, min_in_percentage, max_in_percentage)
30
+ min_angle = compute_angle(min_in_percentage)
31
+ max_angle = compute_angle(max_in_percentage)
32
+ value_angle = compute_angle(value_in_percentage)
33
+
34
+ return min_angle, max_angle, value_angle
35
+ end
36
+
37
+ # Computes the color for the gauge chart based on the minimum and maximum values.
38
+ #
39
+ # @param min [Numeric] The minimum value.
40
+ # @param max [Numeric] The maximum value.
41
+ # @param min_in_percentage [Float] The minimum value in percentage.
42
+ # @param max_in_percentage [Float] The maximum value in percentage.
43
+ # @param color_ok [String] The color for values within the range.
44
+ # @param color_error [String] The color for values outside the range.
45
+ # @param color_generic [String] The color for generic values.
46
+ # @return [Array<Array>] An array of color values and their corresponding percentages.
47
+ def self.compute_color(min, max, min_in_percentage, max_in_percentage, color_ok = "limegreen", color_error = "tomato", color_generic = "dodgerblue")
48
+ color = []
49
+ color << [min_in_percentage, color_error] if !min.zero? && (max > min || max.zero?)
50
+ color << [max_in_percentage, color_ok] if !max.zero? && (max > min || min.zero?)
51
+ color << [1, max > min ? color_error : ( max == min && max != 0 || max == 0 && min ==0 ? color_generic : color_ok )]
52
+
53
+ color
54
+ end
55
+
56
+ # Computes the options for the gauge chart.
57
+ #
58
+ # @param value [Numeric] The value to display on the gauge chart.
59
+ # @param min [Numeric] The minimum value.
60
+ # @param max [Numeric] The maximum value.
61
+ # @param lower_bound [Numeric] The lower bound of the range.
62
+ # @param upper_bound [Numeric] The upper bound of the range.
63
+ # @param measure_unit [String] The unit of measurement for the value.
64
+ # @param name [String] The name of the gauge chart.
65
+ # @param color_ok [String] The color for values within the range.
66
+ # @param color_error [String] The color for values outside the range.
67
+ # @param color_generic [String] The color for generic values.
68
+ # @return [Hash] The options for the gauge chart.
69
+ def self.get_config(value, min, max, lower_bound, upper_bound, measure_unit, name, color_ok = "limegreen", color_error = "tomato", color_generic = "dodgerblue")
70
+ min_in_percentage = compute_percentage(min, lower_bound, upper_bound)
71
+ max_in_percentage = compute_percentage(max, lower_bound, upper_bound)
72
+ value_in_percentage = compute_percentage(value, lower_bound, upper_bound)
73
+
74
+ color = compute_color(min, max, min_in_percentage, max_in_percentage, color_ok, color_error, color_generic)
75
+ min_angle, max_angle, value_angle = compute_angles(value_in_percentage, min_in_percentage, max_in_percentage)
76
+
77
+ # The gauge chart
78
+ raw_js_options = {
79
+ toolbox: {
80
+ feature: {
81
+ saveAsImage: {},
82
+ }
83
+ },
84
+ series: [
85
+ {
86
+ type: "gauge",
87
+ min: lower_bound,
88
+ max: upper_bound,
89
+ splitNumber: ((upper_bound - lower_bound) / lower_bound).abs,
90
+ axisLine: {
91
+ lineStyle: {
92
+ width: 30,
93
+ color: color,
94
+ },
95
+ },
96
+ pointer: {
97
+ itemStyle: {
98
+ color: "auto",
99
+ },
100
+ },
101
+ axisTick: {
102
+ distance: -30,
103
+ length: 8,
104
+ lineStyle: {
105
+ color: "#fff",
106
+ width: 2,
107
+ },
108
+ },
109
+ splitLine: {
110
+ distance: -30,
111
+ length: 30,
112
+ lineStyle: {
113
+ color: "#fff",
114
+ width: 4,
115
+ },
116
+ },
117
+ axisLabel: {
118
+ color: "inherit",
119
+ distance: 40,
120
+ fontSize: 20,
121
+ },
122
+ detail: {
123
+ valueAnimation: true,
124
+ # formatter: "#{value.to_i}#{measure_unit}",
125
+ color: "inherit",
126
+ },
127
+ data: [
128
+ {
129
+ value: value,
130
+ name: name,
131
+ },
132
+ ],
133
+ },
134
+ # Dummy Gauge to be used to show the min max thresholds
135
+ {
136
+ type: "gauge",
137
+ z: 3,
138
+ startAngle: min_angle, # Here you can dinamically change the value
139
+ min: min,
140
+ endAngle: max_angle, # Here you can dinamically change the value
141
+ max: max,
142
+ splitNumber: 1,
143
+ axisLabel: {
144
+ distance: -24,
145
+ },
146
+ axisTick: {
147
+ show: false,
148
+ },
149
+ axisLine: {
150
+ lineStyle: {
151
+ width: 0,
152
+ },
153
+ },
154
+ splitLine: {
155
+ distance: -12,
156
+ # length: 50,
157
+ lineStyle: {
158
+ width: 0,
159
+ },
160
+ },
161
+ },
162
+ ],
163
+ }
164
+
165
+ return raw_js_options
166
+ end
167
+ end
168
+ end
@@ -1,3 +1,3 @@
1
1
  module ThecoreUiCommons
2
- VERSION = "3.1.11".freeze
2
+ VERSION = "3.2.1".freeze
3
3
  end
@@ -5,6 +5,7 @@ require "haml-rails"
5
5
  require "groupdate"
6
6
  # require "apexcharts"
7
7
  require "rails_charts"
8
+ require "echarts/speedometer"
8
9
 
9
10
  require "thecore_ui_commons/engine"
10
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore_ui_commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.11
4
+ version: 3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
@@ -142,6 +142,7 @@ files:
142
142
  - config/locales/it.yml
143
143
  - config/routes.rb
144
144
  - db/seeds.rb
145
+ - lib/echarts/speedometer.rb
145
146
  - lib/tasks/thecore_ui_commons_tasks.rake
146
147
  - lib/thecore_ui_commons.rb
147
148
  - lib/thecore_ui_commons/engine.rb