This is a migrated thread and some comments may be shown as answers.

Get cursor position

5 Answers 363 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Edward
Top achievements
Rank 1
Veteran
Iron
Edward asked on 21 Mar 2021, 11:31 AM
Can we get cursor position on diagram while clicking (or even not clicking) on the diagram canvas like e.point in click event?

5 Answers, 1 is accepted

Sort by
0
Georgi Denchev
Telerik team
answered on 24 Mar 2021, 11:36 AM

Hello, Edward,

You could use javascript events such as mousemove or click to get the coordinates of the pointer when clicking on the diagram.

$("#diagram").kendoDiagram({
   ...options
})

// get X and Y coordinates of the pointer on click.
$("#diagram").on("click", function (e) {
    console.log(e.offsetX)
    console.log(e.offsetY)
});

Let me know if you have any questions.

Best Regards,
Georgi Denchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Edward
Top achievements
Rank 1
Veteran
Iron
answered on 25 Mar 2021, 06:32 AM

Hi Georgi,

Thanks for the reply, but what I need is the coordinates in the diagram widget (the coordinates that you draw shapes), like e.point in diagram's click event. Can I get that somewhere or can I calculate it myself with the coordinates you have mentioned?

0
Georgi Denchev
Telerik team
answered on 29 Mar 2021, 03:03 PM

Hello, Edward,

I am not certain I understand, using the method below you can obtain the X and Y coordinates of the clicked point on the entire diagram widget.

You can test it in the following dojo:

https://dojo.telerik.com/@gdenchev/ahuQICOc

Clicking on one of the shapes is going to call the Diagram.click() event(where you can access e.point) and it is also going to call the Custom event function that I provided. Both are going to return the same value, except the Custom event is going to work outside of the shapes/connectors as well.

The result can be observed in the Browser Console(F12).

Could you please provide me with a bit more details if this is not the functionality you are looking for?

Best Regards,
Georgi Denchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Edward
Top achievements
Rank 1
Veteran
Iron
answered on 30 Mar 2021, 05:17 AM

Hi Georgi,

They are actually not the same value, zoom in the diagram and you will see the difference I talked about.

Thanks!

0
Accepted
Georgi Denchev
Telerik team
answered on 01 Apr 2021, 02:49 PM

Hello, Edward,

Thank you for the clarification.

You can use the diagram's internal _eventPositions() method to get the click coordinates in the same manner as the click event.

I have updated the dojo:

https://dojo.telerik.com/@gdenchev/ahuQICOc

Let me know in case further assistance is required.

Best Regards,
Georgi Denchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Diagram
Asked by
Edward
Top achievements
Rank 1
Veteran
Iron
Answers by
Georgi Denchev
Telerik team
Edward
Top achievements
Rank 1
Veteran
Iron
Share this question
or