Link drag is offset from node shape

Hi Walter,

I think I'm having a problem related to the previous problem. When I drag the link out from the node and the blue arrow indicator appears, it seems like it is offset from my mouse position. Any ideas? The problem is if I set the PortGravity lower, if the user drags their mouse over the node they want to connect to, it doesn't light up for a connection to the destination node. The problem seems worse the farther the node is from the upper left hand corner.

I haven’t noticed any problems with the LinkingTool not having the end of the proposed link follow the mouse.

But if you decrease the LinkingTool.PortGravity, the mouse point has to be closer to the node’s “port” element(s). For example, you’ll notice that the DraggableLink sample sets that property to 20. This is useful because there are little port elements present on each node in addition to the big Shape.

this problem reminds me of the one I was having when I couldn’t select nodes when they were far from the origin, but seemed to go away in version 1.2.2 . Unfortunatly, this is a big problem, because now if the node is far enough out the linking tool can’t even find the node even if I force the link to go right on the node. This pretty much renders the tool unusable, so I need a way, even if I have to do the finding of the node in an override, to customize the behavior to fix it. Maybe it has something to do with being inside of Prism?

I’ve never seen or heard of a problem like that.
Do you have minimal application that demonstrates the problem?

You haven’t customized the LinkingTool, have you?

Hi Walter,
It is a strange problem. By the way, I assume the port gravity goes from 0-100? What is the default? If I get a chance, I'll see if I can duplicate it with a sample app. setting the port gravity to around 60 seems to hide the problem for now.

Here is my Custom Link Tool, but I was having the problem before I customized it.

using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Northwoods.GoXam; using Northwoods.GoXam.Tool; namespace MyNamespace { public class CustomLinkingTool : LinkingTool { public CustomLinkingTool() : base() { PortGravity = 60; }

protected override bool IsBeyondDragSize()
{
Diagram diagram = this.Diagram;
if (diagram == null) return false;
DiagramPanel panel = diagram.Panel;
if (panel == null) return false;
// Get all of the points in screen/view coordinates
Point first = panel.TransformModelToView(diagram.FirstMousePointInModel);
Point last = panel.TransformModelToView(diagram.LastMousePointInModel);
return IsBeyondDragSize(panel, last, first);
}

public static bool IsBeyondDragSize(DiagramPanel panel, Point a, Point b)
{
if (Math.Abs(b.X - a.X) <= 2)
{
return (Math.Abs(b.Y - a.Y) > 2);
}
return true;
}

The LinkingTool.PortGravity is a distance value, not a percentage. The default value is 100. You would not want to use a value of zero. Even a value of 2 is probably not easy to use.

This value is passed as the second argument to DiagramPanel.FindElementsNear.

ah okay. I had settled on 50.

I think I have another clue to the offset problem.

1) It seems more pronounced in IE than Firefox.
2) It seems to get significantly worse if you zoom the browser itself. If the browser is its normal zoom size, the problem is a lot better.

That’s strange.

I just tried drawing new links in the DraggableLink sample of the GoSilverlightDemo (Silverlight 4) at www.goxam.com, using both Internet Explorer 8 and Firefox 3.6.

I tried both at normal page “zoom”, at 50%, and at 200% in both browsers, and at different Diagram scales. (The Diagram.Panel.Scale does not automatically change to follow the page zoom level.)

I never saw odd behavior when linking – the proper port always got highlit, and upon mouse-up the new link connected to the proper port.

Thanks Walter,
I had our tester try it, just to make sure I wasn't crazy
He had the same result on his machine. Keep in mind this is running inside a prism region in silverlight, so I don't know if this would make a difference or not. other than that, there is nothing special about the app. I'll send you my diagram settings. The behavior isn't only with linking. If I drag a selection box it is offset from the mouse. If I drag a node, the mouse appears way outside the node. But its the worst when I zoom the browser in IE 8.

That environment must be messing up the coordinate system somehow. I’m not familiar with Prism. Can you tell if it establishes some kind of transform over your content that contains a Diagram?

Also, try the GoSilverlightDemo on www.goxam.com, just to be sure it isn’t something odd about your system or browser.

The good news is it does not seem to happen for any of the demos. The bad news is its probably not environment specific. It must be either some way I configured my diagram that caused it or the fact that it is living inside of PRISM. (Prism is a silverlight framework for docking controls and windows written by Microsoft)

It seems unlikely that the problem is due to how you set any of the Diagram properties.

Perhaps we should continue this discussion off-line.