Commit 8c2ee2c2 authored by David Redondo's avatar David Redondo 🏎
Browse files

Calculate the maximum data range if the chart is stacked and in automatic mode

We don't want the scale of the chat to be constantly resized but to be maximum
of all stacked sensors. The maximum values of all sensors are summed up to form
the maixmum. If the sensorModel doesn't provide a minimum or maximum we still defer
to quickcharts automatic mode.
parent c26061d0
......@@ -53,14 +53,39 @@ Charts.LineChart {
automatic: root.controller.faceConfiguration.rangeAutoX
}
yRange {
from: root.controller.faceConfiguration.rangeFromY
to: root.controller.faceConfiguration.rangeToY
automatic: root.controller.faceConfiguration.rangeAutoY
readonly property bool stackedAuto: root.controller.faceConfiguration.rangeAutoY && root.controller.faceConfiguration.lineChartStacked
from: stackedAuto ? Math.min(sensorsModel.minimum, 0) : root.controller.faceConfiguration.rangeFromY
to: stackedAuto ? sensorsModel.stackedMaximum : root.controller.faceConfiguration.rangeToY
automatic: (root.controller.faceConfiguration.rangeAutoY && !root.controller.faceConfiguration.lineChartStacked)
|| stackedAuto && yRange.from == yRange.to
}
Sensors.SensorDataModel {
id: sensorsModel
sensors: root.controller.highPrioritySensorIds
property double stackedMaximum: yRange.stackedAuto ? calcStackedMaximum() : 0
function calcStackedMaximum() {
let max = 0
for (let i = 0; i < sensorsModel.sensors.length; ++i) {
max += sensorsModel.data(sensorsModel.index(0, i), Sensors.SensorDataModel.Maximum)
}
return max
}
}
Connections {
target: sensorsModel
enabled: yRange.stackedAuto
function onColumnsInserted() {
sensorsModel.stackedMaximum = sensorsModel.calcStackedMaximum()
}
function onColumnsRemoved() {
sensorsModel.stackedMaximum = sensorsModel.calcStackedMaximum()
}
function onSensorMetaDataChanged() {
sensorsModel.stackedMaximum = sensorsModel.calcStackedMaximum()
}
}
Instantiator {
......
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