Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale temperature chart based on min/max temp data #1013

Closed
wants to merge 2 commits into from

Conversation

bjpetit
Copy link
Contributor

@bjpetit bjpetit commented Dec 6, 2024

What changed?

This change scales the temperature chart to the min/max temperature data. Also, the gradient is dynamically adjusted based on the min/max temperatures.

Why did it change?

The temperature chart is more readable when scaled.

How is this tested?

Tested charts with live data from multiple nodes.
Also tested gradient adjustment against canned data.

Screenshots/Videos (when applicable)

IMG_0584

Checklist

  • My code adheres to the project's coding and style guidelines.
  • I have conducted a self-review of my code.
  • I have commented my code, particularly in complex areas.
  • I have made corresponding changes to the documentation.
  • I have tested the change to ensure that it works as intended.

Dynamically adjust gradient setup based on temp data range
@garthvh
Copy link
Member

garthvh commented Dec 10, 2024

I would like to be able to handle negative temperature numbers better, but scaling to the available data is less useful for temperature as you can't easily tell if it is hot or cold.

@jake-b
Copy link
Contributor

jake-b commented Dec 12, 2024

I am working on a more configurable EnvironmentMetricsLog view that allows you to select attributes to show in chart and table. This kind of requires using the auto-scaling Swift Charts as putting multiple metrics on one chart requires it to scale appropriately for all selected data series.

Its not quite ready for pull, but I'll mention it here in case you'd like to take a look at where it stands:

https://github.com/jake-b/Meshtastic-Apple/tree/configurable_columns

Making things dynamic adds a bit of complexity and some mildly nimble use of the type system. Still working on a few details.

@bjpetit
Copy link
Contributor Author

bjpetit commented Dec 12, 2024

I am working on a more configurable EnvironmentMetricsLog view

Nice. I'll take a look. In the meantime, if the dynamic gradient stop code is helpful feel free to grab it. I'm also going to push some other changes that I was playing with for reference.
I've also had the ...fortune? of seeing what the temp chart does when the temp drops below 0. (thanks Minnesota). I have some recommended tweaks for the Area chart that I can comment on for future reference.

y: .value("Temperature", dataPoint.temperature.localeTemperature()),
stacking: .unstacked
yStart: .value("Temperature", dataPoint.temperature.localeTemperature()),
yEnd: .value("Minimum Temperature", chartLowTemp)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will set the end for the area chart to the minimum temperature so that the area is filled in from the temp to the bottom of the chart. Otherwise the end is 0, meaning the area will be drawn from the y point to 0. For negative temp values, the area will be filled in below 0.

@@ -52,12 +58,9 @@ struct EnvironmentMetricsLog: View {
x: .value("Time", dataPoint.time!),
y: .value("Temperature", dataPoint.temperature.localeTemperature())
)
.interpolationMethod(.cardinal)
.interpolationMethod(.catmullRom)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to consider trying .catmullRom. When there are large jumps in time and value in these charts, the .cardinal interpolation can create some odd curves. .catmullRom isn't perfect, but it handles some of this a bit better.

}
}

// Set up gradient stops relative to the scale of the temperature chart
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently implemented for mapping temperature to gradient stops. But this could be used for other gradient mapping by modifying the stopTargets array elements.

@bjpetit
Copy link
Contributor Author

bjpetit commented Dec 13, 2024

Closing in favor of #1016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants