lightweight-charts icon indicating copy to clipboard operation
lightweight-charts copied to clipboard

Add priceline events support

Open gerardo-contijoch opened this issue 2 years ago • 2 comments

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.

gerardo-contijoch avatar Jul 20 '22 13:07 gerardo-contijoch

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

kirchet avatar Jul 20 '22 17:07 kirchet

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

gerardo-contijoch avatar Jul 20 '22 18:07 gerardo-contijoch