Skip to content

Stop a percentage Y axis expanding past 100 - #53824

Merged
MindFreeze merged 1 commit into
devfrom
percent-axis-ceiling
Aug 27, 2026
Merged

Stop a percentage Y axis expanding past 100#53824
MindFreeze merged 1 commit into
devfrom
percent-axis-ceiling

Conversation

@MindFreeze

Copy link
Copy Markdown
Member

Proposed change

A percentage has a real ceiling the way zero is a real floor, but the gap that keeps series off the plot edges did not know that — so a battery reading 20–100% rounded out to an axis labelled up to 120%, and one sitting flat at 100% reached 160%. This recognises the unit at the two line-chart call sites and holds the axis at 100, mirroring the zero clamp already there. It applies only while the data stays under the ceiling, since power factor is also reported in % and is signed.

Stacked on #53821, which introduced the gap and the zero clamp — review that one first.

Screenshots

A battery sitting at 99%.

Before — the axis runs to 160% and roughly 40% of the plot is values a battery cannot report:

Battery history chart with a Y axis from 40 to 160 percent, the flat 99% line sitting around two thirds up the plot

After — the axis stops at 100:

The same chart with a Y axis from 40 to 100 percent, the flat 99% line just below the top gridline

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Why the unit rather than the device class

device_class would be the more precise signal, but it is not available at either call site. LineChartUnit carries it, yet state-history-charts never forwards it, and it is only populated when split_device_classes is on — which the more info dialog and the history graph card both leave off. StatisticsMetaData has no device_class field at all. The unit string is the only signal both callers already hold, and every existing percentage check in the frontend compares the bare "%" literal.

Why the clamp is conditional

% is not a 0–100 unit in general: power_factor is reported in % and core allows it to be signed. The clamp therefore fires only when the widened maximum would actually cross 100, exactly like the zero clamp only fires when the widened minimum would cross zero. A series that genuinely reads 140% is left alone.

A battery that reaches 100% then sits flush against the top edge, as the second screenshot shows. That is the intended symmetry with 0 rather than a regression — an area fill is anchored at the axis minimum, so nothing collapses at the top, and labelling an axis to 160% is the worse of the two.

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • I have followed the perfect PR recommendations
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

To help with the load of incoming pull requests:

@github-actions github-actions Bot added the Tests: Unit Related to Vitest unit tests label Aug 27, 2026
@MindFreeze
MindFreeze marked this pull request as ready for review August 27, 2026 07:11
timmo001
timmo001 previously approved these changes Aug 27, 2026
Base automatically changed from history-chart-y-axis-padding to dev August 27, 2026 12:57
A percentage has a real ceiling the way zero is a real floor, but the gap that
keeps series off the plot edges did not know that: a battery reading 20-100%
rounded out to an axis labelled up to 120%, and one sitting flat at 100% — a
device left on the charger — reached 160%.

Recognise the unit at the two line-chart call sites and hold the axis at 100,
mirroring the existing zero clamp. Only while the data stays under it, since
power factor is also reported in % and is signed.
@MindFreeze
MindFreeze merged commit 9778a54 into dev Aug 27, 2026
31 checks passed
@MindFreeze
MindFreeze deleted the percent-axis-ceiling branch August 27, 2026 14:14
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed Tests: Unit Related to Vitest unit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants