Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Branching Link (Read 7413 times)
Jessenberg
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 27
Joined: Dec 20th, 2021
Branching Link
Jan 1st, 2022 at 4:46am
Print Post  
Hi, i was wondering how can i make a branching link like this using mindfusion, i'm kind of confused on how to do it using javascript
  

Screenshot_1.png ( 14 KB | 9 Downloads )
Screenshot_1.png
Back to top
 
IP Logged
 
Jessenberg
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 27
Joined: Dec 20th, 2021
Re: Branching Link
Reply #1 - Jan 1st, 2022 at 8:01am
Print Post  
Also side question, i have loaded an svg file into a dict and was wondering how can i set the width and height of the shape and also make the background transparent so that i can load a shape using svg files without the rectangle background

this is my code to load it in, and they came into a default width and height of 24 when i drag and drop it, i want to change it to something like 42 when the shape is dropped because the circle was supposed to be an oval shape in the svg file, and make the rectangle around the circle dissapear, because i have a custom rounded rectangle shape that also has the rectangle background

Code (Javascript)
Select All
Object.values(nodeDict).forEach((dict) => {
      const node = new mf.Diagramming.SvgNode(diagram);
      node.setContent(dict.content);
      node.brush = "white";
      shapeNodes.push(node);
      shapeIds.push(dict.name);
      console.log(node);
    }); 



below is the svg file loaded
« Last Edit: Jan 2nd, 2022 at 8:32am by Jessenberg »  

Screenshot_3.png (Attachment deleted)
Screenshot_4.png (Attachment deleted)
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: Branching Link
Reply #2 - Jan 3rd, 2022 at 6:57am
Print Post  
Hi,

Enable the node.transparent property to hide the node's own shape, leaving only image / svg and text visible.

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


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: Branching Link
Reply #3 - Jan 3rd, 2022 at 7:28am
Print Post  
Hi,

There's no support for branching links. You could use a small node to represent the fork, having two incoming links and one outgoing link connecting to it. Alternatively keep just the two links but add an extra segment to them and make sure the middle control point coordinates coincide. E.g. this will automatically insert a fork node if user tries to connect link to another link -

Code
Select All
diagram.allowUnconnectedLinks = true;
diagram.autoSnapDistance = 2;

diagram.addEventListener(Events.linkCreated, onLinkCreated);
diagram.addEventListener(Events.linkCreating, onLinkCreating);

function onLinkCreating(diagram, args)
{
	if (args.link.targetConnection.node instanceof MindFusion.Diagramming.DummyNode)
		args.cancel = diagram.getItemAt(args.mousePosition) == null;
}

function onLinkCreated(diagram, args)
{
	if (args.link.destination instanceof MindFusion.Diagramming.DummyNode)
	{
		var links = diagram.getLinksAt(args.mousePosition);
		for (var targetLink of links)
		{
			if (targetLink == args.link)
				continue;
			var pos = args.mousePosition;
			var fork = diagram.factory.createShapeNode(pos.x - 4, pos.y - 4, 8, 8);
			fork.shape = "Ellipse";
			diagram.factory.createDiagramLink(targetLink.origin, fork);
			targetLink.origin = fork;
			args.link.destination = fork;
			break;
		}
	}
} 



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


I Love MindFusion!

Posts: 27
Joined: Dec 20th, 2021
Re: Branching Link
Reply #4 - Jan 3rd, 2022 at 8:32am
Print Post  
Slavcho wrote on Jan 3rd, 2022 at 7:28am:
Hi,

There's no support for branching links. You could use a small node to represent the fork, having two incoming links and one outgoing link connecting to it. Alternatively keep just the two links but add an extra segment to them and make sure the middle control point coordinates coincide. E.g. this will automatically insert a fork node if user tries to connect link to another link -

Code
Select All
diagram.allowUnconnectedLinks = true;
diagram.autoSnapDistance = 2;

diagram.addEventListener(Events.linkCreated, onLinkCreated);
diagram.addEventListener(Events.linkCreating, onLinkCreating);

function onLinkCreating(diagram, args)
{
	if (args.link.targetConnection.node instanceof MindFusion.Diagramming.DummyNode)
		args.cancel = diagram.getItemAt(args.mousePosition) == null;
}

function onLinkCreated(diagram, args)
{
	if (args.link.destination instanceof MindFusion.Diagramming.DummyNode)
	{
		var links = diagram.getLinksAt(args.mousePosition);
		for (var targetLink of links)
		{
			if (targetLink == args.link)
				continue;
			var pos = args.mousePosition;
			var fork = diagram.factory.createShapeNode(pos.x - 4, pos.y - 4, 8, 8);
			fork.shape = "Ellipse";
			diagram.factory.createDiagramLink(targetLink.origin, fork);
			targetLink.origin = fork;
			args.link.destination = fork;
			break;
		}
	}
} 



Regards,
Slavcho


hi there, thank you for the solution, i think i'll be using a custom svg node to make such links in the first place, if you don't mind me asking since i just load all of the svg node using a loop, their width and height will be simillar, can you perhaps explain how to load the node into a diferent width and height when you dropped it into the diagram? because that node need to be relatively smaller then the others.

i've tried a couple of stuff but i don't know where or how to declare the height and width to override the base height and width
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: Branching Link
Reply #5 - Jan 3rd, 2022 at 11:22am
Print Post  
Hi,

Assign a Rect instance to node.bounds property to change node's size.

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


I Love MindFusion!

Posts: 27
Joined: Dec 20th, 2021
Re: Branching Link
Reply #6 - Jan 3rd, 2022 at 1:57pm
Print Post  
hi there, since i'm using the older version of the library i followed the youtube tutorial on the chanel for creating a the bound of it, and i also declared the node.Transparent = true on it but it doesn't seem to change, did i perhaps miss something?

here is my code in sandbox, line 165 is the part that i've been working on :

https://codesandbox.io/s/focused-kepler-op5hu?file=/src/DiagramApp.js
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: Branching Link
Reply #7 - Jan 3rd, 2022 at 3:37pm
Print Post  
Hi,

V3 API was using getProperty / setProperty method calls instead of property assignments. Change that line to node.setTransparent(true);

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


I Love MindFusion!

Posts: 27
Joined: Dec 20th, 2021
Re: Branching Link
Reply #8 - Jan 3rd, 2022 at 4:20pm
Print Post  
thank you for making it clear, the node is now transparent

sorry to bother you again but is this the correct way of calling the bound instance?

Code (Javascript)
Select All
 Object.values(nodeDict).forEach((dict) => {
      const node = new mf.Diagramming.SvgNode(diagram);
      [color=#ffff00]node.setBounds(new cm.Drawing.Rect(25, 15, 49, 27));[/color]
      node.setContent(dict.content);
      node.brush = "white";
      node.setTransparent(true);
      shapeNodes.push(node);
      shapeIds.push(dict.name);
      // console.log(node);
    }); 



if i'm not mistaken that's how you set the height and width of the svg node using bound on V3, with 49 being the width and 27 being the height, but they still came out as the default 24, do i have to set the height and width sepparately by just creating an empy instance of Rect first an then bound it with the a Rect variable? i really apreciate your help
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: Branching Link
Reply #9 - Jan 3rd, 2022 at 5:26pm
Print Post  
Hi,

Try setting the NodeListView.defaultNodeSize property to the size you need.

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


I Love MindFusion!

Posts: 27
Joined: Dec 20th, 2021
Re: Branching Link
Reply #10 - Jan 7th, 2022 at 12:52am
Print Post  
Thank you for your help, the code now works but there is a minor problem happening, any svg file that has a round or circle shape now became oval shape, is there a way to render or load the svg file with their own width and height parameter rather than me declaring the size with defaultNodeSize? so that a few shape can render with different value
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: Branching Link
Reply #11 - Jan 7th, 2022 at 8:59am
Print Post  
Try calling this from nodeCreated event handler, making the imageAlign property inherited from base ShapeNode apply to SVG content too:

Code
Select All
node.setImageAlign(ImageAlign.Fit);

node.image.svg = false;
node.image.image.width = node.image.image.naturalWidth;
node.image.image.height = node.image.image.naturalHeight; 



We'll add built-in support for upcoming release.

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


I Love MindFusion!

Posts: 27
Joined: Dec 20th, 2021
Re: Branching Link
Reply #12 - Jan 9th, 2022 at 12:47am
Print Post  
hi, so i'm using V3 and is this the right way to do it?
Code (Javascript)
Select All
 <DiagramView
              diagram={this.state.diagram}
              {...props}
              onLeaveInplaceEditMode={(item, node) => {
                node.item.textColor = "black";
              }}
              onNodeCreated={(item, node) => {
                var align = mf.Diagramming.ImageAlign.Fit;
                node.setImageAlign(align);
                node.image.svg = false;
                node.image.image.width = node.image.image.naturalWidth;
                node.image.image.height = node.image.image.naturalHeight;
                console.log(node);
              }}
              }} 


it say's that setImageAlign is not a function, and the other code below besides the console log gives an error, so i think i might be calling it wrong

if it can give more clarity, it's from line 535 in the sandbox :
https://codesandbox.io/s/nostalgic-keldysh-3docn?file=/src/DiagramApp.js
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: Branching Link
Reply #13 - Jan 10th, 2022 at 8:54am
Print Post  
Hi,

Event handlers' signature should look like onEvent(diagram, event_args):

Code
Select All
onNodeCreated={(diagram, args) => {
    var node = args.getNode(); //v3
    ... 



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


I Love MindFusion!

Posts: 27
Joined: Dec 20th, 2021
Re: Branching Link
Reply #14 - Jan 13th, 2022 at 7:31am
Print Post  
Thank you so much, the code now works as expected
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint