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() default 0.92 → ~4% of width per side). The candle half-width is xTickSpace / 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.
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
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)).±candleHalfWidth.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.