implement () event.
This commit is contained in:
@ -22,6 +22,11 @@ Fires when the range (visibleLogicalRange) changes.
|
||||
|
||||
```
|
||||
|
||||
```{py:method} click -> (chart: Chart, time: NUM, price: NUM)
|
||||
Fires when the mouse is clicked, returning the time and price of the clicked location.
|
||||
|
||||
```
|
||||
|
||||
````
|
||||
|
||||
Tutorial: [Topbar & Events](../tutorials/events.md)
|
||||
|
||||
@ -159,4 +159,15 @@ class Events:
|
||||
wrapper=lambda o, c, *arg: o(c, *[float(a) for a in arg])
|
||||
)
|
||||
|
||||
|
||||
self.click = JSEmitter(chart, f'subscribe_click{salt}',
|
||||
lambda o: chart.run_script(f'''
|
||||
let clickHandler{salt} = (param) => {{
|
||||
if (!param.point) return;
|
||||
const time = {chart.id}.chart.timeScale().coordinateToTime(param.point.x)
|
||||
const price = {chart.id}.series.coordinateToPrice(param.point.y);
|
||||
window.callbackFunction(`subscribe_click{salt}_~_${{time}};;;${{price}}`)
|
||||
}}
|
||||
{chart.id}.chart.subscribeClick(clickHandler{salt})
|
||||
'''),
|
||||
wrapper=lambda func, c, *args: func(c, *[float(a) for a in args])
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user