Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMcInnes committed Jul 12, 2023
1 parent e9ca0ac commit 6a634f3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
44 changes: 22 additions & 22 deletions pages/BriefMonitorPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -216,42 +216,40 @@ exported power v 0.4 | /

// If we have ever seen power exported to the grid, the graph shows imported and exported power, as in Graph B.
// Otherwise, we only show imported power, as in Graph A.
readonly property bool graphShowsExportPower: inputsPower.minimumSeen && inputsPower.minimumSeen < 0
property bool graphShowsExportPower: false

// If we show export power, the minimum scale of the y axis goes from -1000W to +1000W
// If we don't show export power, the minimum scale of the y axis goes from 0W to +1000W
readonly property real minimumRangeWatts: graphShowsExportPower
? Theme.animation.loadGraph.minimumRange.watts * 2
: Theme.animation.loadGraph.minimumRange.watts

// This represents the difference in power between y=0 and y=1
readonly property real graphPowerRange: {
const peakPowerImportedOrExported = Math.max(Math.abs(inputsPower.maximumSeen), Math.abs(inputsPower.minimumSeen))
return graphShowsExportPower
? Math.max(2 * peakPowerImportedOrExported, minimumRangeWatts)
: Math.max(inputsPower.maximumSeen, minimumRangeWatts)
}
property real _oldGraphPowerRange: NaN

// in Graph A, when the graph is at y=0.0, power is zero.
// in Graph B, when the graph is at y=0.5, power is zero.
readonly property real normalizedZeroPowerPoint: graphShowsExportPower ? 0.5 : 0.0
function addNewValue() {
graphShowsExportPower = inputsPower.minimumSeen < 0

readonly property real normalizedPower: (inputsPower.value / graphPowerRange) + normalizedZeroPowerPoint
// If we show export power, the minimum scale of the y axis goes from -1000W to +1000W
// If we don't show export power, the minimum scale of the y axis goes from 0W to +1000W
const minimumRangeWatts = graphShowsExportPower
? Theme.animation.loadGraph.minimumRange.watts * 2
: Theme.animation.loadGraph.minimumRange.watts
const peakPowerImportedOrExported = Math.max(Math.abs(inputsPower.maximumSeen), Math.abs(inputsPower.minimumSeen))
const graphPowerRange = graphShowsExportPower // This represents the difference in power between y=0 and y=1 on the graph
? Math.max(2 * peakPowerImportedOrExported, minimumRangeWatts)
: Math.max(inputsPower.maximumSeen, minimumRangeWatts)

property real _oldGraphPowerRange: NaN
// in Graph A, when the graph is at y=0.0, power is zero.
// in Graph B, when the graph is at y=0.5, power is zero.
const normalizedZeroPowerPoint = graphShowsExportPower ? 0.5 : 0.0
const normalizedPower = (inputsPower.value / graphPowerRange) + normalizedZeroPowerPoint

function addNewValue() {
if (_oldGraphPowerRange != graphPowerRange) {
if (!isNaN(_oldGraphPowerRange)) {
const scalingFactor = graphPowerRange / _oldGraphPowerRange
scaleHistoricalData(scalingFactor)
scaleHistoricalData(scalingFactor, normalizedZeroPowerPoint)
}
_oldGraphPowerRange = graphPowerRange
}
addValue(normalizedPower)
normalizedPowerSlider.value = normalizedPower
}

function scaleHistoricalData(scalingFactor) {
function scaleHistoricalData(scalingFactor, normalizedZeroPowerPoint) {
// If our historical power data was like this: [-1000, 1000, -1000, 1000, ...], and inputsPower.minimumSeen === -1000,
// and inputsPower.maximumSeen === 1000, our graph 'y' values would be like this: [-1, 0, -1, 1, ...]
// If we then got a new power import reading of 5000W, we need to scale down all of the historical data by
Expand Down Expand Up @@ -312,6 +310,8 @@ exported power v 0.4 | /
}
}
Slider {
id: normalizedPowerSlider

enabled: false // not interactive
width: parent.width
height: Theme.geometry.briefPage.sidePanel.generator.slider.height
Expand Down
2 changes: 1 addition & 1 deletion src/veutil

0 comments on commit 6a634f3

Please sign in to comment.