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

How to enable/disable crosshair on desktop #390

Closed fhassis closed 4 years ago

fhassis commented 4 years ago

Is it possible to enable/disable the crosshair on desktop? I can do this on mobile browser enabling by holding on the chart, and double clicking the chart to disable it. How can I have the same behavior on desktop?

timocov commented 4 years ago

I can do this on mobile browser enabling by holding on the chart, and double clicking the chart to disable it. How can I have the same behavior on desktop?

I'm not sure that having on desktop the same behaviour would be good for an user. Right now you need to just move mouse under the chart to use cross hair. It could be disabled by its options (see https://github.com/tradingview/lightweight-charts/blob/v2.0.0/docs/customization.md#crosshair).

fhassis commented 4 years ago

I uderstand your point. What I really need is to be able to drag horizontal lines on the chart, and I thought I could "emulate" this behavior by changing styles of the crosshair. For example, if the user holds on the chart, I could enable both the horizontal line and label, and hide the vertical line and label). Then the user drags the "line" to the price desired, and when it "drops" the line, the current price of the crosshair is taken. I noticed that the crosshair mouse event is fired even when the lines are disabled, and that was other point of my question. But I can surely ignore it when the lines are hidden. Thank you very much for your quick response.

timocov commented 4 years ago

What I really need is to be able to drag horizontal lines on the chart, and I thought I could "emulate" this behavior by changing styles of the crosshair.

What's wrong with the default behaviour we currently have? 🙂 Why it doesn't fit for your requirements?

I noticed that the crosshair mouse event is fired even when the lines are disabled, and that was other point of my question. But I can surely ignore it when the lines are hidden.

That's a good question. The answer is I don't know :) I don't know how it should be either. I meant it depends on how we treat that event.

fhassis commented 4 years ago

Please don't get me wrong. Your default behavior is perfect. By the way, this library is just amazing! I was struggling with other candlestick libraries to adjust the interactivity to what I need, and this library has all of it by default :) I am new to JavaScript, so I thought that using the default crosshair and modifying its style would be easier than really dragging the pricelines. I will investigate this option with more detail now. If you could suggest me how I could be able to select and then drag an existent price line on the chart, that would be awesome.

timocov commented 4 years ago

Please don't get me wrong. Your default behavior is perfect. By the way, this library is just amazing!

Oh, I'm sorry if I confused you in any way.

If you could suggest me how I could be able to select and then drag an existent price line on the chart, that would be awesome.

I'm afraid we don't have that right now (and I'm not sure whether we plan to add it either).

fhassis commented 4 years ago

No problem. Thank you!