Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Query how to align the node text. (Read 6103 times)
Anant_Shukla
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 36
Joined: Mar 16th, 2009
Query how to align the node text.
Mar 16th, 2009 at 12:56pm
Print Post  
Hi All,


I have few node with labels attached to them in my diagram. I have a query regarding changing the position of the text corresponding to a node i.e when I select a node from the design and click on a button for say the button is labeled as "Top" the text corresponding to the selected node should get aligned top to the selected node. Can somebody please help me and tell how can I accomplish this task.

Thanks and Regards,
Anant Shukla.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Query how to align the node text.
Reply #1 - Mar 16th, 2009 at 1:10pm
Print Post  
Hi,

Are your labels displayed inside separate nodes attached to the shape nodes, or you are using ShapeNode.Text to set the label text?

Stoyan
  
Back to top
 
IP Logged
 
Anant_Shukla
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 36
Joined: Mar 16th, 2009
Re: Query how to align the node text.
Reply #2 - Mar 16th, 2009 at 1:44pm
Print Post  
Hi Stoyan,

Thanks for the quick reply.

The query regarding the text alignment from my last post is been resolved with the help few discussions available on the forum. Can you please help me resolving few other issues which are as follows :-

1. I have few nodes in the diagram when I select multiple nodes from the diagram I need to highlight the last selected node so that it can be easily differentiated from other selected nodes.

2. Also in the same situation as described above i.e when I select multiple node from the diagram and click on a button from my design say labeled as "Align Left" then all the nodes other than the last selected one should get aligned left to the last selected node.

Thanks and Regards,
Anant Shukla.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Query how to align the node text.
Reply #3 - Mar 16th, 2009 at 1:54pm
Print Post  
Hi Anant,

The diagram already highlights the last selected item by drawing its selection handles in a different color. The Diagram.ActiveItem property refers to that item. So 1) in the SelectionChanged event you could additionally change the ActiveItem.Brush and 2) loop over Diagram.Selection.Nodes and call their Move method passing the ActiveItem.Bounds.X as the x argument.

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


I love YaBB 1G - SP1!

Posts: 36
Joined: Mar 16th, 2009
Re: Query how to align the node text.
Reply #4 - Mar 16th, 2009 at 3:32pm
Print Post  
Hi Stoyan,

Again thanks for the quick reply. Yes your suggestions proved to be handy but I am facing few more issues please guide me through these issues

1. I have set the HandleStyle property for the node to "MoveOnly" in my diagram with this property set how can I highlight the last node selected in my diagram..

2. Also can you please elaborate on the suggestion provided by you in the last post of yours for the "Align Left" option for the selected nodes.

Thanks and Regards,
Anant Shukla.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Query how to align the node text.
Reply #5 - Mar 16th, 2009 at 4:04pm
Print Post  
Hi,

2) Should look like

Code
Select All
DiagramNode active = diagram.ActiveItem as DiagramNode;
if (active != null)
{
	foreach (DiagramNode node in diagram.Selection.Nodes)
		node.Move(active.Bounds.X, node.Bounds.Y);
}
 



1) Indeed the MoveOnly frame does not look different for the active item. You could set the Brush to highlight the node, or set HandlesStyle = Custom and draw the selection frame as you need it from the DrawAdjustmentHandles event handler.

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


I love YaBB 1G - SP1!

Posts: 36
Joined: Mar 16th, 2009
Re: Query how to align the node text.
Reply #6 - Mar 17th, 2009 at 5:58am
Print Post  
Hi Stoyan,

Thanks for the reply.

Yes surely the code snippet provided by you helped a lot in accomplishing the task and the query is resolved. But I have few more queries can you please guide me through those

1. Same as "Align Left" option in my previous queries I have now buttons say "Align Right" and "Align Bottom" upon clicking on which, as the name suggest, all the selected nodes except the last selected one will get aligned rightward and bottom with respect to the last selected node. I have written the following code for "Align Right" and "Align Bottom" button action respectively.

Align Right :

private void btnAlignRight_Click(object sender, RoutedEventArgs e)
{
DiagramNode active = diagram.ActiveItem as DiagramNode;
if (active != null)
{
foreach (DiagramNode node in diagram.Selection.Nodes)
node.Move(active.Bounds.Right, node.Bounds.Y);
}
}

Align Bottom :

private void btnAlignBottom_Click(object sender, RoutedEventArgs e)
{
DiagramNode active = diagram.ActiveItem as DiagramNode;
if (active != null)
{
foreach (DiagramNode node in diagram.Selection.Nodes)
node.Move( node.Bounds.X, active.Bounds.Bottom );
}
}

These codes align all the nodes to the bottom of the selected node including the last selected node which is not desired. The last selected node should remove stationary in both cases i.e align right and align top while all the other selected nodes should get aligned as desired.

2. Also can you please provide me a sample code for highlighting the last selected node when multiple nodes are selected from the diagram and the HandlesStyle property of the nodes is set to MoveOnly.

Thanks and Regards,
Anant Shukla.
« Last Edit: Mar 17th, 2009 at 8:50am by Anant_Shukla »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Query how to align the node text.
Reply #7 - Mar 17th, 2009 at 9:16am
Print Post  
Align right:
node.Move(active.Bounds.Right - node.Bounds.Width, node.Bounds.Y);

Align bottom:
node.Move( node.Bounds.X, active.Bounds.Bottom - node.Bounds.Height);

Add a handler for the NodeActivated and NodeDeactivated events and handle them by setting the brush of the node:
e.Node.Brush = new SolidColorBrush(...);

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


I love YaBB 1G - SP1!

Posts: 36
Joined: Mar 16th, 2009
Re: Query how to align the node text.
Reply #8 - Mar 17th, 2009 at 10:45am
Print Post  
Hi,

Thanks for the reply. It surely helped. Please help me through few more queries which are as follows :

1. There is a button in the diagram labeled as "Compact" which align all the nodes present in the diagram so that they all occupy minimum area and the X and Y axis distance between all the nodes on the same level of the hierarchy in the diagram is same.

2. There is another button on the diagram labeled as "Hierarchy" which align all the nodes on the same level together based on the links associated with the node and produce a hierarchical arranged node diagram where nodes from same hierarchy level are in one line and as the hierarchy of the nodes flows the nodes representation is the same.

Thanks and Regards,
Anant Shukla.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Query how to align the node text.
Reply #9 - Mar 17th, 2009 at 12:37pm
Print Post  
Hi,

1. GridLayout.Arrange should do that.

2. Try TreeLayout or LayeredLayout.

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


I love YaBB 1G - SP1!

Posts: 36
Joined: Mar 16th, 2009
Re: Query how to align the node text.
Reply #10 - Mar 17th, 2009 at 12:50pm
Print Post  
Hi Stoyan,

I am kind of new to MindFusion so can you please provide a detailed solution or a sample code for the last query from me about the alignment issue.

Thanks and Regards,
Anant Shukla.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Query how to align the node text.
Reply #11 - Mar 17th, 2009 at 2:36pm
Print Post  
Hi Anant,

Import the MindFusion.Diagramming.Layout namespace, create an instance of the respective layout class and call its Arrange method. Check the DirTree or TreeLayout sample projects.

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


I love YaBB 1G - SP1!

Posts: 36
Joined: Mar 16th, 2009
Re: Query how to align the node text.
Reply #12 - Mar 17th, 2009 at 3:00pm
Print Post  
Hi Stoyan,

Thanks again for the vital help.

I have used the GridLayout for the "Compact" button functionality and TreeLayout for the "Heirarchy" button functionality.

The code used by me is as follows :

GridLayout :

private void btnCompact_Click(object sender, RoutedEventArgs e)
{
GridLayout gridLayout = new GridLayout();
gridLayout.GridSize = 75;
gridLayout.Arrange(diagram);
}

TreeLayout :

private void btnHierarchy_Click(object sender, RoutedEventArgs e)
{

TreeLayout treeLayout = new TreeLayout();
treeLayout.Type = TreeLayoutType.Cascading;
treeLayout.LevelDistance = 10;
treeLayout.KeepRootPosition = true;
treeLayout.Arrange(diagram);

}

The issues faced by me are as follows :

1. Each time i click the "Compact" button the nodes in the design gets aligned according to the present alignment of the nodes which is not desired. I just need the nodes to get aligned only once i.e only on the first click of the button and the alignment should be retained even when I click the "Compact" button again. Same is the issue with the TreeLayout.

2. I also tried the HorizontalVertical property in TreeLayout and it did nothing i.e each time I click on the "Heirarchy" button there was no effect on the alignment. The code I used for the purpose is as follows :

private void btnHierarchy_Click(object sender, RoutedEventArgs e)
{

TreeLayout treeLayout = new TreeLayout();
treeLayout.Type = TreeLayoutType.HorizontalVertical;
treeLayout.LevelDistance = 10;
treeLayout.KeepRootPosition = true;
treeLayout.Arrange(diagram);
}

Can you please tell me what is that I am missing in this and also for my requirements which of the property among available ones should I use .

3. Also the links gets bend while aligning the nodes in the Tree as well as Grid layout which is not desired any suggestions how I can prevent the bending of the links between the nodes while aligning them upon clicking the "Compact" and "Hierarchy" buttons.

Thanks and Regards,
Anant Shukla.
« Last Edit: Mar 18th, 2009 at 6:38am by Anant_Shukla »  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint