tradingview / lightweight-charts

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

hoveredMarkerId for marker text within subscribeClick event #1270

Closed FairyWorld closed 1 year ago

FairyWorld commented 1 year ago

When subscribeClick is triggered by the text in the markers, the howeredMarkerId cannot be obtained. Now I have a requirement to click both the marker and the marker text to perform the processing I need to perform

SlicedSilver commented 1 year ago

If you are using the latest release (v4.0) then please be aware of this breaking change: https://tradingview.github.io/lightweight-charts/docs/migrations/from-v3-to-v4#mouseeventparams-field-hoveredmarkerid-was-renamed-to-hoveredobjectid

If this does not resolve your issue then could you please provide the following:

Related: #1267

FairyWorld commented 1 year ago

如果您使用的是最新版本 (v4.0),请注意以下重大更改:tradingview.github.io/lightweight-charts/docs/migrations/from-v3-to-v4#mouseeventparams-field-hoveredmarkerid-was-renamed-to-hoveredobjectid

  • MouseEventParams字段已重命名为hoveredMarkerId``hoveredObjectId

如果这不能解决您的问题,那么您能否提供以下内容:

  • 您正在使用的版本
  • 重现步骤
  • 一个简单的例子(jsFiddle或类似的东西)。

相关: #1267

  1. The version I am using has been upgraded to v4.0.0

  2. Here are some issues I'm having

    • I want to handle something when the marker is clicked.
    • If you click on the shape of the marker, param can get the hoveredObjectId. it's appropriate.
    • But if the text of the marker is clicked, param.hoveredObjectId is undefined. In this case, I want to be able to click on the text of the marker and get param.hoveredObjectId to handle something. The text surrounded by blue cannot judge whether the click is a marker.

image

  1. my configuration
    
    const markers = [
    {
    id: "mark1",
    time: candleStickData[10].time,
    position: "aboveBar",
    color: "#e91e63",
    shape: "circle",
    text: "mark1",
    size: 2,
    }
    ];

series.setMarkers(markers);

chart.subscribeClick((param) => { if (param.hoveredObjectId) { alert("click marker"); } });

SlicedSilver commented 1 year ago

When I tested this further, it looks like the hit box for the text of marker is incorrectly shifted to the right (as if the text wasn't adjusted to be centred).

lwc-marker-bug

Example: https://glitch.com/edit/#!/generated-fir-pomegranate