Skip to content

Commit

Permalink
Fixed non centered text #52. Improved javascript lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
LazeMSS committed Aug 24, 2021
1 parent 9847477 commit 642d7e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
16 changes: 8 additions & 8 deletions octoprint_toptemp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self):

# List of psu
self.psutilList = {
'cpup' : ['CPU usage percentage'],
'cpup' : ['CPU usage %'],
'cpuf' : ['CPU frequency in MHz'],
'loadavg1' : ['Average system load last 1 minute'],
'loadavg5' : ['Average system load last 5 minutes'],
Expand All @@ -47,11 +47,11 @@ def __init__(self):
'memavail' : ['Total available memory in MB'],
'memused' : ['Memory used in MB'],
'memfree' : ['Memory not being used at all in MB'],
'memp' : ['Memory free percentage'],
'memp' : ['Memory free %'],
'swaptotal' : ['Total swap memory in MB'],
'swapused' : ['Used swap memory in MB'],
'swapfree' : ['Free swap memory in MB'],
'swapperc' : ['Free swap percentage']
'swapperc' : ['Free swap %']
}

# Gcode handling
Expand Down Expand Up @@ -361,10 +361,10 @@ def buildPsuUtil(self):
partitions = [partition._asdict() for partition in psutil.disk_partitions()]
count = 0
for partition in partitions:
self.psutilList['diskfree_'+str(count)] = ["Disk free "+partition['mountpoint'],partition['mountpoint']]
self.psutilList['disktotal_'+str(count)] = ["Disk total "+partition['mountpoint'],partition['mountpoint']]
self.psutilList['diskused_'+str(count)] = ["Disk used "+partition['mountpoint'],partition['mountpoint']]
self.psutilList['diskperc_'+str(count)] = ["Disk used percent "+partition['mountpoint'],partition['mountpoint']]
self.psutilList['diskfree_'+str(count)] = ["Disk free \""+partition['mountpoint']+"\"",partition['mountpoint']]
self.psutilList['disktotal_'+str(count)] = ["Disk total \""+partition['mountpoint']+"\"",partition['mountpoint']]
self.psutilList['diskused_'+str(count)] = ["Disk used \""+partition['mountpoint']+"\"",partition['mountpoint']]
self.psutilList['diskperc_'+str(count)] = ["Disk used % \""+partition['mountpoint']+"\"",partition['mountpoint']]
count += 1

# temperatures
Expand Down Expand Up @@ -403,7 +403,7 @@ def buildPsuUtil(self):
if hasattr(psutil, "sensors_battery"):
battery = psutil.sensors_battery()
if battery:
self.psutilList['batper'] = ["Battery power left percentage"]
self.psutilList['batper'] = ["Battery power left %"]
self.psutilList['batsec'] = ["Battery power left seconds"]

self.debugOut(self.psutilList)
Expand Down
29 changes: 17 additions & 12 deletions octoprint_toptemp/static/js/TopTemp.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ $(function() {
'gcOut': {
'Cooling fan speed' : '^M106.*?S([^ ]+)',
'Feedrate %' : '^M220 S([^ ]+)',
'% Completed' : '^M73.*?P(\\d+)',
// 'Extruder feed rate' : '^(?:G0|G1).*?F([^ ]+)'
}
};
Expand Down Expand Up @@ -101,7 +102,7 @@ $(function() {
}
}else{
var reval = 0;
graphData = {'series' : [OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[name].actual.slice(-300).map(function(val,i){return val[1]})]};
graphData = {'series' : [self.tempModel.temperatures[name].actual.slice(-300).map(function(val,i){return val[1]})]};
}
// DO we have what we need
if (graphData != null && typeof Chartist == "object"){
Expand Down Expand Up @@ -1143,8 +1144,8 @@ $(function() {
$('#TopTempPopoverText_'+$thisID).html(output);
}
}else{
var actual = OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].actual[OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].actual.length-1][1];
var target = OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].target[OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].target.length-1][1];
var actual = self.tempModel.temperatures[$thisID].actual[self.tempModel.temperatures[$thisID].actual.length-1][1];
var target = self.tempModel.temperatures[$thisID].target[self.tempModel.temperatures[$thisID].target.length-1][1];
var output = '<div class="pull-left"><small>Actual: '+self.formatTempLabel($thisID,actual,iSettings)+'</small></div><div class="pull-right"><small>Target: ';
if (target == 0){
output += 'Off';
Expand Down Expand Up @@ -1261,8 +1262,8 @@ $(function() {
// Assign it
graphData = {
'series' : [
{'data':buildSeries([...OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].actual]),'className':'ct-series-a'},
{'data':buildSeries([...OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[$thisID].target]),'className':'ct-series-g'},
{'data':buildSeries([...self.tempModel.temperatures[$thisID].actual]),'className':'ct-series-a'},
{'data':buildSeries([...self.tempModel.temperatures[$thisID].target]),'className':'ct-series-g'},
]
};
}
Expand Down Expand Up @@ -1367,33 +1368,37 @@ $(function() {
// Build a single container
self.buildContainer = function(name,className){
var elname = 'navbar_plugin_toptemp_'+name;
var settings = self.getSettings(name);
var localSettings = self.getSettings(name);
// Get name
prettyName = self.getTempName(name);
// Set type
var isCust = false;
if (self.isCustom(name)){
isCust = true;
if (settings.waitForPrint()){
if (localSettings.waitForPrint()){
className += " TopTempWaitPrinter";
}
}
if (self.settings.leftAlignIcons()){
className += " IconsLeft";
}
var textClass = "TopTempText";
if (!localSettings.graphSettings.show() && !localSettings.icon()){
textClass = "navbar-text";
}
// Remove old
$('#'+elname).remove();
// Build new
$('#navbar_plugin_toptemp').append('<div title="'+prettyName+'" id="'+elname+'" class="'+className+'" data-toptempid="'+name+'" data-toptempcust="'+isCust+'"><div id="TopTempGraph_'+name+'_graph" class="TopTempGraph"></div><div id="navbar_plugin_toptemp_'+name+'_text" class="TopTempText"></div></div>');
if (!settings.show()){
$('#navbar_plugin_toptemp').append('<div title="'+prettyName+'" id="'+elname+'" class="'+className+'" data-toptempid="'+name+'" data-toptempcust="'+isCust+'"><div id="TopTempGraph_'+name+'_graph" class="TopTempGraph"></div><div id="navbar_plugin_toptemp_'+name+'_text" class="'+textClass+'"></div></div>');
if (!localSettings.show()){
$('#'+elname).hide();
}
// Set fixed width if entered
if (settings.width() > 0){
$('#'+elname).css({'width':settings.width()+'px'});
if (localSettings.width() > 0){
$('#'+elname).css({'width':localSettings.width()+'px'});
}

self.setGraphStyle(name,settings.graphSettings);
self.setGraphStyle(name,localSettings.graphSettings);
return elname;
}

Expand Down

0 comments on commit 642d7e1

Please sign in to comment.