tradingview / lightweight-charts

Performant financial charts built with HTML5 canvas
https://www.tradingview.com/lightweight-charts/
Apache License 2.0
9.33k stars 1.61k forks source link

Add priceline events support #1129

Closed gerardo-contijoch closed 1 year ago

gerardo-contijoch commented 2 years ago

I have a project where I need to be able to react to clicks on pricelines.

I know I can add a new priceline and setup several of its options but I need to be able to remove it when the user clicks on it.

Also I would like to be able to change the cursor or show a floating pane when the user hovers over a priceline so the user can see information about that price. Obviously, the code for the floating pane would be custom code, not something integrated in the library.

I guess this could be achieved if MouseEventParams interface is updated with a property hoveredPriceLine. This way simply by calling chart.subscribeClick(param) and chart.subscribeCrosshairMove(param) we could implement the required logic.

kirchet commented 2 years ago

We already have the field to store a hovered marker id

https://github.com/tradingview/lightweight-charts/blob/d4863ffc1c0988b2d9b03744d28bdfbdc2ca989e/src/api/ichart-api.ts#L53-L56

These ids can be provided via optional fileld

https://github.com/tradingview/lightweight-charts/blob/d4863ffc1c0988b2d9b03744d28bdfbdc2ca989e/src/model/series-markers.ts#L33-L36

Probably we can add an additional optional field id in PriceLineOptions and rename the field hoveredMarkerId to hoveredObjectId so we can provide not only a marker id but a custom price line id too

gerardo-contijoch commented 2 years ago

I like @kirchet suggestion, it leaves place for future expansion.