Pad OHLC x-axis range so edge candles are not clipped - #1027
Open
timmolter wants to merge 1 commit into
Open
Conversation
The x-axis range spanned exactly [dataMin, dataMax], centering the first and last candles on the plot boundaries and clipping half of each edge candle body. The only slack was the plot-content margin (~4% per side), which the candle half-width (xTickSpace / candleCount / 2) greatly exceeds for small candle counts. Pad the auto-computed range by half the candle spacing per side in AxisPair.overrideMinMaxForXAxis(), next to the existing horizontal-bar outside-labels padding. One candle period then maps to exactly the candle width PlotContent_OHLC draws, so edge candles fit fully. The spacing is the widest per-series median of consecutive x-deltas: median so weekend/holiday gaps in date data don't inflate the estimate, widest because the series with the fewest candles draws the widest bodies. Line-style OHLC series have no width and don't trigger padding, nor do logarithmic x-axes (padding would have to be multiplicative). Manual styler min/max overrides still win, as they are applied afterwards. Fixes #992 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #992.
Problem
The OHLC x-axis range spanned exactly
[dataMin, dataMax], so the first and last candles were centered on the plot's left/right boundaries and roughly half of each edge candle body was clipped. The only slack was the plot-content margin (~4% of width per side), which the candle half-width (xTickSpace / candleCount / 2) greatly exceeds for small candle counts — with 4 candles, half of each edge body is cut off. With many narrow candles the overrun is a sliver, which is why this went unnoticed.Fix
Pad the auto-computed x-axis range by half the candle spacing per side in
AxisPair.overrideMinMaxForXAxis(), next to the existing horizontal-bar outside-labels padding. This spot fixes all consumers at once — ticks, grid lines, cursor, tooltips, and annotations share the[min,max] → tickSpacetransform, so a painter-only remap would have desynced candles from their tick labels.The padding also makes the geometry self-consistent: the range becomes
candleCount · spacing, so one candle period maps to exactly the candle widthPlotContent_OHLCalready draws — no painter changes needed.Details:
Line-style OHLC series have no width and don't trigger padding.styler.setXAxisMin()/Max()still win — they are applied afterwards.Tests
OhlcEdgeCandlePaddingTest: headless pixel-scan test (noXChartPanel) asserting no candle pixels touch the plot's boundary columns. Fails without the fix ("no candle pixels may touch the plot's left/right boundary columns"), passes with it.🤖 Generated with Claude Code