Commit 846aa808 authored by Arjen Hiemstra's avatar Arjen Hiemstra

Change Line Chart face X axis configuration to just a "history amount"

With the changes to have an API that determines what the update rate is
for sensors, it now becomes rather awkward to specify the number of
items a line chart should keep, since this number is dependant on the
update rate. So instead, change the line chart to have a single
configuration value indicating how much history to keep, in seconds.
This is then converted to a number of items based on the current update
rate of the sensor.
parent f59359af
......@@ -42,6 +42,9 @@
<entry name="rangeAutoY" type="Bool">
<default>true</default>
</entry>
<entry name="historyAmount" type="Int">
<default>300</default>
</entry>
</group>
</kcfg>
......@@ -39,9 +39,12 @@ Kirigami.FormLayout {
property alias cfg_rangeAutoY: rangeAutoYCheckbox.checked
property alias cfg_rangeFromY: rangeFromYSpin.value
property alias cfg_rangeToY: rangeToYSpin.value
property alias cfg_rangeAutoX: rangeAutoXCheckbox.checked
property alias cfg_rangeFromX: rangeFromXSpin.value
property alias cfg_rangeToX: rangeToXSpin.value
property alias cfg_historyAmount: historySpin.value
// For backward compatibility
property real cfg_rangeAutoX
property real cfg_rangeFromX
property real cfg_rangeToX
Item {
Kirigami.FormData.label: i18n("Appearance")
......@@ -98,25 +101,22 @@ Kirigami.FormLayout {
Kirigami.FormData.label: i18n("To (Y):")
enabled: !rangeAutoYCheckbox.checked
}
QQC2.CheckBox {
id: rangeAutoXCheckbox
text: i18n("Automatic X Data Range")
}
QQC2.SpinBox {
id: rangeFromXSpin
editable: true
from: -99999
to: 99999
Kirigami.FormData.label: i18n("From (X):")
enabled: !rangeAutoXCheckbox.checked
}
QQC2.SpinBox {
id: rangeToXSpin
id: historySpin
editable: true
from: -99999
to: 99999
Kirigami.FormData.label: i18n("To (X):")
enabled: !rangeAutoXCheckbox.checked
from: 0
to: 999999999
Kirigami.FormData.label: i18n("Amount of History to Keep:")
textFromValue: function(value, locale) {
return i18ncp("%1 is seconds of history", "%1 second", "%1 seconds", Number(value).toLocaleString(locale, "f", 0));
}
valueFromText: function(value, locale) {
// Don't use fromLocaleString here since it will error out on extra
// characters like the (potentially translated) seconds that gets
// added above. Instead parseInt ignores non-numeric characters.
return parseInt(value)
}
}
}
......@@ -34,7 +34,7 @@ Charts.LineChart {
//property var sensors: root.controller.highPrioritySensorIds
readonly property alias sensorsModel: sensorsModel
property int maximumHistory: root.controller.faceConfiguration.rangeToX - root.controller.faceConfiguration.rangeFromX
readonly property int historyAmount: root.controller.faceConfiguration.historyAmount
direction: Charts.XYChart.ZeroAtEnd
......@@ -45,11 +45,6 @@ Charts.LineChart {
//TODO: Have a central heading here too?
//TODO: Have a plasmoid config value for line thickness?
xRange {
from: root.controller.faceConfiguration.rangeFromX
to: root.controller.faceConfiguration.rangeToX
automatic: root.controller.faceConfiguration.rangeAutoX
}
yRange {
readonly property bool stackedAuto: root.controller.faceConfiguration.rangeAutoY && root.controller.faceConfiguration.lineChartStacked
from: stackedAuto ? Math.min(sensorsModel.minimum, 0) : root.controller.faceConfiguration.rangeFromY
......@@ -88,13 +83,16 @@ Charts.LineChart {
Instantiator {
model: sensorsModel.sensors
delegate: Charts.ModelHistorySource {
model: sensorsModel
column: index
row: 0
roleName: "Value"
maximumHistory: chart.maximumHistory
interval: 2000
delegate: Charts.HistoryProxySource {
source: Charts.ModelSource {
model: sensorsModel
column: index
roleName: "Value"
}
interval: sensorsModel.ready ? sensorsModel.headerData(index, Qt.Horizontal, Sensors.SensorDataModel.UpdateInterval) : 0
maximumHistory: interval > 0 ? (chart.historyAmount * 1000) / interval : 100
fillMode: Charts.HistoryProxySource.FillFromEnd
}
onObjectAdded: {
chart.insertValueSource(index, object)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment