Skip to content

feat(price-line): add configurable hitTestTolerance option#2081

Open
sahil-tandon wants to merge 3 commits into
tradingview:masterfrom
sahil-tandon:feature/price-line-hit-test-threshold
Open

feat(price-line): add configurable hitTestTolerance option#2081
sahil-tandon wants to merge 3 commits into
tradingview:masterfrom
sahil-tandon:feature/price-line-hit-test-threshold

Conversation

@sahil-tandon

@sahil-tandon sahil-tandon commented Apr 22, 2026

Copy link
Copy Markdown

Summary

Closes #1610.

If you stack several price lines close together on a chart, hovering over one can register as a hit on a neighbor. The reason is a 7-pixel hit-test extension around each line that's hardcoded in the renderer. On desktop, where the cursor is precise, that extra padding is usually more confusing than helpful, and there's no way to tighten it.

This PR makes the value configurable per price line via a new hitTestTolerance: number on PriceLineOptions. The name matches the series-level hitTestTolerance option added in #2090, so the two hit-test surfaces stay consistent. Default stays at 7 (the historical price-line value), so existing integrations don't change. Set it to 0 on desktop for exact hits, or bump it higher for a fatter touch target on mobile.

The change

  • Adds hitTestTolerance: number to PriceLineOptions with TSDoc and @defaultValue 7.
  • Sets hitTestTolerance: 7 in priceLineOptionsDefaults.
  • HorizontalLineRenderer reads the field from its data. It falls back to 7 when the field is absent, which keeps SeriesPriceLinePaneView and SeriesHorizontalBaseLinePaneView (the two internal consumers of this renderer that aren't user-configurable) on their legacy behavior with no code change.
  • Deletes the private const enum Constants { HitTestThreshold = 7 }. The constant lives in one place now, inside the renderer module.
  • CustomPriceLinePaneView populates the new field from user options.
  • checkPriceLineOptions (dev builds only) rejects non-finite and negative values using the existing isNumber helper.

How it was tested

  • 5 unit tests in tests/unittests/price-line-options-validator.spec.ts cover the accept/reject paths, including Infinity and NaN.
  • tsc -b src/tsconfig.composite.json, eslint on the changed files, and the unit suite all pass after rebasing onto current master.

History note

Rebased onto current master to resolve a conflict in horizontal-line-renderer.ts introduced by #2090, and renamed the option from the original hitTestThreshold to hitTestTolerance for consistency with the series-level option. The runtime hit-test math is unchanged (itemY ± (lineWidth + tolerance)), so this revision is a rename plus rebase on top of the originally reviewed behavior.

PS: No graphics tests added. This change only affects hit-testing math, not pixels.

Expose the per-price-line hit-test tolerance (previously hardcoded as 7
pixels in a private const enum) via a new `hitTestTolerance` field on
PriceLineOptions. The name mirrors the series-level hitTestTolerance
option. The default remains 7, so existing integrations are unaffected.

The renderer now reads the value from HorizontalLineRendererData and
falls back to 7 when the field is absent, preserving legacy behavior for
SeriesPriceLinePaneView and SeriesHorizontalBaseLinePaneView, which
share the renderer but are not user-configurable.

Dev builds validate that the value is a non-negative number.

Refs tradingview#1610
Use the existing isNumber helper (which also rejects Infinity and NaN)
in checkPriceLineOptions. Without this, Infinity silently passed the
>= 0 check and would expand the hit area to the entire chart.

Add an explicit regression test covering Infinity and NaN.
@sahil-tandon sahil-tandon force-pushed the feature/price-line-hit-test-threshold branch from 084ea3e to 8babbe9 Compare May 23, 2026 21:38
@sahil-tandon sahil-tandon changed the title feat(price-line): add configurable hitTestThreshold option feat(price-line): add configurable hitTestTolerance option May 23, 2026
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.

Way to change price line HitTestThreshold

1 participant