Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Convert Mouse Point X,Y to MM (Read 5071 times)
Megan1717
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 39
Joined: Jun 20th, 2016
Convert Mouse Point X,Y to MM
Jul 7th, 2016 at 10:04pm
Print Post  
Hello,

Sorry, but I have another question (or two)!

1. I would like to convert the mouse point (x and y coordinates) of where user clicks from pixels to millimeters (since that is the diagram's default), so I can draw a node at that location. All I need to know is how to convert the coordinate values, please.

2. Related to that question, I am using a kendo/telerik widget that has the node types displayed (similar to nodelistview). The even handler has supposedly been attached to the diagram (document.getElementById("diagramNameHere"), but it fires prematurely when the user clicks on the node in the widget. Desired behavior: The user should be able to select the node they want to draw, which triggers the widget's event handler, which in turn adds the event listener to the diagram and should then wait to draw the node until the user clicks on the canvas. Currently, it fires and draws the node as soon as the node has been selected in the widget. Is there maybe a way to check that the click occurs on the diagram to prevent it firing early?

Thanks yet again!
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Convert Mouse Point X,Y to MM
Reply #1 - Jul 8th, 2016 at 7:40am
Print Post  
Hi,

1. You can convert from pixels to diagram units using the clientToDoc method of base Canvas class. You should not need this if you handle the Clicked event raised by the diagram control when users click on an empty spot -

Code
Select All
//diagView.ClickedScript("onDiagramClicked")

function onDiagramClicked(sender, args)
{
    var diagram = sender;
    var pos = args.mousePosition;
    var node = diagram.factory.createShapeNode(
		pos.x - 20, pos.y - 10, 40, 20);
} 



2. Do you mean the widget's DOM element is located over the diagram canvas, and you are getting canvas's own mouseDown events raised when you click the widget?

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Megan1717
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 39
Joined: Jun 20th, 2016
Re: Convert Mouse Point X,Y to MM
Reply #2 - Jul 8th, 2016 at 2:55pm
Print Post  
Thanks for your quick reply. Very much appreciated. Here's an update:

1. Unfortunately, I can't rely on the Clicked event as I need to allow users to drop new nodes on top of other items. I did implement the clientToDoc method, which gets the positioning closer to where it should be, but still doesn't draw the node where the user clicks. It's also inconsistent in placement: some nodes are too far left of where they should be while others are too far to the right, and the y coordinate is off too. Suggestions for troubleshooting?

2. I placed each element in a different div row, and it became clear that the click event is picking up the x,y of where the widget was clicked. So, I will look into this other control's api and see what can be done.

As always, thanks for your time and support.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Convert Mouse Point X,Y to MM
Reply #3 - Jul 8th, 2016 at 4:09pm
Print Post  
Where are you getting the coordinates to pass to clientToDoc from? The method expects them to be relative to the top-left of diagram's canvas element. It won't work if you pass window or document-relative coordinates, unless the canvas itself is at top-left side of the window / document.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Megan1717
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 39
Joined: Jun 20th, 2016
Re: Convert Mouse Point X,Y to MM
Reply #4 - Jul 8th, 2016 at 5:06pm
Print Post  
Okay, that's the problem then. I was getting them from event.clientX & Y. So how can I get mouse position without using the Clicked handler?

Thanks.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Convert Mouse Point X,Y to MM
Reply #5 - Jul 8th, 2016 at 6:32pm
Print Post  
If you mean a MouseEvent, check if this will work -

Code
Select All
var Utils = MindFusion.Diagramming.Utils;
var clientPos = Utils.getCursorPos(event, diagram.get_element());
var diagPoint = diagram.clientToDoc(clientPos); 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Megan1717
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 39
Joined: Jun 20th, 2016
Re: Convert Mouse Point X,Y to MM
Reply #6 - Jul 8th, 2016 at 7:23pm
Print Post  
Works perfectly! Exactly what I needed! Thanks so much! Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint