Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Bounds for Layout (Read 4796 times)
Davaaron
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 42
Joined: Jul 12th, 2018
Bounds for Layout
Sep 3rd, 2018 at 11:46pm
Print Post  
Hi,

I openend a suggestion for this topic but maybe this is already possible. The goal is to set custom bounds for a LayeredLayout. For the diagram, I setup multiple colored backgrounds (ShapeNodes) which should behave like a kind of container (i can get the bounds of them).
Is it possible to layout my data shape nodes (so not the background shape nodes) only within the background shape nodes (the z-index of the data shape nodes is higher) based on the tag property (which specifies the background owner)?
So I could say this ShapeNode should appear upon that background, while other ShapeNode should appear upon others. But all ShapeNodes should be arranged.

I tried to override the arrange method but I couldn't even get the ShapeNodes arranged correctly (they were stacked all upon each other).
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Bounds for Layout
Reply #1 - Sep 4th, 2018 at 8:27am
Print Post  
Hi,

You could control the layout's top-left point by temporarily changing diagram.Bounds value. Unfortunately you won't be able to limit LayeredLayout's width / height to background node's size.

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


I Love MindFusion!

Posts: 42
Joined: Jul 12th, 2018
Re: Bounds for Layout
Reply #2 - Sep 4th, 2018 at 10:20am
Print Post  
Then I will need to create multiple diagrams and struggle with the bounds (to be able to create connections between the bounds)
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Bounds for Layout
Reply #3 - Sep 4th, 2018 at 2:07pm
Print Post  
Maybe consider using ContainerNode for each part. If you don't want to keep containers in the diagram, you could use a temporary instance, adding respective child nodes just to arrange them, and remove again later.
  
Back to top
 
IP Logged
 
Davaaron
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 42
Joined: Jul 12th, 2018
Re: Bounds for Layout
Reply #4 - Sep 5th, 2018 at 5:44pm
Print Post  
I rely on the bounds and replaced the shapenodes by containernodes.
However, the bound system doesnt seem to work again..  Grin

I resize the canvas as follows:
Code (Javascript)
Select All
let diagramDOM = document.getElementById('diagram');

    let pWidth = diagramDOM.parentElement.getBoundingClientRect().width;
    let pHeight = diagramDOM.parentElement.getBoundingClientRect().height;
, pWidth, pHeight);

    let pCtdWH = diagram.clientToDoc(new Point(pWidth, pHeight));

    let diaBounds = new Rect(0, 0, pCtdWH.x, pCtdWH.y);
    diagram.setBounds(diaBounds);
 



I had 'clientWidth' and 'clientHeight' instead of getBoundingClientRect, but it's the same result. The canvas parent (div) got a height of 938px and a width of 1600. The canvas gets a height of 986px and a width of 1635.
Could this be caused because the div got the css flexbox class? The div got additionally a css property height:100vh.
In the picture though, there is a gap at the bottom and the canvas overlaps the right bound and is being drawn beyond the next html element.

Furthermore, when I stick to container Nodes. Can I nest container nodes into a container node?

Additionally, it'd be a pleasure if you provide an example of how to override a layout arrange algorithm or how to apply a custom one for typescript.

So much is going on under the hood  Shocked Grin
  

bounds_wrong.PNG ( 7 KB | 135 Downloads )
bounds_wrong.PNG
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Bounds for Layout
Reply #5 - Sep 6th, 2018 at 11:42am
Print Post  
Hi,

Testing with your code snippet and the following html and couldn't reproduce the issue:
Code (HTML)
Select All
<div id="view" style="height: 100vh; width: 1600px; display: flex; overflow: auto; background-color: Red;">
  <canvas id="diagram">
  </canvas>
 </div> 



Can you verify that diagram bounds are located at 0,0 in your case? Maybe there was a padding value applied after running a layout.

Regards,
Lyubo
  
Back to top
 
IP Logged
 
Davaaron
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 42
Joined: Jul 12th, 2018
Re: Bounds for Layout
Reply #6 - Sep 6th, 2018 at 2:00pm
Print Post  
Na, I removed all paddings from the bootstrap layout. But the project itself is behaving strange.. but that has nothing to do with MindFusion.

I found a solution by setting the window height:
Code (Javascript)
Select All
   var xPixels = window.innerWidth - otherElements.clientWidth;
    var yPixels = window.innerHeight;
    var mmSize = diagram.clientToDoc({ x: xPixels, y: yPixels });
    let bounds = new Rect(0, 0, mmSize.x, mmSize.y);
    diagram.setBounds(bounds);
 



It's working. So there has to be some issue with the layout, but I can't identify it.

Quote:
Maybe consider using ContainerNode for each part


I do so now. Is there a way that I can scale or resize the content of a container node without scaling/resizing the header and without implementing a custom node? If not, I think i will attach a usual ShapeNode to a ContainerNode, so that the ShapeNode represents the header and the ContainerNode the content which I can resize and scale up/down.

Edit: Maybe by manipulating the rect I get with getGraphicsContent()?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Bounds for Layout
Reply #7 - Sep 7th, 2018 at 9:03am
Print Post  
Do you mean resizing child nodes while users resize their container?
  
Back to top
 
IP Logged
 
Davaaron
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 42
Joined: Jul 12th, 2018
Re: Bounds for Layout
Reply #8 - Sep 7th, 2018 at 9:31am
Print Post  
The user shouldn't be able to resize the container by hand. I want to add zoom and pan functionality only to the content of a container node. I try to find a way I can implement the design I got as a requirement.
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Bounds for Layout
Reply #9 - Sep 11th, 2018 at 6:44am
Print Post  
Hi,

You can try modifying the ContainerNode, to be able to use the ZoomControl widget provided with the Diagramming package. Here is a simple concept, showing how this can be done:

Code (Javascript)
Select All
// Add some backing fields that will store the node's zoom level and scroll positions
MindFusion.Diagramming.ContainerNode.prototype.zoomFactor = 100;
MindFusion.Diagramming.ContainerNode.prototype.scrollX = 0;
MindFusion.Diagramming.ContainerNode.prototype.scrollY = 0;

// The following methods are expected by the ZoomControl to be present on its target
// and will be invoked in response to interactions with the widget

// Sets the zoom factor of the target
MindFusion.Diagramming.ContainerNode.prototype.setZoomLevel = function (zoomFactor)
{
	var dz = (zoomFactor - this.zoomFactor) / 100;
	this.zoomFactor = zoomFactor;

        // Update the bounds of the children with the new scale
	MindFusion.Collections.ArrayList.forEach(this.children, function (child)
	{
		var transform = new MindFusion.Drawing.Matrix();
		transform.scale(1 + dz, 1 + dz);

		var bounds = child.getBounds();
		bounds = transform.transformRect(bounds);

		child.setBounds(bounds, true);
	});
};

// Gets the current scroll positions
MindFusion.Diagramming.ContainerNode.prototype.getScrollX = function ()
{
	return this.scrollX;
};
MindFusion.Diagramming.ContainerNode.prototype.getScrollY = function ()
{
	return this.scrollY;
};

// Sets the scroll position of the target
MindFusion.Diagramming.ContainerNode.prototype.setScroll = function (x, y)
{
	if (this.zoomFactor <= 100)
		return;

	var dx = x - this.scrollX;
	var dy = y - this.scrollY;

	this.scrollX = x;
	this.scrollY = y;

        // Update the bounds of children with the new offset
	MindFusion.Collections.ArrayList.forEach(this.children, function (child)
	{
		var bounds = child.getBounds();
		bounds.x -= dx;
		bounds.y -= dy;
		child.setBounds(bounds, true);
	});
};

// ...

// Create the zoom control from the html canvas element
var zoomer = MindFusion.Controls.ZoomControl.create($("#zoomer")[0]);

// Set the current target of the widget, in this case for example, a selected ContainerNode
zoomer.setTarget(diagram.getActiveItem()); 

Code (HTML)
Select All
<div style="width: 50px; height: 300px; position: absolute; top: 20px; left: 20px; width: 50px; height: 300px;">
    <canvas id="zoomer" width="50" height="300">
    </canvas>
</div> 



The ZoomControl in addition expects that the target has a zoomChanged event, to which it responds if there's a change to the scale of the target from another source (not shown above).

The example can be additionally extended by providing some limits and constraints for the panning and zooming, and some kind of indicators that show to the user the current scroll position of the item.

Regards,
Lyubo
  
Back to top
 
IP Logged
 
Davaaron
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 42
Joined: Jul 12th, 2018
Re: Bounds for Layout
Reply #10 - Sep 11th, 2018 at 1:46pm
Print Post  
Thanks for your effort. That's a good kickoff.
How would you update the links? Zooming can cause a strange side effect where links are not scaling.
« Last Edit: Sep 11th, 2018 at 9:18pm by Davaaron »  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: Bounds for Layout
Reply #11 - Sep 12th, 2018 at 12:50pm
Print Post  
Hi,

The above sample code iterates over the ContainerNode children collection, which contains only nodes, and applies scale/offset. Links update their end points in response of the node.setBounds call (note the true parameter). Other control points will need to be scaled/offset individually.

Regards,
Lyubo
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint