Skip to content

fix(chart): keep candles at normal width when few bars exist - #48

Open
niravpatidar37 wants to merge 1 commit into
ErTasselli:mainfrom
niravpatidar37:fix/chart-bar-width
Open

niravpatidar37 wants to merge 1 commit into
ErTasselli:mainfrom
niravpatidar37:fix/chart-bar-width

Conversation

@niravpatidar37

Copy link
Copy Markdown

Problem

On short histories the chart calls timeScale().fitContent(), which stretches however many bars exist across the whole panel. Early in the session this is very visible: at 10:30 ET a 1D chart has about 13 five-minute bars, so each candle is drawn about 70 px wide. They only look normal near the close. New listings with little history on longer ranges get the same giant bars.

Fix

One file, web/components/widgets/ChartWidget.tsx. When there are fewer bars than a minimum, set the visible logical range instead of fitting:

  • 1D: reserve the full 9:30–16:00 session, which is 78 five-minute slots. The day fills in left to right, like a normal terminal intraday chart.
  • Other ranges: reserve at least 60 slots.
  • Otherwise: fitContent() as before.

The range starts at -1.5 so the first candle isn't clipped at the left edge.

Verification

  • next build (lint + types) and tsc are clean on main, and the 26 existing tests pass.
  • Measured in headless Chromium on SPY 1D at 10:35 ET (13 bars): candle bodies are 7 px wide, against about 70 px before. Screenshots were checked to confirm the first candle is fully visible and the axis extends into the afternoon.
  • Ranges with enough bars (5D and up, crypto 1D with 288 bars) still use fitContent(), so they're unchanged.

Notes

Security impact: none. This is client-side chart viewport logic only, with no new inputs, network calls or rendering of external data.

fitContent() stretched early-session 1D data (e.g. 13 five-minute bars at
10:30) across the whole panel, producing ~70 px candles. Reserve the full
9:30-16:00 session (78 slots) on 1D, and at least 60 slots elsewhere, so
the chart fills in left to right like a normal terminal.
niravpatidar37 added a commit to niravpatidar37/OpenTerminal that referenced this pull request Oct 20, 2026
fitContent() stretched early-session 1D data (e.g. 13 five-minute bars at
10:30) across the whole panel, producing ~70 px candles. Reserve the full
9:30-16:00 session (78 slots) on 1D, and at least 60 slots elsewhere, so
the chart fills in left to right like a normal terminal.

Squash of fix/chart-bar-width (also proposed alone as ErTasselli#48).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant