Skip to content

Fix zero-value bar stubs (#263) and Y-axis overshoot below zero (#304) - #382

Merged
follesoe merged 2 commits into
mainfrom
fix/263-304-barchart-axis
Jul 21, 2026
Merged

follesoe merged 2 commits into
mainfrom
fix/263-304-barchart-axis

Conversation

@follesoe

Copy link
Copy Markdown
Contributor

Summary

Two BarChart / axis rendering fixes.

#263 — zero-value bars rendered a stub

BarChart.GetBarDrawingProperties used Math.Max(MinBarHeight, Abs(origin - barY)), so a zero-value bar (true height 0) was forced up to MinBarHeight (4px). The minimum is now enforced only for non-zero bars, so zero-value bars stay empty.

#304 — Y-axis could show a tick below zero (and could drop the 0 tick)

MeasureHelper.CalculateYAxis counted ticks from the nice data range (NiceScale's range output) rather than the actual [niceMin, niceMax] axis span, so the labels could overshoot below niceMin. For all-positive data this drew a gridline below zero for some max values, and dropped the 0 tick for others. Counting ticks over niceMax - niceMin makes the labels span exactly the axis every time:

data (min=0) before after
max = 510 600, 400, 200, 0, -200 600, 400, 200, 0
max = 950 1000, 800, 600, 400, 200 (no 0) 1000, 800, 600, 400, 200, 0

Verification

Closes #263.
Closes #304.

🤖 Generated with Claude Code

#263: BarChart.GetBarDrawingProperties enforced MinBarHeight on every bar,
so a zero-value bar was drawn as a 4px stub. Enforce the minimum height
only for non-zero bars.

#304: MeasureHelper.CalculateYAxis counted ticks from the nice data range
instead of the actual [niceMin, niceMax] axis span, so the labels could
overshoot below niceMin (a gridline below zero for all-positive data) or
drop the final tick. Count ticks over niceMax - niceMin so the labels span
exactly the axis.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@follesoe follesoe added the bug label Jul 21, 2026
@follesoe
follesoe requested a review from Copilot July 21, 2026 12:14
@follesoe follesoe self-assigned this Jul 21, 2026
@follesoe follesoe added this to the v2.0.0 milestone Jul 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses two BarChart/axis-rendering bugs in Microcharts: (1) preventing zero-value bars from rendering as a visible “stub”, and (2) ensuring Y-axis tick labels span exactly the computed nice axis range so the axis doesn’t overshoot below zero or drop the 0 tick.

Changes:

  • Adjust bar height enforcement so MinBarHeight is only applied to non-zero bars (fixing zero-value stubs; #263).
  • Fix Y-axis tick counting to use the [niceMin, niceMax] span rather than the “nice data range” (fixing overshoot / missing zero tick; #304).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Sources/Microcharts/Charts/BarChart.cs Changes MinBarHeight enforcement so zero-value bars stay empty, and updates bar sizing logic.
Sources/Microcharts/Helpers/MeasureHelper.cs Fixes Y-axis tick count to align tick labels with the computed nice axis bounds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Sources/Microcharts/Charts/BarChart.cs Resolved
Addresses Copilot review on #382: when enforcing MinBarHeight on a small
non-zero bar, the code compared against the chart bottom rather than the
axis origin, so a small positive bar in a mixed positive/negative range
extended below the origin into the negative area. Anchor to origin instead -
positive bars grow up from it, negative bars grow down.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@follesoe
follesoe merged commit 8a9e7da into main Jul 21, 2026
2 checks passed
@follesoe
follesoe deleted the fix/263-304-barchart-axis branch July 21, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Barchart shows Y-axis below zero while all values are positive [Bug] Show bar height with colour when entry value is zero

2 participants