feat: Add findNearest second arg to TimeScale#timeToCoordinate() #1458
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.
Type of PR: Bugfix/Feature
PR checklist:
Overview of change:
There's currently a pretty major limitation with
TimeScale#timeToCoordinate()
If you have data that's of a smaller interval than the timescale,
timeToCoordinate()
always returns null even though internally it still performs the binary search and finds the correct closest index.I think in this scenario it'd be much better to return the closest bar than it is to return nothing at all. Or, at the very least allow the user the option of choosing by adding a second argument to
timeToCoordinate()
.Personally, I'd be ok with defaulting
findNearest
totrue
instead offalse
, since I doubt anyone would be surprised if it returns the containing bar/index instead ofnull
, but at least with an argument the user has the option.Additional context
My simple use case: I am writing custom pane views to show order markers. Even if the main series is set to daily bars or higher I'd still like to be able to show the orders.