Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Nodes outline and links behaviour (Read 5525 times)
Sabrina C.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 35
Joined: Dec 20th, 2012
Nodes outline and links behaviour
May 16th, 2016 at 2:01pm
Print Post  
Hi,

we're looking for a method to make links follow the outline of a shape in a template node just like when using ShapeNode with the predefined shapes.

When we use a template node, the links are attached to node by snapping to the bounding box and the result we obtain is unacceptable for our charts. When we use a path in the template (for example an hexagon) we want the links to be continuously snapped to the hexagon. See the heaxagon and the circle problem in the attached figure

We know the availability of the ShapeNode with the specific MindFusion elements and formulas, but we're trying to generalize the construction of shapes by using XAML, inside the template node that can accomodate many different elements.

We found this page in the documentation http://www.mindfusion.eu/onlinehelp/wpfdiagram/O_T_MindFusion_Diagramming_Wpf_Sh...
referring to the possibility to specify a pathGeometry callback. We're looking for something very similar both for TemplateNode and ShapeNode. Such constructors are not present in the ShapeNodes.

Independently from the Shape or the content of the TemplateNode, we're looking for a way to specify the path around which the arrows should be snapped to, but we do'nt want to rely on discrete control points, because the nodes are used in the Spring layout which does not work well with control points, from the graphical point of view.

To generate the border of the Template nodes we're using, we typically insert a Path into it, and in code behind we use a snippet like this one to construct its shape.

Code
Select All
string data = "M0,1 A 1,1 180 1 1 2,1  A 1,1 180 1 1 0,1";
			var converter = TypeDescriptor.GetConverter(typeof(Geometry));
			CircleBorder = (Geometry)converter.ConvertFrom(data);
 



Hope you can point us in the right direction or provide a a way to obtain the result we're expecting. For us it would be sufficient to provide the path the links should snap to in both shapenode and templatenode
Thanks in advance.
  

anchoring2_001.png ( 23 KB | 136 Downloads )
anchoring2_001.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Nodes outline and links behaviour
Reply #1 - May 17th, 2016 at 7:41am
Print Post  
Hi,

If you enable diagram's AutoSnapLinks property, the control should actually inspect the visual tree generated from a node's template and align the link to nearest point of the node's outline. This is done only for links drawn interactively by the user though. If you need to do the same for links created from code, try aligning link end points to nodes after creating the link -

Code
Select All
link.StartPoint = link.Origin.GetNearestBorderPoint(link.StartPoint);
link.EndPoint = link.Destination.GetNearestBorderPoint(link.EndPoint);
link.UpdateFromPoints(false, false); 



Since a node's visual tree does not exist until WPF applies its template, which happens asynchronously some time after the node is created, the code above might not work if you create the links immediately after nodes. If you use a custom node class, you could work around that by aligning link ends from OnApplyTemplate override. With a custom node class you could also override the GetIntersection method, which lets you return aligned end points immediately when link is created instead of realigning them afterwards.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Sabrina C.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 35
Joined: Dec 20th, 2012
Re: Nodes outline and links behaviour
Reply #2 - May 30th, 2016 at 2:54pm
Print Post  
Unfortunately the proposed solution is not viable for us (some other glitches).

We're trying to find an alternative. One of the possibilities would be that we're going to use shapenodes to leverage it's capabilities with respect to border snap, and to give them additional custom elements with XAML. It is important for us to be able to define additional visual elements with XAML.

Is it possible to create shapenodes and to apply a custom template which adds specific content by including the original appearance and behaviour?

Example: we want to create an ellipse shape node so that links are snapped to it and provide a template which includes the ellipse visual and some additional wpf elements like a grid and another path?

Can you provide a working example? I've tries with content presenter or contentcontrol, but it's not working.

Code
Select All
<Style TargetType="ent:ClusterCompanyNode">
		<Setter Property="Template">
			<Setter.Value>

				<DataTemplate >
					<Grid UseLayoutRounding="True" >

						<Path x:Name="Border"
							Effect="{Binding BorderEffect}"
							Stroke="{Binding Stroke}"
							Fill="{Binding Brush}"
							Panel.ZIndex="100"
							Stretch="Fill"
							StrokeThickness="{Binding StrokeThickness}"
							StrokeDashArray="{Binding StrokeDashArray}"
							Data="{Binding BorderGeometry}" >
						</Path>

						<ContentControl />


					</Grid>
				</DataTemplate>
			</Setter.Value>
		</Setter>
	</Style>
 




where ent:ClusterCompanyNode is a subclass of ShapeNode.

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


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Nodes outline and links behaviour
Reply #3 - May 31st, 2016 at 9:35am
Print Post  
Hi,

It's possible. You must also associate your class with the template key by calling this from its static constructor -

Code
Select All
DefaultStyleKeyProperty.OverrideMetadata(
	typeof(ClusterCompanyNode), new FrameworkPropertyMetadata(typeof(ClusterCompanyNode))); 



The tutorials also mention the key in DataTemplate Xaml definition, so it might be required too -

Code
Select All
<Style TargetType="local:OrgChartNode">
...
    <DataTemplate DataType="local:OrgChartNode"> 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Sabrina C.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 35
Joined: Dec 20th, 2012
Re: Nodes outline and links behaviour
Reply #4 - Jun 3rd, 2016 at 9:41am
Print Post  
Hi Slavcho,

unfortunately the solution you provided me seems not working. If I provide the template XAML for the ShapeNode it is not rendered at all. No matter if I add the the datatype in the datatemplate and the override for the default style. Maybe the template I provide is wrong.


Can you provide me with a working example application where:

- a ShapeNode with the ellipse shape is displayed in a diagram
- A template XAML for the shape node is loaded by the application which:
- includes the original text and border of the shapenode
- includes another WPF element e.g. a rectangle


Thanks. A.


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


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Nodes outline and links behaviour
Reply #5 - Jun 3rd, 2016 at 11:10am
Print Post  
Here you are -
https://mindfusion.eu/_samples/TemplatedShapeNode.zip

If you prefer keeping all standard ShapeNode rendering and placing other graphics on top of it instead of adding the Ellipse and TextBlock as in the example, add this to the template in their stead -

Code
Select All
<diag:NodeRenderer Node="{Binding}" /> 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Sabrina C.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 35
Joined: Dec 20th, 2012
Re: Nodes outline and links behaviour
Reply #6 - Jun 6th, 2016 at 8:40am
Print Post  
Hi,

the  <diag:NodeRenderer Node="{Binding}" />
is exactly what we're looking for. Unfortunately there is a bug(?) which prevents us from using it.

In our application according to some user options at run time, the Text property changes on the fly. When using the custom template for the shape nodes, the Text of the node does not get updated. I attach your project with a button showing the problem. Can we overcome it?

S.

  

Bug.zip ( 8 KB | 211 Downloads )
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Nodes outline and links behaviour
Reply #7 - Jun 6th, 2016 at 1:23pm
Print Post  
Hi,

It seems the data template is not repainted if there's no direct binding to the changed property. For time being you can work around it like this -

Code
Select All
// in derived node class
protected override void OnTextAttributeChanged(DependencyPropertyChangedEventArgs e)
{
    base.OnTextAttributeChanged(e);

    var templateGrid = GetVisualChild(0) as Grid;
    if (templateGrid != null)
        templateGrid.Children[0].InvalidateVisual();
} 



It could also be possible to implement that using multi-binding or triggers in the template. For next release we'll check if there's a way to refresh it automatically for any property change.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Sabrina C.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 35
Joined: Dec 20th, 2012
Re: Nodes outline and links behaviour
Reply #8 - Jun 13th, 2016 at 7:26am
Print Post  
Other properties are affected too, e.g. the Brush of the node.
While for the text property we have added our custom textblock in the template bound to a NodeText property, we need to make the Brush property of the node work, so it can be changed runtime. Can you help? With invalidate visual on the node renderer, it does not work.

this is the template we are using:

Code
Select All
 <Style TargetType="ent:ClusterCompanyNode">
        <Setter Property="Template">
            <Setter.Value>

                <DataTemplate DataType="ent:ClusterCompanyNode" >
                    <Grid UseLayoutRounding="True" >

                        <TextBlock
                            Text="{Binding NodeText}"
							Foreground="{Binding TextBrush}"
                            FontSize="{Binding FontSize}"
                            FontWeight="{Binding FontWeight}"
                            FontFamily="{Binding FontFamily}"
                            FontStretch="{Binding FontStretch}"
                            FontStyle="{Binding FontStyle}"
                            TextDecorations="{Binding TextDecorations}"
                            TextAlignment="Center"
                            VerticalAlignment="Center"
							Panel.ZIndex="102"
                            Margin="5,0" Padding="0"   TextWrapping="Wrap" TextTrimming="CharacterEllipsis"
						/>

                        <Grid UseLayoutRounding="True" Panel.ZIndex="100"   Visibility="{Binding ShowCategoryIcon, Converter={StaticResource BooleanToVisibilityConverter}}" >

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="1*"/>
                                <ColumnDefinition Width="7.5*"/>
                                <ColumnDefinition Width="1*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="1*" />
                                <RowDefinition Height="7.5*" />
                                <RowDefinition Height="1*" />
                            </Grid.RowDefinitions>
                            <Path  Grid.Column="1" Grid.Row="1"
							Stroke="{x:Null}"
							Fill="{StaticResource CompanyCategoryBrush}"
							Stretch="Uniform"
							Data="{Binding CategoryGeometry}" >
                            </Path>
                        </Grid>

                        <diag:NodeRenderer Node="{Binding}" />

                    </Grid>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>
 




Thanks, Sabrina
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Nodes outline and links behaviour
Reply #9 - Jun 15th, 2016 at 6:05am
Print Post  
One solution I can think of is to add NodeRenderer properties just for the sake of binding -

Code
Select All
public class MyNodeRenderer : NodeRenderer
{
	static DependencyProperty BrushProperty =
		DiagramItem.BrushProperty.AddOwner(
			typeof(MyNodeRenderer),
			new FrameworkPropertyMetadata(null,
				FrameworkPropertyMetadataOptions.AffectsRender));

	public Brush Brush
	{
		get { return (Brush)GetValue(BrushProperty); }
		set { SetValue(BrushProperty, value); }
	}
}

<DataTemplate ...
	<local:MyNodeRenderer Node="{Binding}" Brush="{Binding Brush}" /> 



We'll try to make this automatic for upcoming release in a few weeks.

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


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Nodes outline and links behaviour
Reply #10 - Jul 29th, 2016 at 4:18pm
Print Post  
Please try this new build -
https://mindfusion.eu/_beta/wpf_noderenderer.zip

The standard NodeRenderer will now repaint automatically when any dependency property of the node changes, without you having to specify additional bindings.

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