Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Questions about the diagramming package for Xamarin (Read 6926 times)
dpru2
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Feb 2nd, 2021
Questions about the diagramming package for Xamarin
Feb 2nd, 2021 at 5:20pm
Print Post  
I am testing out the diagramming package to see if it would be suitable for the app that I am building. I have a few questions just based on my initial testing of it.

1. It seems like when you draw links between nodes, they are always straight lines from point A to point B. Is there any way to get it to automatically route the link/wire as I am drawing it?

2. It seems like you can just create as many links out of a node as you want. How do I make it so there are very specific points on the node that can be linked to/from? For example, if I have a node that looks like a "logical AND gate", I would expect that node would have 2 inputs and 1 output. I would not want the user to be able to just start creating random links willy-nilly.

3. The behavior of moving nodes seems a little difficult. As far as I can tell, I first have to select the node. Then, I have to press very carefully directly in the center of the node for it to initiate the "move node" operation, and then I can drag the node to wherever I want on the diagram. If I press anywhere else on the node other than exactly in the center, it doesn't move the node, but rather starts drawing a new link, which is not at all what I want to do. Is there a way to modify this behavior?

4. Is there a way to edit resize behavior of nodes? What if I only want to allow them to be resized in one direction - either horizontally or vertically? What if I want to enforce that all resizes must align to the grid? What if I want to create new "linking points" as the resize happens (I don't know what you call a "linking point" in this API - a terminal? a port?)

Thanks for any help and information you can provide!!!


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


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Questions about the diagramming package for Xamarin
Reply #1 - Feb 2nd, 2021 at 5:54pm
Print Post  
Hi!

Quote:
1. It seems like when you draw links between nodes, they are always straight lines from point A to point B. Is there any way to get it to automatically route the link/wire as I am drawing it?


Try setting diagram's RouteLinks property, or call RouteAllLinks / link.Route methods from event handlers.

Quote:
2. It seems like you can just create as many links out of a node as you want. How do I make it so there are very specific points on the node that can be linked to/from? For example, if I have a node that looks like a "logical AND gate", I would expect that node would have 2 inputs and 1 output. I would not want the user to be able to just start creating random links willy-nilly.


Create an AnchorPattern object defining inputs and outputs. For an example see the AnchorPoints sample project.

Quote:
3. The behavior of moving nodes seems a little difficult. As far as I can tell, I first have to select the node. Then, I have to press very carefully directly in the center of the node for it to initiate the "move node" operation, and then I can drag the node to wherever I want on the diagram. If I press anywhere else on the node other than exactly in the center, it doesn't move the node, but rather starts drawing a new link, which is not at all what I want to do. Is there a way to modify this behavior?


You could toggle diagram.Behavior value to MoveNodes to allow moving without selecting first. Alternatively change nodes' HandlesStyle value to HatchHandles2 to have wider area for moving.

Quote:
4. Is there a way to edit resize behavior of nodes? What if I only want to allow them to be resized in one direction - either horizontally or vertically? What if I want to enforce that all resizes must align to the grid? What if I want to create new "linking points" as the resize happens (I don't know what you call a "linking point" in this API - a terminal? a port?)


You could allow resize only in some directions via the node.EnabledHandles property. There's the Diagram.AlignToGrid property for grid alignment. You could set new AnchorPattern from e.g. NodeModified event handler.

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


I Love MindFusion!

Posts: 19
Joined: Feb 2nd, 2021
Re: Questions about the diagramming package for Xamarin
Reply #2 - Feb 5th, 2021 at 10:48am
Print Post  
Thank you for the informative response. It really helped. It has also generated some new questions!

Quote:
Create an AnchorPattern object defining inputs and outputs. For an example see the AnchorPoints sample project.


I was able to create some AnchorPoints and an AnchorPattern very easily, so thanks for pointing out those properties. I also see that there is a function called DrawAnchors() on the Node class. I would like my anchor points to be visible, rather than invisible. I assume this method should be called in order to do so, and it takes an IGraphics object. I tried doing the following right after creating the node to see if it would do anything, but I didn't notice any visible anchors:


Code (C++)
Select All
var graphics = GraphicsFactory.CreateGraphics();
graphics.DrawEllipse(new Pen(Colors.Red), new Rectangle(0, 0, 5, 5));
node1.DrawAnchors(graphics);
 



What's the best way to get the anchors to be visible?

Quote:
Alternatively change nodes' HandlesStyle value to HatchHandles2 to have wider area for moving.


HatchHandles2 and HatchHandles3 are both excellent! Thanks for pointing me to those. I like them much better than the default.

Quote:
You could toggle diagram.Behavior value to MoveNodes to allow moving without selecting first.


Thanks for pointing me to the diagram.Behavior property. It's helpful to see the different behaviors that are available. I think my default go-to will be PanAndModify.

Quote:
You could allow resize only  in some directions via the node.EnabledHandles property. There's the Diagram.AlignToGrid property for grid alignment. You could set new AnchorPattern from e.g. NodeModified event handler.


This all works really nicely, thank you!

Quote:
Try setting diagram's RouteLinks property, or call RouteAllLinks / link.Route methods from event handlers.


This is one aspect I am still having trouble with. I set the "RouteLinks" property to true on the diagram, but did not notice any effect.

Basically, I want the diagram to automatically figure out the appropriate path the link should take as I am drawing it, or as I am moving around nodes. I am not really wanting any diagonal lines - everything should be aligned to the grid and a mix of horizontal and vertical segments. Think along the lines of LabVIEW:










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


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Questions about the diagramming package for Xamarin
Reply #3 - Feb 5th, 2021 at 11:37am
Print Post  
Hi,

Set Diagram.ShowAnchors = Always to make the points visible.

Routing might not show results if there aren't any obstacle nodes in link's path, and also depends on link's Shape. Check if it works for you with link.Shape = Cascading and try moving some node on top of a link. For more control over routing, try also setting diagram.LinkRouter = new GridRouter() and adjusting values in diagram.RoutingOptions.

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


I Love MindFusion!

Posts: 19
Joined: Feb 2nd, 2021
Re: Questions about the diagramming package for Xamarin
Reply #4 - Feb 10th, 2021 at 5:48pm
Print Post  
I'm still having some trouble with links, but I am gradually working through all of the issues.

I do have one question regarding links that I can't seem to figure out:

Is there an easy way to change the "stroke width" of a link? The lines are rather thin and I would like them to be thicker.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Questions about the diagramming package for Xamarin
Reply #5 - Feb 10th, 2021 at 6:25pm
Print Post  
I think in last release we made links a bit thicker by default, so you might check if you are on latest version. Anyway you could set either link.Pen to a pen with wanted width, or link.Style.StrokeThickness if you are using style objects.

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


I Love MindFusion!

Posts: 19
Joined: Feb 2nd, 2021
Re: Questions about the diagramming package for Xamarin
Reply #6 - Feb 11th, 2021 at 10:58am
Print Post  
Thank you for the additional info. I promise I am almost done asking questions Wink

Let me show you my current code as well as a couple of example videos. The first example video shows you what is being produced by my current code. The second example video shows you the kind of experience I am hoping to have in my app.

First, here is my current code:

Code (C++)
Select All
public MainPage()
{
	InitializeComponent();

	var node1 = diagram.Factory.CreateShapeNode(10, 20, 40, 30);
	node1.EnabledHandles = AdjustmentHandles.ResizeBottomCenter;
	node1.Text = "Hello,";
	node1.HandlesStyle = HandlesStyle.HatchHandles3;
	node1.AnchorPattern = new AnchorPattern()
	{
		Points = new AnchorPointCollection()
		{
			new AnchorPoint(0, 33, true, false),
			new AnchorPoint(0, 66, true, false),
			new AnchorPoint(100, 50, false, true)
		}
	};



	var node2 = diagram.Factory.CreateShapeNode(80, 90, 40, 30);
	node2.EnabledHandles = AdjustmentHandles.ResizeBottomCenter;
	node2.Text = "World!";
	node2.HandlesStyle = HandlesStyle.HatchHandles3;
	node2.AnchorPattern = new AnchorPattern()
	{
		Points = new AnchorPointCollection()
		{
			new AnchorPoint(0, 33, true, false),
			new AnchorPoint(0, 66, true, false),
			new AnchorPoint(100, 50, false, true)
		}
	};

	var link1 = diagram.Factory.CreateDiagramLink(node1, node2);
	link1.Shape = LinkShape.Cascading;
	link1.AutoRoute = true;
	link1.HeadBrush = MindFusion.Drawing.Brushes.Red;
	link1.HeadShape = Shapes.Rectangle;
	link1.BaseShape = Shapes.Rectangle;
	link1.BaseBrush = MindFusion.Drawing.Brushes.Red;
	link1.RetainForm = false;
	link1.Pen = new Pen(Colors.Red, 1.0);

	diagram.Behavior = MindFusion.Diagramming.Behavior.PanAndModify;
	diagram.RouteLinks = true;
	diagram.LinkRouter = new GridRouter();
	diagram.AlignToGrid = true;
	diagram.ShowGrid = true;
	diagram.GridSizeX = 10;
	diagram.GridSizeY = 10;
	diagram.GridStyle = GridStyle.Lines;
	diagram.ShowAnchors = ShowAnchors.Always;
	diagram.SnapToAnchor = SnapToAnchor.OnCreateOrModify;
}
 



That code generates a diagram that looks like and interacts like what you see in this video: https://www.youtube.com/watch?v=IDrZndu6560&feature=youtu.be

As you notice, the "base" of the link does not appear to be even initially attached to the source node, which seems like an issue. Also, something is wrong with the algorithm that is routing the link: this link should easily be routed in 3 segments. It should be a horizontal line coming out of the source node, then a vertical line doing down, and then a horizontal line going into the destination node. Finally, when I move the nodes around, there is also some weird behavior. I would expect the link to re-route intelligently, but it seems like what's happening is the link is staying fairly static and only the final segment of the link is changing its angle.

To show you the kind of interaction/behavior I am looking for, I made another video in which I use an app called Lucid Chart to create a simple 2 node diagram with a link between the two nodes, and then I move the nodes around. Here is the video: https://www.youtube.com/watch?v=w2taMRQSwn0&feature=youtu.be

How can I achieve the same behaviors that you can see in that 2nd video?

Namely:
1. The link should have the correct number of segments (I know I can set the "SegmentCount" property on the link, but I shouldn't have to tell it how many segments it should have. It should figure that out intelligently).
2. The link should re-route intelligently as I move nodes around.
3. The link should appear correctly.

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


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Questions about the diagramming package for Xamarin
Reply #7 - Feb 11th, 2021 at 12:40pm
Print Post  
Hi,

Try rerouting node's links from NodeModifying event handler -

Code
Select All
void Diagram_NodeModifying(object sender, NodeValidationEventArgs e)
{
	diagram.LinkRouter.RouteLinks(
		e.Node.GetAllLinks());
} 



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


I Love MindFusion!

Posts: 19
Joined: Feb 2nd, 2021
Re: Questions about the diagramming package for Xamarin
Reply #8 - Feb 11th, 2021 at 1:21pm
Print Post  
I added the event handler, but the behavior is identical to the previous behavior.

Here is the code I added:

Code (C++)
Select All
//This line of code was added to the MainPage constructor,
//the same place where the code I showed previously is located
diagram.NodeModifying += Diagram_NodeModifying;

//This new method is found in MainPage
private void Diagram_NodeModifying(object sender, NodeValidationEventArgs e)
{
	diagram.LinkRouter.RouteLinks(e.Node.GetAllLinks());
}
 



Any suggestions?

Once again, my goal is to get the behavior to be something similar to what is seen in the second video that I linked above (the one in which I was using the Lucid Chart application).
  
Back to top
 
IP Logged
 
dpru2
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Feb 2nd, 2021
Re: Questions about the diagramming package for Xamarin
Reply #9 - Feb 11th, 2021 at 1:23pm
Print Post  
Actually I just put a breakpoint in the event handler to see if it was getting called, and it looks like the event handler isn't even getting called, which doesn't make much sense. Any reason why the event handler wouldn't be getting called?

I have also tried subscribing to the NodeModified event, but it doesn't seem to be getting called either.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Questions about the diagramming package for Xamarin
Reply #10 - Feb 11th, 2021 at 2:04pm
Print Post  
Are you using latest 1.4 version? It works kind of as in second video testing with that event handler in AnchorPoints example. Check if you aren't replacing view's diagram at a later point.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Questions about the diagramming package for Xamarin
Reply #11 - Feb 11th, 2021 at 2:34pm
Print Post  
Actually we've reproduced event not firing when using PanAndModify behavior. Our developer will try to fix that soon.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Questions about the diagramming package for Xamarin
Reply #12 - Feb 11th, 2021 at 4:14pm
Print Post  
This build should fix NodeModifying not raising for PanAndModify -
https://mindfusion.eu/_temp/XamarinDiagram.zip
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Questions about the diagramming package for Xamarin
Reply #13 - Feb 11th, 2021 at 4:19pm
Print Post  
this should fix the initially-unattached problem:

Code
Select All
var link1 = diagram.Factory.CreateDiagramLink(node1, node2);
link1.SegmentCount = 3;
link1.Shape = LinkShape.Cascading; 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Questions about the diagramming package for Xamarin
Reply #14 - Feb 11th, 2021 at 4:33pm
Print Post  
Another problem we've found is PanAndModify incorrectly lets you move nodes when EnabledHandles does not contain the Move bit. Change it to this instead if you allow moving nodes (to get the event raised with new build above) -

Code
Select All
node2.EnabledHandles = AdjustmentHandles.ResizeBottomCenter | AdjustmentHandles.Move; 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint