feat(price-line): add configurable hitTestTolerance option#2081
Open
sahil-tandon wants to merge 3 commits into
Open
feat(price-line): add configurable hitTestTolerance option#2081sahil-tandon wants to merge 3 commits into
sahil-tandon wants to merge 3 commits into
Conversation
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.
084ea3e to
8babbe9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: numberonPriceLineOptions. The name matches the series-levelhitTestToleranceoption 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
hitTestTolerance: numbertoPriceLineOptionswith TSDoc and@defaultValue 7.hitTestTolerance: 7inpriceLineOptionsDefaults.HorizontalLineRendererreads the field from its data. It falls back to 7 when the field is absent, which keepsSeriesPriceLinePaneViewandSeriesHorizontalBaseLinePaneView(the two internal consumers of this renderer that aren't user-configurable) on their legacy behavior with no code change.const enum Constants { HitTestThreshold = 7 }. The constant lives in one place now, inside the renderer module.CustomPriceLinePaneViewpopulates the new field from user options.checkPriceLineOptions(dev builds only) rejects non-finite and negative values using the existingisNumberhelper.How it was tested
tests/unittests/price-line-options-validator.spec.tscover the accept/reject paths, includingInfinityandNaN.tsc -b src/tsconfig.composite.json,eslinton the changed files, and the unit suite all pass after rebasing onto currentmaster.History note
Rebased onto current
masterto resolve a conflict inhorizontal-line-renderer.tsintroduced by #2090, and renamed the option from the originalhitTestThresholdtohitTestTolerancefor 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.