Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Incorrect Node Selected in NodeDoubleClicked Event (Read 3400 times)
Megan1717
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 39
Joined: Jun 20th, 2016
Incorrect Node Selected in NodeDoubleClicked Event
Jun 18th, 2021 at 12:38am
Print Post  
Hello,

We have customers reporting an issue when their diagrams feature nodes closely packed together. The issue is that the node they double clicked is not the node that gets selected. Instead, it is a nearby node. The event for NodeSelectedScript shows the same problem: the adjacent node (Node B) is shown as the one having been moused over when it was in fact a different node (Node A).

For background, our nodes are connected. One ShapeNode contains an image and the other contains text. The text node is attached to the image node at the bottom left corner and this forms one complete diagram node for the user's purpose.

It seems if we prevent the text node from showing, this problem does not occur, but we need users to be able to see their text nodes.

If the text node of Node A comes close to an image node of Node B, it appears that that text node of Node A takes precedence when the double click event fires even though it is quite obvious visually that the user is clicking on Node B.

Do you have any suggestions on how to resolve this issue?

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


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: Incorrect Node Selected in NodeDoubleClicked Event
Reply #1 - Jun 18th, 2021 at 5:53am
Print Post  
Hi,

This shows correct results for me -

Code
Select All
var n1 = diagram.factory.createShapeNode(10, 30, 40, 20);
n1.setText("node 1");
var n2 = diagram.factory.createShapeNode(10, 50, 40, 20);
n2.setText("node 2");
n2.attachTo(n1);

function onNodeDoubleClicked(diagram, e)
{
	alert(e.getNode().getText());
}
 



If your text node is set to Transparent, make sure its geometry isn't actually overlapping the main node's one. E.g. this will show the "node 2" text below main node, but node2's rectangle covers node1 completely and will get all double clicks -

Code
Select All
var n1 = diagram.factory.createShapeNode(10, 30, 40, 20);
n1.setText("node 1");
var n2 = diagram.factory.createShapeNode(10, 30, 40, 60);
n2.setText("node 2");
n2.setTransparent(true);
n2.attachTo(n1); 



If there's no overlapping geometries, please attach your diagram's json file.

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


I Love MindFusion!

Posts: 39
Joined: Jun 20th, 2016
Re: Incorrect Node Selected in NodeDoubleClicked Event
Reply #2 - Jun 18th, 2021 at 1:34pm
Print Post  
Hello,

Thank you for your quick reply. I am attaching sample code as requested, so you can see exactly how we create the connected nodes.

Code (Java)
Select All
float width = 128;
float height = 48;
float difference = width / 2 - 8;
float xLocation = (float)taskNode.XLocation / 2 - difference;
float yLocation = (float)taskNode.YLocation / 2 + 6;

ShapeNode textnode = diagram.Factory.CreateShapeNode(xLocation, yLocation, width, height );

textnode.Text = "Sample Text";
textnode.Id = GetNewId();
textnode.Transparent = true;
textnode.Style = nodestyle;

float innerXLocation = (float)task.XLocation / 2;
float innerYLocation = (float)task.YLocation / 2;
float innerWidth = 16;
float innerHeight = 16;

ShapeNode imagenode = diagram.Factory.CreateShapeNode(innerXLocation, innerYLocation, innerWidth, innerHeight);
imagenode.Id = textnode.Id;
imagenode.Image = GetImage();
imagenode.ImageAlign = MindFusion.Drawing.ImageAlign.Fit;
imagenode.ImagePadding = new Thickness(0);
imagenode.Transparent = true;
imagenode.EnabledHandles = AdjustmentHandles.Move;

textnode.AttachTo(textnode, AttachToNode.BottomLeft);
textnode.EnabledHandles = AdjustmentHandles.None;
textnode.HandlesStyle = HandlesStyle.Invisible;
textnode.Locked = true;
textnode.AllowIncomingLinks = false;
textnode.AllowOutgoingLinks = false;
 



Both nodes are transparent. And we are doing some calculations for the textnode that my team hasn't been able to explain why they did so exactly. I suspect the issue may lie in their code change as I don't remember this being an issue with my original code.

Any suggestions would be greatly appreciated!

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


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: Incorrect Node Selected in NodeDoubleClicked Event
Reply #3 - Jun 18th, 2021 at 2:20pm
Print Post  
It's hard to tell without knowing the taskNode.Location and task.Location values. Assuming they refer to same coordinates, this code can definitely lead to overlapping image and text nodes. I'm seeing attached image if I replace the task* location values with 100, and if you click on the overlapping area, you could get unexpected results. You can verify that with your values by commenting out the Transparent assignments. You can be sure there's no overlap by setting the image location relative to text's bottom, e.g. innerYLocation = textnode.Bounds.Bottom;

Regards,
Slavcho
  

Untitled_013.png ( 37 KB | 279 Downloads )
Untitled_013.png
Back to top
 
IP Logged
 
Megan1717
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 39
Joined: Jun 20th, 2016
Re: Incorrect Node Selected in NodeDoubleClicked Event
Reply #4 - Jun 19th, 2021 at 11:05pm
Print Post  
Hello,

"innerYLocation = textNode.Bounds.Bottom" did the trick! This would have been more obvious had we not made both nodes transparent, but now we know!

Thanks very much!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint