Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) two links overlaping (Read 9926 times)
kirri
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 19
Joined: May 18th, 2011
two links overlaping
May 24th, 2011 at 2:19pm
Print Post  
Hi,
i have 2 nodes and link goes from 1st node to the 2nd . and from 2nd to the 1st. they overlap over each other and i can not see the text that i associated with the links
I tried to add link.route to each link i am creating, but it made no change. as if this property does not affect my diagram.
I just generate the diagram, i do not manipulate with it after.

Please help

Thank you very much

Michal
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: two links overlaping
Reply #1 - May 24th, 2011 at 2:32pm
Print Post  
Hi,

The method shown here changes the link shapes to Bezier to pull them apart while keeping common end points:
http://mindfusion.eu/Forum/YaBB.pl?board=fcnet_disc;action=display;num=122711142...

The one here pulls apart straight-line links:
http://mindfusion.eu/Forum/YaBB.pl?board=fcnet_disc;action=display;num=126638813...

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
kirri
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 19
Joined: May 18th, 2011
Re: two links overlaping
Reply #2 - May 24th, 2011 at 3:06pm
Print Post  
thanks for such  a qucik reply. I hope i will do it

Michal
  
Back to top
 
IP Logged
 
kirri
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 19
Joined: May 18th, 2011
Re: two links overlaping
Reply #3 - May 25th, 2011 at 10:44am
Print Post  
Hi,
I am rewriting the code and I can not find out how to deal with input parameter type LinkEventArgs. I can not find it anywhere, so I tried to exchange it for DiagramLink, which has common methods available. But there is a problem with
PointF pt1 = e.Link.ControlPoints[0];
Method DiagramLink.getControlPoint.get(0) does not return the same type as e.Link.ControlPoints[0];

I do not know if I am doing it correctly. Please give me an advice.

Thank you very much
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: two links overlaping
Reply #4 - May 25th, 2011 at 10:49am
Print Post  
That's an event handler for the LinkCreated event, but it won't be raised if you create links programmatically. You could replace it with a void OnLinkCreated(DiagramLink link) method and call it yourself after creating a second link between the same nodes.

The sample code is for our Windows Forms control. In a WPF project your should replace PointF with System.Windows.Point, the link.Style property with link.Shape and the LinkStyle enum with with LinkShape.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
kirri
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 19
Joined: May 18th, 2011
Re: two links overlaping
Reply #5 - May 25th, 2011 at 10:53am
Print Post  
I am going to try immediately Smiley. I hope I will do it. Thanks for your reactions, it helps me a lot.
  
Back to top
 
IP Logged
 
kirri
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 19
Joined: May 18th, 2011
Re: two links overlaping
Reply #6 - May 25th, 2011 at 11:20am
Print Post  
I am writing it in Java, creating a Java application. The only purpose is to generate the image of process graph programatically.
If I call DiagramLink.getControlPoints().get(0), it returns a float. Do I not need it to return a Point?
I can paste a few lines of code where is the problem, if it could help

(I hope you understand, English is not my mother tongue)

Thanks very much

Michal
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: two links overlaping
Reply #7 - May 25th, 2011 at 11:29am
Print Post  
It's not a float number but a Point2D.Float (a Float class embedded in the Point2D interface).
  
Back to top
 
IP Logged
 
kirri
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 19
Joined: May 18th, 2011
Re: two links overlaping
Reply #8 - May 25th, 2011 at 11:34am
Print Post  
You are right. I did not realized it. I am sorry for that.

Thanks for your advices.
I hope now I will be able to complete it Smiley

Michal
  
Back to top
 
IP Logged
 
kirri
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 19
Joined: May 18th, 2011
Re: two links overlaping
Reply #9 - May 25th, 2011 at 2:25pm
Print Post  
Hi,
I rewrote the code according to my needs, but it does not make any changes when I call the method.
I created angle and radius as global variables in order to avoid using reference

Here is how it looks like. If you will have a time, please look at it.

Code
Select All
void diagram_LinkCreated(DiagramLink link1)
{
    List<DiagramLink> commonLinks = new ArrayList<DiagramLink>();
    commonLinks = GetCommonLinks(link1.getOrigin(), link1.getDestination());
    Float pt1 = link1.getControlPoints().get(0);
    Float pt2 = link1.getControlPoints().get(link1.getControlPoints().size() - 1);

    if (commonLinks.size() > 1)
    {
        for (int c = 0; c < commonLinks.size(); ++c)
        {
            DiagramLink link = commonLinks.get(c);
            link.setStyle(LinkStyle.Bezier);
            link.setSegmentCount(1);
            cp1 = new Float(pt1.x + 1 * (pt2.x - pt1.x) / 3, pt1.y + 1 * (pt2.y - pt1.y) / 3);
            cp2 = new Float(pt1.x + 2 * (pt2.x - pt1.x) / 3, pt1.y + 2 * (pt2.y - pt1.y) / 3);
            angle = 0;
            radius = 0;
            CartesianToPolar(pt1, pt2, angle, radius);
            int pairOffset = (c / 2 + 1) * 5;

            if (commonLinks.size() % 2 == 0)
            {
                PolarToCartesian(cp1, c % 2 == 0 ? angle - 90 : angle + 90, pairOffset, cp1);
                PolarToCartesian(cp2, c % 2 == 0 ? angle - 90 : angle + 90, pairOffset, cp2);

                if (link1.getControlPoints().get(0) == pt1)
                {
                    link.getControlPoints().set(1, cp1);
                    link.getControlPoints().set(2, cp2);
                }
                else
                {
                    link.getControlPoints().set(1, cp2);
                    link.getControlPoints().set(2, cp1);
                }
                link.updateFromPoints();
            }
        }
    }
}

List<DiagramLink> GetCommonLinks(DiagramNode node1, DiagramNode node2)
{
    List<DiagramLink> commonLinks = new ArrayList<DiagramLink>();

    for (DiagramLink link : node1.getOutgoingLinks())
        if (link.getDestination() == node2)
            commonLinks.add(link);

    for (DiagramLink link : node1.getIncomingLinks())
        if (link.getDestination() == node2)
            commonLinks.add(link);
    return commonLinks;
}

void PolarToCartesian(Float coordCenter, float a, float r, Float cartesian)
{
    if (r == 0)
    {
        cartesian = coordCenter;
        return;
    }
    cartesian.x = (float) (coordCenter.x + Math.cos(a * Math.PI / 180) * r);
    cartesian.y = (float) (coordCenter.y - Math.sin(a * Math.PI / 180) * r);
}

void CartesianToPolar(Float coordCenter, Float cartesian, float a, float r)
{
    if (coordCenter == cartesian)
    {
        a = 0;
        r = 0;
        return;
    }

    float dx = cartesian.x - coordCenter.x;
    float dy = cartesian.y - coordCenter.y;
    double x = Math.pow(dx, 2);
    double y = Math.pow(dy, a);
    double sqrt = Math.sqrt(x + y);
    r = (float) sqrt;
    a = (float) (Math.atan(-dy / dx) * 180 / Math.PI);
    if (dx < 0)
        a = a + 180;
    this.radius = r;
    this.angle = a;
}
 



Thanks very much

Michal
« Last Edit: May 31st, 2021 at 1:39pm by Forum Admin »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: two links overlaping
Reply #10 - May 25th, 2011 at 4:43pm
Print Post  
Hi,

1. Too much copy & paste in your GetCommonLinks Smiley The original checks for Origin in one of the if blocks, your code checks getDestination() twice.

2. .NET has value-equality operator for points, which you should replace with equals(), otherwise it becomes reference comparison.

Here's my Java version (it turned out we have the polar-to-cartesian translation methods in the Utilities class):

Code
Select All
void diagram_LinkCreated(DiagramLink link1)
{
	List<DiagramLink> commonLinks = GetCommonLinks(link1.getOrigin(), link1.getDestination());
	Point2D.Float pt1 = link1.getControlPoints().get(0);
	Point2D.Float pt2 = link1.getControlPoints().get(link1.getControlPoints().size() - 1);

	if (commonLinks.size() > 1)
	{
		for (int c = 0; c < commonLinks.size(); ++c)
		{
			DiagramLink link = commonLinks.get(c);
			link.setStyle(LinkStyle.Bezier);
			link.setSegmentCount(1);
			Point2D.Float cp1 = new Point2D.Float(pt1.x + 1 * (pt2.x - pt1.x) / 3, pt1.y + 1 * (pt2.y - pt1.y) / 3);
			Point2D.Float cp2 = new Point2D.Float(pt1.x + 2 * (pt2.x - pt1.x) / 3, pt1.y + 2 * (pt2.y - pt1.y) / 3);
			Point2D.Float radialCoords = new Point2D.Float();
			Utilities.cartesianToPolar(pt1, pt2, radialCoords);
			float angle = radialCoords.x;
			int pairOffset = (c / 2 + 1) * 5;

			if (commonLinks.size() % 2 == 0)
			{
				Utilities.polarToCartesian(cp1, c % 2 == 0 ? angle - 90 : angle + 90, pairOffset, cp1);
				Utilities.polarToCartesian(cp2, c % 2 == 0 ? angle - 90 : angle + 90, pairOffset, cp2);

				if (link.getControlPoints().get(0).equals(pt1))
				{
					link.getControlPoints().set(1, cp1);
					link.getControlPoints().set(2, cp2);
				}
				else
				{
					link.getControlPoints().set(1, cp2);
					link.getControlPoints().set(2, cp1);
				}
				link.updateFromPoints();
			}
		}
	}
}

List<DiagramLink> GetCommonLinks(DiagramNode node1, DiagramNode node2)
{
	List<DiagramLink> commonLinks = new ArrayList<DiagramLink>();

	for (DiagramLink link : node1.getOutgoingLinks())
	if (link.getDestination() == node2)
		commonLinks.add(link);

	for (DiagramLink link : node1.getIncomingLinks())
	if (link.getOrigin() == node2)
		commonLinks.add(link);

	return commonLinks;
} 



I hope that helps,
Stoyan
« Last Edit: May 31st, 2021 at 1:41pm by Slavcho »  
Back to top
 
IP Logged
 
kirri
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 19
Joined: May 18th, 2011
Re: two links overlaping
Reply #11 - May 26th, 2011 at 9:38am
Print Post  
Thanks very much, surely it helps. But...I do not know why it does not function for my diagram Cheesy
It makes no changes to it. I must have some mistake in the code I think.
I use very simple methods, I am very new to Jdiagram

At first a create diagram and diagramView. Than I call this method:
Code
Select All
private void arrangeDiagram() {

  diagram.clearAll();


  addNodes();

  addEdges(); //adding lines between nodes

  arrange();
    }
 



arrange() is also very simple, i have used the LayeredLayout sample Smiley
Code
Select All
 private void arrange()
{

  LayeredLayout layout = new LayeredLayout();

  layout.setEnforceLinkFlow(true);

  layout.setStraightenLongLinks(true);

  layout.setNodeDistance(10);

  layout.setLayerDistance(15);

  layout.arrange(diagram);

  diagram.resizeToFitItems(1);
}
 


I call the method diagram_LinkCreated(DiagramLink link1) when I create the second link from node1 to node2
Is it wrong? Can you please give me an advice again?

And the second question.. I am also trying to rewrite the code from http://mindfusion.eu/Forum/YaBB.pl?board=fcnet_disc;action=display;num=126638813...

What is the equivalent for node.GetCenter();
Thanks very much for your reply and time

Michal
  
Back to top
 
IP Logged
 
kirri
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 19
Joined: May 18th, 2011
Re: two links overlaping
Reply #12 - May 26th, 2011 at 11:43am
Print Post  
I DID IT Tongue
I have to collect links that overlap and call the method diagram_LinkCreated for these links AFTER method arrange() Smiley

Maybe it can help somebody too
  
Back to top
 
IP Logged
 
kirri
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 19
Joined: May 18th, 2011
Re: two links overlaping
Reply #13 - May 31st, 2011 at 11:44am
Print Post  
Hi,
I have one more question aby link route. When there is a link from node1 to node2 and from node2 back to node1, is it possible to do it as it is shown in the picture attached?
I think I have seen such a topic somewhere, but I am looking for it for a long time and can not find it
Code
Select All
https://docs.google.com/leaf?id=0B8vQshcp7q_QYTUzMGIyOGUtZGVmYS00MTNjLWE0ODEtZThkMTA4ZTEzZDU0&hl=en_US
 



Thank you very much

Michal
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: two links overlaping
Reply #14 - May 31st, 2011 at 12:01pm
Print Post  
Hi,

Perhaps this one:
http://mindfusion.eu/Forum/YaBB.pl?board=wpfdg_disc;action=display;num=125187153...

That might also work by just setting the end points of the link on the right and calling route().

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint