Skip to content

Commit 92cf5ac

Browse files
authored
Merge pull request #85 from LazeMSS/develop
0.0.2.0 - puterboy special
2 parents 097305d + 6b5ada7 commit 92cf5ac

File tree

5 files changed

+251
-43
lines changed

5 files changed

+251
-43
lines changed

octoprint_toptemp/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def __init__(self):
7070
self.defaultConfig = {
7171
'firstRun' : True,
7272
'fahrenheit' : False,
73+
'showTempCombined': False,
7374
'leftAlignIcons' : False,
7475
'hideInactiveTemps' : True,
7576
'clickPopover' : False,
@@ -97,9 +98,13 @@ def __init__(self):
9798
'noDigits': 0,
9899
'showUnit': True,
99100
'decSep': ',',
101+
'gMin': '',
102+
'gMax': '',
103+
'gHisSecs': 600,
100104
'graphSettings': {
101105
'height': 50,
102106
'show': True,
107+
'forceStyle': False,
103108
'opa': 0.2,
104109
'width': 1,
105110
'color' : '#000000',
@@ -108,7 +113,7 @@ def __init__(self):
108113
}
109114

110115
# type can be cmd, gcIn, gcOut, psutil
111-
self.defaultsCustom = {'cmd':'','name':'','interval': 25, 'type':'cmd', 'isTemp' : True , 'waitForPrint' : False, 'unit' : '', 'postCalc' : None}
116+
self.defaultsCustom = {'cmd':'','name':'','interval': 25, 'type':'cmd', 'isTemp' : True , 'waitForPrint' : False, 'hideIfNoPrinter': False, 'unit' : '', 'postCalc' : None}
112117

113118
# ----------------------------------------------------------------------------------------------------------------
114119
# Lets get started

octoprint_toptemp/static/css/TopTemp.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,9 @@ body.TopTemPreviewON div#settings_dialog {
232232
color: #333;
233233
}
234234

235+
.topTempHideHard{
236+
display: none !important;
237+
}
238+
239+
235240
/* TopTemp END */

octoprint_toptemp/static/js/TopTemp.js

Lines changed: 144 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ $(function() {
6060
var iSettings = self.getSettings(name);
6161

6262
// 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+
){
6472
$('#navbar_plugin_toptemp_'+name).hide();
6573
$('#navbar_plugin_toptemp_'+name+'_divider').hide();
6674
return;
@@ -107,6 +115,12 @@ $(function() {
107115
var reval = 0;
108116
graphData = {'series' : [self.tempModel.temperatures[name].actual.slice(-300).map(function(val,i){return val[1]})]};
109117
}
118+
119+
var MinYVal = reval;
120+
if (iSettings.gMin() != ""){
121+
MinYVal = iSettings.gMin()*1;
122+
}
123+
110124
// DO we have what we need
111125
if (graphData != null && typeof Chartist == "object"){
112126
var graphOptions = {
@@ -121,18 +135,21 @@ $(function() {
121135
showGrid: false,
122136
padding: 0,
123137
offset: 0,
124-
low: reval,
138+
low: MinYVal,
125139
type: Chartist.AutoScaleAxis,
126140
referenceValue: reval
127141
},
128-
low: reval,
142+
low: MinYVal,
129143
fullWidth: true,
130144
showPoint: false,
131145
lineSmooth: false,
132146
showGridBackground: false,
133147
chartPadding: 0,
134148
labelOffset: 0
135149
}
150+
if (iSettings.gMax() != ""){
151+
graphOptions.high = iSettings.gMax()*1;
152+
}
136153
new Chartist.Line('#TopTempGraph_'+name+'_graph', graphData,graphOptions);
137154
}
138155
}
@@ -144,7 +161,7 @@ $(function() {
144161
}
145162

146163
// Append actual data
147-
outputstr += self.formatTempLabel(name,data.actual,iSettings);
164+
outputstr += self.formatTempLabel(name,data.actual,iSettings,true);
148165

149166
// Append target if not custom type, we have a target and told to show it
150167
if (!customType && typeof data.target != undefined && data.target > 0){
@@ -172,7 +189,7 @@ $(function() {
172189
if (!iSettings.showTargetArrow()){
173190
outputstr += "/";
174191
}
175-
outputstr += self.formatTempLabel(name,data.target,iSettings);
192+
outputstr += self.formatTempLabel(name,data.target,iSettings,true);
176193
}
177194

178195
}
@@ -200,7 +217,7 @@ $(function() {
200217
}
201218

202219
// Pretty format a temperature label
203-
self.formatTempLabel = function(name,value,iSettings){
220+
self.formatTempLabel = function(name,value,iSettings,appendF){
204221
// No value or not a temperature
205222
if (value == null){
206223
return value;
@@ -229,22 +246,57 @@ $(function() {
229246

230247
// Temperature handling
231248
var formatSymbol = "C";
232-
if (self.settings.fahrenheit()){
233-
value = self.convertToF(value);
234-
formatSymbol = "F";
235-
}
236249

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+
239282
}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+
}
248300
}
249301
return value;
250302
}
@@ -667,10 +719,10 @@ $(function() {
667719
direction: 'vertical',
668720
dragoverBubble: false,
669721
onStart: function(){
670-
$('#drop_overlay').addClass('UICHideHard');
722+
$('#drop_overlay').addClass('topTempHideHard');
671723
},
672724
onEnd: function(evt){
673-
$('#drop_overlay').removeClass('UICHideHard in');
725+
$('#drop_overlay').removeClass('topTempHideHard in');
674726
if (self.previewOn){
675727
var sortlist = $('#TopTempSortList >div').map(function(){return $(this).data('sortid')}).get();
676728
$.each(sortlist,function(i,val){
@@ -947,6 +999,13 @@ $(function() {
947999

9481000
// UI ready
9491001
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+
9501009
// Set class
9511010
$('#navbar_plugin_toptemp').addClass('navbar-text');
9521011

@@ -989,13 +1048,6 @@ $(function() {
9891048
return;
9901049
}
9911050

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-
9991051
// Wait for js
10001052
if (!self.jsLoaded){
10011053
return;
@@ -1004,11 +1056,11 @@ $(function() {
10041056
// Update printer operational
10051057
self.tempModel.isOperational.subscribe(function(state){
10061058
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();
10091061
}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();
10121064
}
10131065
});
10141066

@@ -1173,6 +1225,23 @@ $(function() {
11731225
});
11741226
}
11751227

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+
11761245
self.updatePopover = function($thisID,$isCustom,iSettings){
11771246
var mainItem = $('#navbar_plugin_toptemp_'+$thisID);
11781247
// Check if open or not
@@ -1187,20 +1256,23 @@ $(function() {
11871256
if ($('#TopTempPopoverText_'+$thisID).length){
11881257
if ($isCustom){
11891258
if ($thisID in self.customHistory){
1259+
var stats = self.findMinMaxAvg(self.customHistory[$thisID]);
11901260
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)+' &middot; Min: '+self.formatTempLabel($thisID,stats.low,iSettings,false)+' &middot; Avg: '+self.formatTempLabel($thisID,stats.avg,iSettings,false)+'</small></div>';
11921262
$('#TopTempPopoverText_'+$thisID).html(output);
11931263
}
11941264
}else{
1265+
var stats = self.findMinMaxAvg(self.tempModel.temperatures[$thisID].actual);
11951266
var actual = self.tempModel.temperatures[$thisID].actual[self.tempModel.temperatures[$thisID].actual.length-1][1];
11961267
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: ';
11981269
if (target == 0){
11991270
output += 'Off';
12001271
}else{
1201-
output += self.formatTempLabel($thisID,target,iSettings);
1272+
output += self.formatTempLabel($thisID,target,iSettings,false);
12021273
}
12031274
output += '</small></div>';
1275+
output += '<div class="text-center"><small>Max: '+self.formatTempLabel($thisID,stats.high,iSettings,false)+' &middot; Min: '+self.formatTempLabel($thisID,stats.low,iSettings,false)+' &middot; Avg: '+self.formatTempLabel($thisID,stats.avg,iSettings,false)+'</small></div>'
12041276
$('#TopTempPopoverText_'+$thisID).html(output);
12051277
}
12061278
}
@@ -1228,6 +1300,10 @@ $(function() {
12281300
}
12291301
}
12301302

1303+
var maxHis = self.popoverGHist;
1304+
if (iSettings.gHisSecs() > 0){
1305+
maxHis = 0 - iSettings.gHisSecs();
1306+
}
12311307
// Custom data or not?
12321308
if ($isCustom){
12331309
// No data?!
@@ -1244,7 +1320,7 @@ $(function() {
12441320
$.each(temp,function(x,val){
12451321
var seconds = val[0]-nowTs;
12461322
// only get last 10 min
1247-
if (seconds < self.popoverGHist){
1323+
if (seconds < maxHis){
12481324
return false;
12491325
}
12501326
dataFound++;
@@ -1295,7 +1371,7 @@ $(function() {
12951371
$.each(temp,function(x,val){
12961372
var seconds = Math.round((val[0]-nowTs)/1000);
12971373
// only get last 10 min
1298-
if (seconds < self.popoverGHist && dataFound > 10){
1374+
if (seconds < maxHis && dataFound > 10){
12991375
return false;
13001376
}
13011377
dataFound++;
@@ -1316,6 +1392,15 @@ $(function() {
13161392
};
13171393
}
13181394

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+
13191404
// Now build it
13201405
var options = {
13211406
axisX: {
@@ -1347,9 +1432,9 @@ $(function() {
13471432
scaleMinSpace: 20,
13481433
onlyInteger: true,
13491434
referenceValue: reval,
1350-
low: reval,
1435+
low: MinYVal,
13511436
},
1352-
low: reval,
1437+
low: MinYVal,
13531438
showLine: true,
13541439
showPoint: false,
13551440
showArea: false,
@@ -1426,6 +1511,9 @@ $(function() {
14261511
if (localSettings.waitForPrint()){
14271512
className += " TopTempWaitPrinter";
14281513
}
1514+
if (localSettings.hideIfNoPrinter()){
1515+
className += " TopTempHideNoPrinter";
1516+
}
14291517
}
14301518
if (self.settings.leftAlignIcons()){
14311519
className += " IconsLeft";
@@ -1471,10 +1559,25 @@ $(function() {
14711559

14721560
// Add CSS for the graphs
14731561
self.setGraphStyle = function(name,settings){
1562+
var important = "";
1563+
if (settings.forceStyle()){
1564+
important = " !important";
1565+
}
14741566
// Remove old
14751567
$('#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+
14761579
// 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>');
14781581
// Show the graph?
14791582
if (settings.show){
14801583
$('#TopTempGraph_'+name+'_graph').show();

0 commit comments

Comments
 (0)