Skip to content

feat: add scrub.snapToCandles — crosshair snaps to candle centers - #264

Merged
brandtnewlabs merged 2 commits into
brandtnewlabs:mainfrom
ianlapham:scrub-snap-candles
Aug 11, 2026
Merged

feat: add scrub.snapToCandles — crosshair snaps to candle centers#264
brandtnewlabs merged 2 commits into
brandtnewlabs:mainfrom
ianlapham:scrub-snap-candles

Conversation

@ianlapham

Copy link
Copy Markdown
Contributor

What

  • New opt-in ScrubConfig.snapToCandles (default false): quantizes the scrub X to the hovered candle's center, so the crosshair — and everything derived from it (time, tooltip, trailing dim) — jumps tick-to-tick, TradingView-style, instead of gliding.
  • Gaps between candles and line mode pass the raw X through; the Candlestick demo gains a Snap to candles switch.

Why a pure helper in crosshairShared

  • snapScrubXToCandleCenter (the inverse of computeScrubTime, then the forward mapping of the picked candle's center via pickCandleAtTime) is unit-testable under Jest; the gesture-side gate stays a thin istanbul-ignored worklet like its siblings.

Why LiveChart only

  • LiveChartSeries has no candle mode, so the flag is wired through useCrosshair's two plain-scrub call sites (startPlainScrub / updatePlainScrub) and is inert everywhere else. Default behavior is unchanged.

Test plan

  • resolveScrub default/carry cases; snap-math unit tests (center quantization across a bucket, live candle, gap + pre-history pass-through, zero-width plot/window guards); render coverage in candle and line mode with the flag on.
  • npm run verify green; coverage thresholds hold (branches 91.6, functions 95.3, lines 97.0, statements 96.2).
  • The gesture handlers are UI-thread worklets (istanbul-ignored like their siblings), so snap-while-dragging wasn't exercised under Jest; the equivalent behavior has been running in production at FOMO.

🤖 Generated with Claude Code

@brandtnewlabs

Copy link
Copy Markdown
Owner

Reviewed, fixed, and QA'd.

What I found:

  • The snap-to-candles implementation itself looks sound; I found no functional blocker in the code.
  • The public API is covered by typed JSDoc, the API reference, the scrubbing and candlestick guides, and the changelog.
  • The example app exposes the feature on the Candlestick screen with a Snap to candles toggle.
  • The merge blocker was a single CHANGELOG.md conflict with current main.

What I fixed:

  • Merged the latest main into this branch.
  • Resolved CHANGELOG.md by preserving both the candle-snapping Added entry and the existing marker/badge Fixed entries from main.
  • Pushed the resolution in commit a77fca4.

Validation:

  • npm run verify passed: typecheck, lint, and all 99 test suites (1,511 passed, 5 skipped).
  • React Doctor: 96/100, no PR-specific issues.
  • Agent-device QA passed on an iPhone 17 Pro simulator: nearby scrub positions stayed quantized to one candle center/time and then jumped discretely to the next candle; the restored app build logged no JavaScript/runtime errors.

The PR is mergeable now; CI is rerunning on the updated head.

@brandtnewlabs
brandtnewlabs merged commit 90ad6f2 into brandtnewlabs:main Aug 11, 2026
5 checks passed
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.

2 participants