Change the type of edges when using the Diagram Data Importer

Applies to: Nevron Diagram for .NET

How to change the type of edges when using the Diagram Data Importer?

When using NGraphDataSourceImporter or NTreeDataSourceImporter to import vertices and edges from a database, the type of all edges is NRoutableConnector by default. To change the type of edges in the EdgeImported event, you can create a shape factory (by implementing the INShapeFactory interface) that creates the edge types you want and assign it to the EdgesShapeFactory property of the graph / tree data importer.



The following code is a simple implementation of a shape factory:

[C#]
public class MyEdgeShapeFactory : NShapesFactory
{
      public MyEdgeShapeFactory()
            : base("MyEdgeShapeFactory")
      {
      }
 
      public override int ShapesCount
      {
            get
            {
                  return Enum.GetValues(GetEnumType()).Length;
            }
      }
       
      public override NShape CreateShape(int index)
      {
            switch ((MyEdgeShapes)index)
            {
                  case MyEdgeShapes.ArrowShape:
                        NArrowShape arrowShape = new NArrowShape(new NPointF(0, 0), new NPointF(DefaultSize.Width, DefaultSize.Height));
                        return arrowShape;
 
                  default:
                        throw new Exception("New shape type ?");
            }
      }
      protected override NShapeInfo CreateShapeInfo(int index)
      {
            MyEdgeShapes edgeShape = (MyEdgeShapes)index;
            NShapeInfo info = new NShapeInfo(NSystem.InsertSpacesBeforeUppers(edgeShape.ToString()));
            return info;
      }
      protected override Type GetEnumType()
      {
            return typeof(MyEdgeShapes);
      }
}
 
public enum MyEdgeShapes
{
      ArrowShape
}

[VB.NET]
Public Class MyEdgeShapeFactory
    Inherits NShapesFactory
    Public Sub New()
        MyBase.New("MyEdgeShapeFactory")
    End Sub
 
    Public Overrides ReadOnly Property ShapesCount() As Integer
        Get
            Return [Enum].GetValues(GetEnumType()).Length
        End Get
    End Property
 
    Public Overrides Function CreateShape(index As Integer) As NShape
        Select Case DirectCast(index, MyEdgeShapes)
            Case MyEdgeShapes.ArrowShape
                Dim arrowShape As New NArrowShape(New NPointF(0, 0), New NPointF(DefaultSize.Width, DefaultSize.Height))
                Return arrowShape
            Case Else
 
                Throw New Exception("New shape type ?")
        End Select
    End Function
    Protected Overrides Function CreateShapeInfo(index As Integer) As NShapeInfo
        Dim edgeShape As MyEdgeShapes = DirectCast(index, MyEdgeShapes)
        Dim info As New NShapeInfo(NSystem.InsertSpacesBeforeUppers(edgeShape.ToString()))
        Return info
    End Function
    Protected Overrides Function GetEnumType() As Type
        Return GetType(MyEdgeShapes)
    End Function
End Class
 
Public Enum MyEdgeShapes
    ArrowShape
End Enum

To make the graph / tree data importer use this shape factory to create edges, use the following piece of code:

[C#]
MyEdgeShapeFactory edgesFactory = new MyEdgeShapeFactory();
edgesFactory.DefaultSize = new NSizeF(60, 30);
TreeImporter.EdgeShapesFactory = edgesFactory;
TreeImporter.EdgeShapesName = MyEdgeShapes.ArrowShape.ToString();
//GraphImporter.EdgeShapesFactory = edgesFactory;
//GraphImporter.EdgeShapesName = MyEdgeShapes.ArrowShape.ToString();

[VB.NET]
Dim edgesFactory As New MyEdgeShapeFactory()
edgesFactory.DefaultSize = New NSizeF(60, 30)
TreeImporter.EdgeShapesFactory = edgesFactory
TreeImporter.EdgeShapesName = MyEdgeShapes.ArrowShape.ToString()
'GraphImporter.EdgeShapesFactory = edgesFactory;
'GraphImporter.EdgeShapesName = MyEdgeShapes.ArrowShape.ToString();

Article ID: 127, Created On: 11/16/2010, Modified: 12/1/2010