OHLC: first and last candles are clipped at the plot edges
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- java
- Domain
- data-visualization
Research direction
Start in PlotContent_OHLC.doPaint, especially the xTransform calculation and candle width handling. Reproduce the issue with a chart containing four wide candles and inspect the related test coverage from PR #991. Done means the first and last candles render fully inside the plot area without regressing the existing OHLC behavior.
Written by the indexing model from the issue text.
Description
Description
In an OHLC candlestick chart, the x-axis range is set to exactly [dataMin, dataMax]. As a result, the first and last candles are centered on the plot's left/right boundaries, so roughly half of each edge candle body extends past the plot content area and is clipped.
Reproduction
A chart with few, wide candles makes this obvious (e.g. 4 candles) — the leftmost and rightmost candle bodies are visibly cut in half by the plot border. See screenshot discussion in #734 / PR #991.
Root cause
- The first data point (
x = xMin) maps to the left edge of the tick space and the last (x = xMax) to the right edge —PlotContent_OHLC.doPaint(xTransform = xLeftMargin + ((x - xMin) / (xMax - xMin) * xTickSpace)). - Each candle is drawn centered on that point, extending
±candleHalfWidth. - The only slack is the plot-content margin (
getPlotContentSize()default0.92→ ~4% of width per side). The candle half-width isxTickSpace / xData.length / 2, which for a small number of candles greatly exceeds that margin, so the edge candles overrun the boundary.
With realistic OHLC data (many narrow candles) the overrun is a thin sliver and largely unnoticeable, which is likely why it hasn't been reported before.
Suggested fix
Pad the x-axis range (or the mapped plot area) by ~half a candle width on each side, as most candlestick charting libraries do, so the first and last candles render fully inside the plot. This should be independent of the candle count.
Notes
Discovered while adding test coverage in PR #991 (issue #734, doji candles). This clipping is a pre-existing, general OHLC rendering behavior, unrelated to the doji fix.
- Dominant language
- Java
- Stars
- 1.6k
- Forks
- 398
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from knowm/XChart
-
BoxChart rejects valid List.of data with NullPointerExceptionPossibly taken @PHJ2000 claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
X-Axis Line not visiblePossibly taken @timmolter claimed this 59 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 58/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
`CategoryChart.addSeries` could support additional call signature for interoperability with ScalaOpen
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
AnnotationsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
commonmark/commonmark-java#460 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
GoogleCloudPlatform/spring-cloud-gcp#4664 ·
Maintainers usually reply within 1 day
-
enhancement user story
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100