-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcmd.info.numeric.nooInfoGradientSlider.html
382 lines (349 loc) · 12.6 KB
/
cmd.info.numeric.nooInfoGradientSlider.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<div
style="margin-right: 5px; margin-left: 5px; padding: 0px !important"
class="cmd #history# container-fluid tooltips cmd cmd-widget"
data-type="info"
data-subtype="numeric"
data-cmd_id="#id#"
data-cmd_uid="#uid#"
data-version="#version#"
>
<!-- ################ nooInfoGradientSlider ################
********** Paramètres Optionnels ***************
width : largeur ('200px' si non renseigné)
height : hauteur ('30px' si non renseigné)
bgColor : couleur de début du dégradé du bouton Off ('#333' si non renseigné)
bgPixelsOff : couleur de fin du dégradé du bouton Off ('#000' si non renseigné)
gradientValues : valeurs des dégradés de couleurs ('0|80|100' si non renseigné)
gradientColors : couleur des pixels de fond ('green|yellow|red' si non renseigné)
vertical : affichage vertical : '0' pour affichage horizontal, '1' pour affichage vertical('0' si non renseigné)
Pensez au café pour les nuits blanches de codage ;)
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=noodom.fr%40gmail.com¤cy_code=EUR&source=url
########### by @noodom ;)
########### code disponible ici : https://github.com/noodom/jeedom_widgets/tree/master/nooInfoGradientSlider
-->
<!--
nooInfoGradientSlider : widget for Jeedom
Copyright (C) 2023 @noodom
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-->
<template>
<div>width : largeur ('200px' si non renseigné)</div>
<div>height : hauteur ('30px' si non renseigné)</div>
<div>bgColor : couleur de fond ('#333' si non renseigné)</div>
<div>
bgPixelsOff : couleur des pixels de fond ('#666' si non renseigné)
</div>
<div>
gradientValues : valeurs des dégradés de couleurs ('0|80|100' si non
renseigné)
</div>
<div>
gradientColors : couleur des pixels de fond ('green|yellow|red' si non
renseigné)
</div>
<div>vertical : affichage vertical ('0' si non renseigné)</div>
</template>
<center>
<div class="title #hide_name#">
<div class="cmdName">#name_display#</div>
</div>
<br />
<div>
<div class="centered">
<div class="val"></div>
<div class="content2">
<div class="levels" id="levels">
<div class="level" id="level"></div>
</div>
<div class="verticalLimits">
<div class="maxValue">100</div>
<div class="minValue">0</div>
</div>
</div>
<div class="horizontalLimits">
<div class="minValue">0</div>
<div class="maxValue">100</div>
</div>
</div>
</div>
<div class="value #hide_history#">
<div class="col-xs-12 center-block">
<span title="{{Min}}" class="tooltips">#minHistoryValue#</span>|<span
title="{{Moyenne}}"
class="tooltips"
>#averageHistoryValue#</span
>|<span title="{{Max}}" class="tooltips">#maxHistoryValue#</span>
<i class="#tendance#"></i>
</div>
</div>
</center>
<script>
// Chargement des paramètres optionnels
var width#id# = ('#width#' != '#' + 'width#') ? "#width#" : '200px';
if (width#id# != '') {
document.documentElement.style.setProperty('--width#id#', width#id#);
}
var height#id# = ('#height#' != '#' + 'height#') ? "#height#" : '30px';
if (height#id# != '') {
document.documentElement.style.setProperty('--height#id#', height#id#);
}
var bgColor#id# = ('#bgColor#' != '#' + 'bgColor#') ? "#bgColor#" : '#333';
if (bgColor#id# != '') {
document.documentElement.style.setProperty('--bg-color#id#', bgColor#id#);
}
var bgPixelsOff#id# = ('#bgPixelsOff#' != '#' + 'bgPixelsOff#') ? "#bgPixelsOff#" : '#666';
if (bgPixelsOff#id# != '') {
document.documentElement.style.setProperty('--bg-pixels-off#id#', bgPixelsOff#id#);
}
var vertical#id# = ('#vertical#' != '#' + 'vertical#') ? "#vertical#" : '0';
var cmd = $('.cmd[data-cmd_id=#id#]')
if (vertical#id# === '1') {
cmd.find('.levels').addClass('vertical');
}
var gradientValues#id# = ('#gradientValues#' != '#' + 'gradientValues#') ? "#gradientValues#" : '0|80|100';
var gradientColors#id# = ('#gradientColors#' != '#' + 'gradientColors#') ? "#gradientColors#" : 'green|yellow|red';
var percents = gradientValues#id#.split('|');
var colors = gradientColors#id#.split('|');
var gradientGauge#id# = (vertical#id# === '1')?'linear-gradient(to top':'linear-gradient(to right';
var nbGradientColors = colors.length;
for (let i=0 ; i<nbGradientColors ; i++) {
gradientGauge#id# += ', ' + colors[i] + ' ' + percents[i] + '%';
}
gradientGauge#id# += ')';
document.documentElement.style.setProperty('--gradient-gauge#id#', gradientGauge#id#);
// jeedom.cmd.update['#id#'] = function(_options){
jeedom.cmd.addUpdateFunction('#id#',function(_options) {
var value = ($.isNumeric(_options.display_value)) ? parseFloat(_options.display_value) : 0.0;
var intNum = Math.trunc(value);
var valsign = '-';
var decNum = Math.round((value - intNum) * 10);
if (value < 0) {
var intNum = (valsign+intNum*-1);
var decNum = Math.round((decNum)*-1);
}
var minValue = ($.isNumeric('#minValue#')) ? parseFloat('#minValue#') : 0.0;
var maxValue = ($.isNumeric('#maxValue#')) ? parseFloat('#maxValue#') : 100.0;
var moyValue = Math.round((maxValue+minValue)/2);
var maxvaleur = maxValue + minValue;
var minNegative = 0;
if (minValue < 0){
var minNegative = minValue*-1;
var maxvaleur = maxValue + minNegative;
}
var maxNegative = 0;
if (maxValue < 0){
var maxNegative = maxValue*-1;
var maxvaleur = maxNegative + minNegative;
}
var valeurState = value + minNegative;
var jauge = 100 - Math.round( (_options.display_value - (minValue)) * (100/(maxValue - (minValue))) );
if (vertical#id# !== '1') {
// horizontal
document.documentElement.style.setProperty('--clip-path#id#', 'inset(0 ' + jauge + '% 0 0)');
$('.cmd[data-cmd_id=#id#] .verticalLimits').css('display', 'none');
}
else {
// vertical
document.documentElement.style.setProperty('--clip-path#id#', 'inset(' + jauge + '% 0 0 0)');
$('.cmd[data-cmd_id=#id#] .horizontalLimits').css('display', 'none');
}
$('.cmd[data-cmd_id=#id#]').attr('title','Valeur du '+_options.valueDate+', collectée le '+_options.collectDate);
//$('.cmd[data-cmd_id=#id#] .state').empty().append(_options.display_value);
$('.cmd[data-cmd_id=#id#] .val').empty().append(_options.display_value).append('#unite#');
$('.cmd[data-cmd_id=#id#] .minValue').empty().append(minValue);
$('.cmd[data-cmd_id=#id#] .maxValue').empty().append(maxValue);
});
jeedom.cmd.refreshValue([{cmd_id :'#id#',display_value: '#state#', valueDate: '#valueDate#', collectDate: '#collectDate#', alertLevel: '#alertLevel#', unit: '#unite#'}])
</script>
<style>
:root {
--width#id#: 200px;
--height#id#: 30px;
--bg-color#id#: #333;
--bg-pixels-off#id#: #666;
--percent#id#: 20%;
--clip-path#id#: inset(0 50% 0 0);
--gradient-gauge#id#: linear-gradient(
to right,
green 0%,
yellow 80%,
red 100%
);
}
[data-cmd_id="#id#"] .limits {
display: flex;
justify-content: space-between;
}
[data-cmd_id="#id#"] .verticalLimits {
display: flex;
flex-direction: column;
justify-content: space-between;
margin-left: 3px;
}
[data-cmd_id="#id#"] .horizontalLimits {
display: flex;
flex-direction: row;
justify-content: space-between;
margin-top: 3px;
}
[data-cmd_id="#id#"] .val {
height: 18px;
font-size: 14px;
width: fit-content;
padding: 3px;
margin-bottom: 3px;
color: var(--bg-pixels-off#id#);
background-color: var(--bg-color#id#);
border-radius: 10%;
}
[data-cmd_id="#id#"] .value {
margin-top: 3px;
}
[data-cmd_id="#id#"] .content2 {
display: flex !important;
flex-direction: row;
}
/* paint background of level meter */
[data-cmd_id="#id#"] .levels {
width: var(--width#id#);
height: var(--height#id#);
background-color: var(--bg-color#id#);
border-radius: 2px;
display: flex;
flex-direction: column;
padding: 3px 4px;
}
/* paint not glowing LEDs */
[data-cmd_id="#id#"] .level {
position: relative;
margin: 2px 0;
flex-grow: 1;
z-index: 3;
background-color: transparent;
background-repeat: repeat-x;
background-image: linear-gradient(
to right,
var(--bg-pixels-off#id#) 3px,
transparent 1px
);
background-size: 4px 100%;
}
/* paint glowing LEDs */
[data-cmd_id="#id#"] .level:before {
width: 100%;
height: 100%;
content: " ";
position: absolute;
top: 0px;
left: 0px;
z-index: 1;
background-repeat: no-repeat;
background-image: var(--gradient-gauge#id#);
background-size: 100% 100%;
clip-path: inset(0 0% 0 0);
/* switch off leds via clipping */
-webkit-clip-path: inset(0 0% 0 0);
}
/* paint gap lines of LEDs */
[data-cmd_id="#id#"] .level::after {
width: 100%;
height: 100%;
content: " ";
position: absolute;
top: 0px;
left: 0px;
z-index: 2;
margin-left: 3px;
background-image: linear-gradient(
to right,
var(--bg-color#id#) 1px /* space between leds*/,
transparent 1px
);
background-repeat: repeat-x;
background-size: 4px 100%;
/* 4px LED height */
background-color: transparent;
}
[data-cmd_id="#id#"] #level::before {
clip-path: var(--clip-path#id#);
-webkit-clip-path: var(--clip-path#id#);
}
/** vertical **/
/* paint background of level meter */
[data-cmd_id="#id#"] .vertical .levels {
width: var(--width#id#);
height: var(--height#id#);
background-color: #333;
border-radius: 2px;
display: flex;
flex-direction: row;
padding: 4px 3px;
/*margin: auto;
margin-top: 20px;*/
}
/* paint not glowing LEDs */
[data-cmd_id="#id#"] .vertical .level {
position: relative;
margin: 0 2px;
flex-grow: 1;
z-index: 3;
background-color: transparent;
background-repeat: repeat-y;
background-image: linear-gradient(
to bottom,
var(--bg-pixels-off#id#) 3px,
transparent 1px
);
background-size: 100% 4px;
}
/* paint glowing LEDs */
[data-cmd_id="#id#"] .vertical .level::before {
width: 100%;
height: 100%;
content: " ";
position: absolute;
top: 0px;
left: 0px;
z-index: 1;
background-repeat: no-repeat;
background-image: var(--gradient-gauge#id#);
background-size: 100% 100%;
clip-path: inset(0% 0 0 0);
/* switch off leds via clipping */
-webkit-clip-path: inset(0% 0 0 0);
/* Safari */
/*animation: level-animation 500ms alternate infinite;*/
}
/* paint gap lines of LEDs */
[data-cmd_id="#id#"] .vertical .level::after {
width: 100%;
height: 100%;
content: " ";
position: absolute;
top: 0px;
left: 0px;
z-index: 2;
margin-top: 3px;
margin-left: unset;
background-image: linear-gradient(
to bottom,
#333 1px /* space between leds*/,
transparent 1px
);
background-repeat: repeat-y;
background-size: 100% 4px;
/* 4px LED height */
background-color: transparent;
}
</style>
</div>