Skip to content

Commit

Permalink
refactor!: change way to config graph
Browse files Browse the repository at this point in the history
BREAKING CHANGE: all config related to graph as been merged in "graphs" json
  • Loading branch information
orblazer committed Mar 29, 2024
1 parent 4875171 commit 6543475
Show file tree
Hide file tree
Showing 31 changed files with 1,557 additions and 1,568 deletions.
17 changes: 17 additions & 0 deletions debug_graphs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# CPU
[{"_v":1,"type":"cpu","colors":["highlightColor","textColor","textColor"],"sensorsType":["usage","classic",true],"clockAgregator":"average","eCoresCount":0,"thresholds":[85,105]}]

# Memory
[{"_v":1,"type":"memory","colors":["highlightColor","negativeTextColor"],"sensorsType":["physical","swap"],"thresholds":[70,90]}]

# GPU
[{"_v":1,"type":"gpu","colors":["highlightColor","positiveTextColor","textColor"],"sensorsType":["memory",true],"thresholds":[70,90],"gpuIndex":"gpu1"}]

# Network
[{"_v":1,"type":"network","colors":["highlightColor","positiveTextColor"],"sensorsType":["kibibyte"],"uplimits":[100000,100000],"ignoredInterfaces":[]}]

# Disks
[{"_v":1,"type":"disks","colors":["highlightColor","positiveTextColor"],"uplimits":[200000,200000]}]

# Full
[{"_v":1,"type":"cpu","colors":["highlightColor","textColor","textColor"],"sensorsType":["usage","classic",true],"clockAgregator":"average","eCoresCount":0,"thresholds":[85,105]},{"_v":1,"type":"memory","colors":["highlightColor","negativeTextColor"],"sensorsType":["physical","swap"],"thresholds":[70,90]},{"_v":1,"type":"gpu","colors":["highlightColor","positiveTextColor","textColor"],"sensorsType":["memory",true],"thresholds":[70,90],"gpuIndex":"gpu1"},{"_v":1,"type":"network","colors":["highlightColor","positiveTextColor"],"sensorsType":["kibibyte"],"uplimits":[100000,100000],"ignoredInterfaces":[]},{"_v":1,"type":"disks","colors":["highlightColor","positiveTextColor"],"uplimits":[200000,200000]}]
17 changes: 9 additions & 8 deletions package/contents/config/config.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import org.kde.plasma.configuration

ConfigModel {
ConfigCategory {
name: i18nc("Config header", "General")
icon: 'preferences-desktop-plasma'
source: 'config/ConfigGeneral.qml'
}
ConfigCategory {
name: i18nc("Config header", "Data")
icon: 'preferences-desktop'
source: 'config/ConfigData.qml'
name: i18nc("Config header", "Graphs")
icon: 'office-chart-line-stacked'
source: 'config/ConfigGraph.qml'
includeMargins: false
}
ConfigCategory {
name: i18nc("Config header", "Appearance")
icon: 'preferences-desktop-color'
source: 'config/ConfigAppearance.qml'
}
ConfigCategory {
name: i18nc("Config header", "Misc")
icon: 'preferences-system-other'
source: 'config/ConfigMisc.qml'
}
}
166 changes: 3 additions & 163 deletions package/contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,134 +9,16 @@
<default>1.0</default>
</entry>

<entry name="cpuUnit" type="String">
<choices>
<choice name="none" />
<choice name="usage" />
<choice name="system" />
<choice name="user" />
</choices>
<default>usage</default>
</entry>
<entry name="cpuClockType" type="String">
<choices>
<choice name="none" />
<choice name="classic" />
<choice name="ecores" />
</choices>
<default>classic</default>
</entry>
<entry name="cpuClockAgregator" type="String">
<choices>
<choice name="average" />
<choice name="minimum" />
<choice name="maximum" />
</choices>
<default>average</default>
</entry>
<entry name="showCpuTemperature" type="Bool">
<default>false</default>
</entry>

<entry name="memoryUnit" type="String">
<choices>
<choice name="none" />
<choice name="physical" />
<choice name="physical-percent" />
<choice name="application" />
<choice name="application-percent" />
</choices>
<default>physical</default>
</entry>
<entry name="memorySecondUnit" type="String">
<choices>
<choice name="none" />
<choice name="swap" />
<choice name="swap-percent" />
<choice name="memory-percent" />
</choices>
<default>swap</default>
</entry>

<entry name="networkUnit" type="String">
<choices>
<choice name="none" />
<choice name="kibibyte" />
<choice name="kilobit" />
<choice name="kilobyte" />
</choices>
<default>none</default>
</entry>

<entry name="showGpuMonitor" type="Bool">
<default>false</default>
</entry>
<entry name="gpuMemoryUnit" type="String">
<choices>
<choice name="none" />
<choice name="memory" />
<choice name="memory-percent" />
</choices>
<default>memory</default>
</entry>
<entry name="showGpuTemperature" type="Bool">
<default>false</default>
</entry>

<entry name="showDiskMonitor" type="Bool">
<default>false</default>
<entry name="graphs" type="String">
<label>Graphs order and settings in JSON format</label>
<default>[{"_v":1,"type":"cpu","colors":["highlightColor","textColor","textColor"],"sensorsType":["usage","classic",false],"clockAgregator":"average","eCoresCount":0,"thresholds":[85,105]},{"_v":1,"type":"memory","colors":["highlightColor","negativeTextColor"],"sensorsType":["physical","swap"],"thresholds":[70,90]}]</default>
</entry>

<entry name="clickActionCommand" type="String">
<default>plasma-systemmonitor</default>
</entry>
</group>

<group name="Data">
<entry name="cpuECoresCount" type="Int">
<default>0</default>
</entry>

<entry name="ignoredNetworkInterfaces" type="StringList">
</entry>
<entry name="networkReceivingTotal" type="Double">
<default>100000.0</default>
</entry>
<entry name="networkSendingTotal" type="Double">
<default>100000.0</default>
</entry>

<entry name="diskReadTotal" type="Double">
<default>200000.0</default>
</entry>
<entry name="diskWriteTotal" type="Double">
<default>200000.0</default>
</entry>

<entry name="gpuIndex" type="String">
<default>gpu0</default>
</entry>

<entry name="thresholdWarningCpuTemp" type="Double">
<default>85.0</default>
</entry>
<entry name="thresholdCriticalCpuTemp" type="Double">
<default>105.0</default>
</entry>
<entry name="thresholdWarningMemory" type="Int">
<default>70</default>
</entry>
<entry name="thresholdCriticalMemory" type="Int">
<default>90</default>
</entry>
<entry name="thresholdWarningGpuTemp" type="Int">
<default>75</default>
</entry>
<entry name="thresholdCriticalGpuTemp" type="Int">
<default>85</default>
</entry>
</group>

<group name="Appearance">
<entry name="verticalLayout" type="Bool">
<default>false</default>
Expand Down Expand Up @@ -173,48 +55,6 @@
<default>top-right</default>
</entry>

<entry name="graphOrders" type="StringList">
<default>cpu,memory,gpu,disks,network</default>
</entry>

<entry name="cpuColor" type="String">
<default>highlightColor</default>
</entry>
<entry name="cpuTemperatureColor" type="String">
<default>textColor</default>
</entry>

<entry name="memColor" type="String">
<default>highlightColor</default>
</entry>
<entry name="memSecondColor" type="String">
<default>negativeTextColor</default>
</entry>

<entry name="netDownColor" type="String">
<default>highlightColor</default>
</entry>
<entry name="netUpColor" type="String">
<default>positiveTextColor</default>
</entry>

<entry name="gpuColor" type="String">
<default>highlightColor</default>
</entry>
<entry name="gpuMemoryColor" type="String">
<default>positiveTextColor</default>
</entry>
<entry name="gpuTemperatureColor" type="String">
<default>textColor</default>
</entry>

<entry name="diskReadColor" type="String">
<default>highlightColor</default>
</entry>
<entry name="diskWriteColor" type="String">
<default>positiveTextColor</default>
</entry>

<entry name="warningColor" type="String">
<default>neutralTextColor</default>
</entry>
Expand Down
4 changes: 3 additions & 1 deletion package/contents/ui/components/functions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ export function formatByteValue(value, dialect, precision = 1) {
* @returns The color color
*/
export function resolveColor(color) {
if (color.startsWith("#")) {
if (!color) {
return undefined;
} else if (color.startsWith("#")) {
return color;
}
return _kirigamiTheme[color] || _kirigamiTheme.textColor;
Expand Down
43 changes: 17 additions & 26 deletions package/contents/ui/components/graph/CpuGraph.qml
Original file line number Diff line number Diff line change
@@ -1,64 +1,55 @@
import QtQuick
import org.kde.plasma.plasmoid
import org.kde.kirigami as Kirigami
import "./base" as RMBaseGraph
import "../sensors" as RMSensors
import "../functions.mjs" as Functions

RMBaseGraph.SensorGraph {
id: root
objectName: "CpuGraph"

// Config shrotcut
property bool showClock: Plasmoid.configuration.cpuClockType !== "none"
property bool clockIsEcores: Plasmoid.configuration.cpuClockType === "ecores"
property color temperatureColor: Functions.resolveColor(Plasmoid.configuration.cpuTemperatureColor)
// Settings
property string clockAgregator: "average" // Values: average, minimum, maximum
property int eCoresCount: 0

// Handle config update
Connections {
target: Plasmoid.configuration
function onCpuUnitChanged() {
_updateSensors();
}
}
// Config shortcut
property bool showClock: sensorsType[1] !== "none"
property bool clockIsEcores: sensorsType[1] === "ecores"

// Graph options
// NOTE: "sensorsModel.sensors" is set by "_updateSensors"
chartColor: Functions.resolveColor(Plasmoid.configuration.cpuColor)

chart.yRange {
from: 0
to: 100
}

// Labels options
thresholds: [undefined, undefined, [Plasmoid.configuration.thresholdWarningCpuTemp, Plasmoid.configuration.thresholdCriticalCpuTemp]]

thresholdIndex: 2
realThresholds: thresholds // No change needed, simply map it
textContainer {
labelColors: [root.chartColor, undefined, temperatureColor]
valueColors: [undefined, undefined, temperatureColor]
labelColors: [root.colors[0], undefined, root.colors[2]]
valueColors: [undefined, undefined, root.colors[2]]

labels: ["CPU", (showClock ? i18nc("Graph label", "Clock") : ""), (Plasmoid.configuration.showCpuTemperature ? i18nc("Graph label", "Temp.") : "")]
labels: ["CPU", (root.showClock ? i18nc("Graph label", "Clock") : ""), (root.sensorsType[2] ? i18nc("Graph label", "Temp.") : "")]
}

// CPU frequency handle
_formatValue: (index, data) => {
if (index === 1) {
return cpuFrequenry.getFormattedValue(clockIsEcores);
return cpuFrequenry.getFormattedValue(root.clockIsEcores);
}
return _defaultFormatValue(index, data);
}

RMSensors.CpuFrequency {
id: cpuFrequenry
enabled: showClock
agregator: Plasmoid.configuration.cpuClockAgregator
eCoresCount: Plasmoid.configuration.cpuECoresCount
enabled: root.showClock
agregator: root.clockAgregator
eCoresCount: root.eCoresCount

onReady: _updateSensors()
onReady: root._updateSensors()
}

function _updateSensors() {
sensorsModel.sensors = ["cpu/all/" + Plasmoid.configuration.cpuUnit, "cpu/cpu0/frequency", "cpu/cpu0/temperature"];
sensorsModel.sensors = ["cpu/all/" + sensorsType[0], "cpu/cpu0/frequency", "cpu/cpu0/temperature"];
}
}
19 changes: 2 additions & 17 deletions package/contents/ui/components/graph/DisksGraph.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,17 @@ RMBaseGraph.TwoSensorsGraph {
id: root
objectName: "DisksGraph"

// Apply dialect to uplimits
readonly property var diskIoDialect: Functions.getNetworkDialectInfo("kibibyte", i18nc)

Connections {
target: Plasmoid.configuration
function onDiskReadTotalChanged() {
_updateUplimits();
}
function onDiskWriteTotalChanged() {
_updateUplimits();
}
}
Component.onCompleted: {
_updateUplimits();
realUplimits = [uplimits[0] * diskIoDialect.multiplier, uplimits[1] * diskIoDialect.multiplier];
}

// Labels
textContainer {
labelColors: root.colors
labels: [i18nc("Graph label", "Read"), i18nc("Graph label", "Write"), ""]
}

// Graph options
sensorsModel.sensors: ["disk/all/read", "disk/all/write"]
colors: [Functions.resolveColor(Plasmoid.configuration.diskReadColor), Functions.resolveColor(Plasmoid.configuration.diskWriteColor)]

function _updateUplimits() {
uplimits = [Plasmoid.configuration.diskReadTotal * diskIoDialect.multiplier, Plasmoid.configuration.diskWriteTotal * diskIoDialect.multiplier];
}
}
Loading

0 comments on commit 6543475

Please sign in to comment.