@@ -60,7 +60,15 @@ $(function() {
60
60
var iSettings = self . getSettings ( name ) ;
61
61
62
62
// Do know this or want it shown
63
- if ( typeof iSettings == "undefined" || iSettings . show ( ) == false || data . actual == null || data . actual == undefined || ( data . target == 0 && iSettings . hideOnNoTarget ( ) ) || ( ! customType && self . settings . hideInactiveTemps ( ) && self . tempModel . isOperational ( ) !== true ) || ( 'waitForPrint' in iSettings && iSettings . waitForPrint ( ) && ! self . connection . isPrinting ( ) ) ) {
63
+ if ( typeof iSettings == "undefined"
64
+ || iSettings . show ( ) == false
65
+ || data . actual == null
66
+ || data . actual == undefined
67
+ || ( data . target == 0 && iSettings . hideOnNoTarget ( ) )
68
+ || ( ! customType && self . settings . hideInactiveTemps ( ) && self . tempModel . isOperational ( ) !== true )
69
+ || ( 'waitForPrint' in iSettings && iSettings . waitForPrint ( ) && ! self . connection . isPrinting ( ) )
70
+ || ( 'hideIfNoPrinter' in iSettings && iSettings . hideIfNoPrinter ( ) && ! self . tempModel . isOperational ( ) )
71
+ ) {
64
72
$ ( '#navbar_plugin_toptemp_' + name ) . hide ( ) ;
65
73
$ ( '#navbar_plugin_toptemp_' + name + '_divider' ) . hide ( ) ;
66
74
return ;
@@ -107,6 +115,12 @@ $(function() {
107
115
var reval = 0 ;
108
116
graphData = { 'series' : [ self . tempModel . temperatures [ name ] . actual . slice ( - 300 ) . map ( function ( val , i ) { return val [ 1 ] } ) ] } ;
109
117
}
118
+
119
+ var MinYVal = reval ;
120
+ if ( iSettings . gMin ( ) != "" ) {
121
+ MinYVal = iSettings . gMin ( ) * 1 ;
122
+ }
123
+
110
124
// DO we have what we need
111
125
if ( graphData != null && typeof Chartist == "object" ) {
112
126
var graphOptions = {
@@ -121,18 +135,21 @@ $(function() {
121
135
showGrid : false ,
122
136
padding : 0 ,
123
137
offset : 0 ,
124
- low : reval ,
138
+ low : MinYVal ,
125
139
type : Chartist . AutoScaleAxis ,
126
140
referenceValue : reval
127
141
} ,
128
- low : reval ,
142
+ low : MinYVal ,
129
143
fullWidth : true ,
130
144
showPoint : false ,
131
145
lineSmooth : false ,
132
146
showGridBackground : false ,
133
147
chartPadding : 0 ,
134
148
labelOffset : 0
135
149
}
150
+ if ( iSettings . gMax ( ) != "" ) {
151
+ graphOptions . high = iSettings . gMax ( ) * 1 ;
152
+ }
136
153
new Chartist . Line ( '#TopTempGraph_' + name + '_graph' , graphData , graphOptions ) ;
137
154
}
138
155
}
@@ -144,7 +161,7 @@ $(function() {
144
161
}
145
162
146
163
// Append actual data
147
- outputstr += self . formatTempLabel ( name , data . actual , iSettings ) ;
164
+ outputstr += self . formatTempLabel ( name , data . actual , iSettings , true ) ;
148
165
149
166
// Append target if not custom type, we have a target and told to show it
150
167
if ( ! customType && typeof data . target != undefined && data . target > 0 ) {
@@ -172,7 +189,7 @@ $(function() {
172
189
if ( ! iSettings . showTargetArrow ( ) ) {
173
190
outputstr += "/" ;
174
191
}
175
- outputstr += self . formatTempLabel ( name , data . target , iSettings ) ;
192
+ outputstr += self . formatTempLabel ( name , data . target , iSettings , true ) ;
176
193
}
177
194
178
195
}
@@ -200,7 +217,7 @@ $(function() {
200
217
}
201
218
202
219
// Pretty format a temperature label
203
- self . formatTempLabel = function ( name , value , iSettings ) {
220
+ self . formatTempLabel = function ( name , value , iSettings , appendF ) {
204
221
// No value or not a temperature
205
222
if ( value == null ) {
206
223
return value ;
@@ -229,22 +246,57 @@ $(function() {
229
246
230
247
// Temperature handling
231
248
var formatSymbol = "C" ;
232
- if ( self . settings . fahrenheit ( ) ) {
233
- value = self . convertToF ( value ) ;
234
- formatSymbol = "F" ;
235
- }
236
249
237
- if ( iSettings . noDigits ( ) != - 1 ) {
238
- value = Number . parseFloat ( value ) . toFixed ( iSettings . noDigits ( ) ) ;
250
+ // Join temps
251
+ if ( appendF && self . settings . fahrenheit ( ) && self . settings . showTempCombined ( ) ) {
252
+ fVal = self . convertToF ( value ) ;
253
+ if ( iSettings . noDigits ( ) != - 1 ) {
254
+ fVal = Number . parseFloat ( fVal ) . toFixed ( iSettings . noDigits ( ) ) ;
255
+ } else {
256
+ fVal = Number . parseFloat ( fVal ) ;
257
+ }
258
+ fVal = fVal . toString ( ) ;
259
+ if ( iSettings . decSep ( ) != "" ) {
260
+ fVal = fVal . replace ( "." , iSettings . decSep ( ) ) ;
261
+ }
262
+ if ( iSettings . showUnit ( ) ) {
263
+ fVal += '°F' ;
264
+ }
265
+
266
+ dVal = value ;
267
+ if ( iSettings . noDigits ( ) != - 1 ) {
268
+ dVal = Number . parseFloat ( dVal ) . toFixed ( iSettings . noDigits ( ) ) ;
269
+ } else {
270
+ dVal = Number . parseFloat ( dVal ) ;
271
+ }
272
+ dVal = dVal . toString ( ) ;
273
+ if ( iSettings . decSep ( ) != "" ) {
274
+ dVal = dVal . replace ( "." , iSettings . decSep ( ) ) ;
275
+ }
276
+ if ( iSettings . showUnit ( ) ) {
277
+ dVal += '°C' ;
278
+ }
279
+
280
+ value = fVal + "(" + dVal + ")" ;
281
+
239
282
} else {
240
- value = Number . parseFloat ( value ) ;
241
- }
242
- value = value . toString ( ) ;
243
- if ( iSettings . decSep ( ) != "" ) {
244
- value = value . replace ( "." , iSettings . decSep ( ) ) ;
245
- }
246
- if ( iSettings . showUnit ( ) ) {
247
- value += '°' + formatSymbol ;
283
+ if ( self . settings . fahrenheit ( ) ) {
284
+ value = self . convertToF ( value ) ;
285
+ formatSymbol = "F" ;
286
+ }
287
+
288
+ if ( iSettings . noDigits ( ) != - 1 ) {
289
+ value = Number . parseFloat ( value ) . toFixed ( iSettings . noDigits ( ) ) ;
290
+ } else {
291
+ value = Number . parseFloat ( value ) ;
292
+ }
293
+ value = value . toString ( ) ;
294
+ if ( iSettings . decSep ( ) != "" ) {
295
+ value = value . replace ( "." , iSettings . decSep ( ) ) ;
296
+ }
297
+ if ( iSettings . showUnit ( ) ) {
298
+ value += '°' + formatSymbol ;
299
+ }
248
300
}
249
301
return value ;
250
302
}
@@ -667,10 +719,10 @@ $(function() {
667
719
direction : 'vertical' ,
668
720
dragoverBubble : false ,
669
721
onStart : function ( ) {
670
- $ ( '#drop_overlay' ) . addClass ( 'UICHideHard ' ) ;
722
+ $ ( '#drop_overlay' ) . addClass ( 'topTempHideHard ' ) ;
671
723
} ,
672
724
onEnd : function ( evt ) {
673
- $ ( '#drop_overlay' ) . removeClass ( 'UICHideHard in' ) ;
725
+ $ ( '#drop_overlay' ) . removeClass ( 'topTempHideHard in' ) ;
674
726
if ( self . previewOn ) {
675
727
var sortlist = $ ( '#TopTempSortList >div' ) . map ( function ( ) { return $ ( this ) . data ( 'sortid' ) } ) . get ( ) ;
676
728
$ . each ( sortlist , function ( i , val ) {
@@ -947,6 +999,13 @@ $(function() {
947
999
948
1000
// UI ready
949
1001
self . onAllBound = function ( ) {
1002
+ // We dont wait for this :)
1003
+ if ( typeof Sortable != "function" ) {
1004
+ var script = document . createElement ( 'script' ) ;
1005
+ script . src = '/plugin/toptemp/static/js/Sortable.min.js' ;
1006
+ document . body . appendChild ( script ) ;
1007
+ }
1008
+
950
1009
// Set class
951
1010
$ ( '#navbar_plugin_toptemp' ) . addClass ( 'navbar-text' ) ;
952
1011
@@ -989,13 +1048,6 @@ $(function() {
989
1048
return ;
990
1049
}
991
1050
992
- // We dont wait for this :)
993
- if ( typeof Sortable != "function" ) {
994
- var script = document . createElement ( 'script' ) ;
995
- script . src = '/plugin/toptemp/static/js/Sortable.min.js' ;
996
- document . body . appendChild ( script ) ;
997
- }
998
-
999
1051
// Wait for js
1000
1052
if ( ! self . jsLoaded ) {
1001
1053
return ;
@@ -1004,11 +1056,11 @@ $(function() {
1004
1056
// Update printer operational
1005
1057
self . tempModel . isOperational . subscribe ( function ( state ) {
1006
1058
if ( state ) {
1007
- $ ( '#navbar_plugin_toptemp div.TopTempPrinter' ) . show ( ) ;
1008
- $ ( '#navbar_plugin_toptemp div.TopTempPrinter + span.divider-vertical' ) . show ( ) ;
1059
+ $ ( '#navbar_plugin_toptemp div.TopTempPrinter, #navbar_plugin_toptemp div.TopTempHideNoPrinter ' ) . show ( ) ;
1060
+ $ ( '#navbar_plugin_toptemp div.TopTempPrinter + span.divider-vertical, #navbar_plugin_toptemp div.TopTempHideNoPrinter + span.divider-vertical ' ) . show ( ) ;
1009
1061
} else if ( self . settings . hideInactiveTemps ( ) ) {
1010
- $ ( '#navbar_plugin_toptemp div.TopTempPrinter' ) . hide ( ) ;
1011
- $ ( '#navbar_plugin_toptemp div.TopTempPrinter + span.divider-vertical' ) . hide ( ) ;
1062
+ $ ( '#navbar_plugin_toptemp div.TopTempPrinter, #navbar_plugin_toptemp div.TopTempHideNoPrinter ' ) . hide ( ) ;
1063
+ $ ( '#navbar_plugin_toptemp div.TopTempPrinter + span.divider-vertical, #navbar_plugin_toptemp div.TopTempHideNoPrinter + span.divider-vertical ' ) . hide ( ) ;
1012
1064
}
1013
1065
} ) ;
1014
1066
@@ -1173,6 +1225,23 @@ $(function() {
1173
1225
} ) ;
1174
1226
}
1175
1227
1228
+ self . findMinMaxAvg = function ( data ) {
1229
+ var items = data . length ;
1230
+ var lowValD = null ;
1231
+ var highValD = null ;
1232
+ var sum = 0 ;
1233
+ data . map ( function ( val , i ) {
1234
+ sum += val [ 1 ] ;
1235
+ if ( lowValD == null || lowValD > val [ 1 ] ) {
1236
+ lowValD = val [ 1 ] ;
1237
+ }
1238
+ if ( highValD == null || highValD < val [ 1 ] ) {
1239
+ highValD = val [ 1 ] ;
1240
+ }
1241
+ } ) ;
1242
+ return { 'low' :lowValD , 'high' :highValD , 'avg' :( sum / items ) }
1243
+ }
1244
+
1176
1245
self . updatePopover = function ( $thisID , $isCustom , iSettings ) {
1177
1246
var mainItem = $ ( '#navbar_plugin_toptemp_' + $thisID ) ;
1178
1247
// Check if open or not
@@ -1187,20 +1256,23 @@ $(function() {
1187
1256
if ( $ ( '#TopTempPopoverText_' + $thisID ) . length ) {
1188
1257
if ( $isCustom ) {
1189
1258
if ( $thisID in self . customHistory ) {
1259
+ var stats = self . findMinMaxAvg ( self . customHistory [ $thisID ] ) ;
1190
1260
var actual = self . customHistory [ $thisID ] [ self . customHistory [ $thisID ] . length - 1 ] [ 1 ] ;
1191
- var output = '<div class="pull-right "><small>Current: ' + self . formatTempLabel ( $thisID , actual , iSettings ) + '</small></div>' ;
1261
+ var output = '<div class="pull-left "><small>Current: ' + self . formatTempLabel ( $thisID , actual , iSettings , false ) + '</small></div><div class="pull-right"><small>Max: ' + self . formatTempLabel ( $thisID , stats . high , iSettings , false ) + ' · Min: ' + self . formatTempLabel ( $thisID , stats . low , iSettings , false ) + ' · Avg: ' + self . formatTempLabel ( $thisID , stats . avg , iSettings , false ) + '</small></div>' ;
1192
1262
$ ( '#TopTempPopoverText_' + $thisID ) . html ( output ) ;
1193
1263
}
1194
1264
} else {
1265
+ var stats = self . findMinMaxAvg ( self . tempModel . temperatures [ $thisID ] . actual ) ;
1195
1266
var actual = self . tempModel . temperatures [ $thisID ] . actual [ self . tempModel . temperatures [ $thisID ] . actual . length - 1 ] [ 1 ] ;
1196
1267
var target = self . tempModel . temperatures [ $thisID ] . target [ self . tempModel . temperatures [ $thisID ] . target . length - 1 ] [ 1 ] ;
1197
- var output = '<div class="pull-left"><small>Actual: ' + self . formatTempLabel ( $thisID , actual , iSettings ) + '</small></div><div class="pull-right"><small>Target: ' ;
1268
+ var output = '<div class="pull-left"><small>Actual: ' + self . formatTempLabel ( $thisID , actual , iSettings , false ) + '</small></div><div class="pull-right"><small>Target: ' ;
1198
1269
if ( target == 0 ) {
1199
1270
output += 'Off' ;
1200
1271
} else {
1201
- output += self . formatTempLabel ( $thisID , target , iSettings ) ;
1272
+ output += self . formatTempLabel ( $thisID , target , iSettings , false ) ;
1202
1273
}
1203
1274
output += '</small></div>' ;
1275
+ output += '<div class="text-center"><small>Max: ' + self . formatTempLabel ( $thisID , stats . high , iSettings , false ) + ' · Min: ' + self . formatTempLabel ( $thisID , stats . low , iSettings , false ) + ' · Avg: ' + self . formatTempLabel ( $thisID , stats . avg , iSettings , false ) + '</small></div>'
1204
1276
$ ( '#TopTempPopoverText_' + $thisID ) . html ( output ) ;
1205
1277
}
1206
1278
}
@@ -1228,6 +1300,10 @@ $(function() {
1228
1300
}
1229
1301
}
1230
1302
1303
+ var maxHis = self . popoverGHist ;
1304
+ if ( iSettings . gHisSecs ( ) > 0 ) {
1305
+ maxHis = 0 - iSettings . gHisSecs ( ) ;
1306
+ }
1231
1307
// Custom data or not?
1232
1308
if ( $isCustom ) {
1233
1309
// No data?!
@@ -1244,7 +1320,7 @@ $(function() {
1244
1320
$ . each ( temp , function ( x , val ) {
1245
1321
var seconds = val [ 0 ] - nowTs ;
1246
1322
// only get last 10 min
1247
- if ( seconds < self . popoverGHist ) {
1323
+ if ( seconds < maxHis ) {
1248
1324
return false ;
1249
1325
}
1250
1326
dataFound ++ ;
@@ -1295,7 +1371,7 @@ $(function() {
1295
1371
$ . each ( temp , function ( x , val ) {
1296
1372
var seconds = Math . round ( ( val [ 0 ] - nowTs ) / 1000 ) ;
1297
1373
// only get last 10 min
1298
- if ( seconds < self . popoverGHist && dataFound > 10 ) {
1374
+ if ( seconds < maxHis && dataFound > 10 ) {
1299
1375
return false ;
1300
1376
}
1301
1377
dataFound ++ ;
@@ -1316,6 +1392,15 @@ $(function() {
1316
1392
} ;
1317
1393
}
1318
1394
1395
+ var MinYVal = reval ;
1396
+ if ( iSettings . gMin ( ) != "" ) {
1397
+ MinYVal = iSettings . gMin ( ) * 1 ;
1398
+ }
1399
+
1400
+ if ( iSettings . gMax ( ) != "" ) {
1401
+ varHigh = iSettings . gMax ( ) * 1 ;
1402
+ }
1403
+
1319
1404
// Now build it
1320
1405
var options = {
1321
1406
axisX : {
@@ -1347,9 +1432,9 @@ $(function() {
1347
1432
scaleMinSpace : 20 ,
1348
1433
onlyInteger : true ,
1349
1434
referenceValue : reval ,
1350
- low : reval ,
1435
+ low : MinYVal ,
1351
1436
} ,
1352
- low : reval ,
1437
+ low : MinYVal ,
1353
1438
showLine : true ,
1354
1439
showPoint : false ,
1355
1440
showArea : false ,
@@ -1426,6 +1511,9 @@ $(function() {
1426
1511
if ( localSettings . waitForPrint ( ) ) {
1427
1512
className += " TopTempWaitPrinter" ;
1428
1513
}
1514
+ if ( localSettings . hideIfNoPrinter ( ) ) {
1515
+ className += " TopTempHideNoPrinter" ;
1516
+ }
1429
1517
}
1430
1518
if ( self . settings . leftAlignIcons ( ) ) {
1431
1519
className += " IconsLeft" ;
@@ -1471,10 +1559,25 @@ $(function() {
1471
1559
1472
1560
// Add CSS for the graphs
1473
1561
self . setGraphStyle = function ( name , settings ) {
1562
+ var important = "" ;
1563
+ if ( settings . forceStyle ( ) ) {
1564
+ important = " !important" ;
1565
+ }
1474
1566
// Remove old
1475
1567
$ ( '#TopTempGraph_' + name + '_style' ) . remove ( ) ;
1568
+
1569
+ var styleSet = `
1570
+ #TopTempGraph_${ name } _graph{
1571
+ height:${ settings . height ( ) } %${ important } ;
1572
+ }
1573
+ #TopTempGraph_${ name } _graph.TopTempGraph > svg >g .ct-line{
1574
+ stroke-width: ${ settings . width ( ) } px${ important } ;
1575
+ stroke-opacity: ${ settings . opa ( ) } ${ important } ;
1576
+ stroke: ${ settings . color ( ) } ${ important } ;
1577
+ }` ;
1578
+
1476
1579
// Build new
1477
- $ ( 'head' ) . append ( '<style id="TopTempGraph_' + name + '_style">\n#TopTempGraph_' + name + '_graph{\nheight:' + settings . height ( ) + '%\n}\n#TopTempGraph_' + name + '_graph.TopTempGraph > svg >g .ct-line{\nstroke-width: ' + settings . width ( ) + 'px;\nstroke-opacity: ' + settings . opa ( ) + ';\nstroke: ' + settings . color ( ) + ';\n}\n </style>' ) ;
1580
+ $ ( 'head' ) . append ( '<style id="TopTempGraph_' + name + '_style">\n' + styleSet + ' </style>') ;
1478
1581
// Show the graph?
1479
1582
if ( settings . show ) {
1480
1583
$ ( '#TopTempGraph_' + name + '_graph' ) . show ( ) ;
0 commit comments