GraphArea object has two properties that can be set to disable default algorithms and use algorithm coded in supplied object:
  • ExternalLayoutAlgorithm - external layout calculation algorithm
  • ExternalOverlapRemovalAlgorithm - external overlap removal algorithm
  • ExternalEdgeRoutingAlgorithm - external edge routing algorithm

ExternalLayoutAlgorithm

To implement external layout algorithm your class must be inherited from IExternalLayout<TVertex> interface. The most notable members of this interface are:
  • VertexPositions - vertices position data that will be calculated by this algo
  • VertexSizes - optional visual vertex control sizes storage
  • NeedVertexSizes - boolean switch. If true - visual vertex control sizes will be automaticaly calculated and inserted into the VertexSizes collection allowing it to be used during following calculation.
  • Compute() - this method implements actual algorithm calculation with the resulting fill of VertexPositions collection.

    public class ExampleExternalLayoutAlgorithm: IExternalLayout<DataVertex>
    {

        public void Compute()
        {
        }

        public IDictionary<DataVertex, System.Windows.Point> VertexPositions
        {
            get { return null; }
        }

        public IDictionary<DataVertex, System.Windows.Size> VertexSizes{ get; set; }

        public bool NeedVertexSizes
        {
            get { return false; }
        }
    }

Note that if your algorithm needs actual vertex sizes then you need to specify NeedVertexSizes property TRUE. In this case VertexSizes will be filled with actual vertex control sizes (if any vertices was ever preloaded into GraphArea) and sizes collection can be used in Compute() method. Here is example code for such case:
            //IF NeedVertexSizes set to false and/or you need sizes before calc for some reason
            var graph = new GraphExample();
            gg_Area.ExternalLayoutAlgorithm = new ExampleExternalLayoutAlgorithm();
            gg_Area.PreloadVertexes(graph); //preload vertices
            var sizes = gg_Area.GetVertexSizes(); //calculate and get vertex sizes
            //... DO SMTH ...
            gg_Area.RelayoutGraph(); // call relayout to generate graph as vertices already has been added

            //IF NeedVertexSizes set to True
            var graph = new GraphExample();
            gg_Area.ExternalLayoutAlgorithm = new ExampleExternalLayoutAlgorithm();
            gg_Area.GenerateGraph(graph); // generate graph

ExternalOverlapRemovalAlgorithm

To implement external overlap removal algorithm your class must be inherited from IExternalOverlapRemoval<TVertex> interface. The most notable members of this interface are:
  • Rectangles - this collection is filled automaticaly before calling Compute() method and contains vertex controls size data.
  • Compute() - overlap removal algorithm implementaion that fills Rectangles collection with the results of computation.
    public class ExampleExternalOverlapRemovalAlgorithm: IExternalOverlapRemoval<DataVertex>
    {
        public IDictionary<DataVertex, System.Windows.Rect> Rectangles { get; set; }

        public void Compute()
        {
            throw new NotImplementedException();
        }
    }

ExternalEdgeRoutingAlgorithm

To implement external edge routing algorithm your class must be inherited from IExternalEdgeRouting<TVertex, TEdge> interface. The most notable members of this interface are:
  • VertexSizes - current vertices sizes. Autofilled before Compute() call.
  • VertexPositions - current vertices positions. Autofilled before Compute() call.
  • Compute() - edge routing algorithm implementaion that fills EdgeRoutes collection with the results of computation.
  • ComputeSingle() - compute edge routing for single data edge and return new route path.
  • UpdateVertexData() - update vertex data inside algorithm data storage. Can be essebtial when you need to recalculate edge routing for single edge or all vertex edges.
    public class ExampleExternalEdgeRoutingAlgorithm<TVertex, TEdge> : 
        IExternalEdgeRouting<TVertex, TEdge>
    {
        public void Compute()
        {
        }

        public IDictionary<TVertex, System.Windows.Rect> VertexSizes { get; set; }

        public IDictionary<TVertex, System.Windows.Point> VertexPositions { get; set; }

        Dictionary<TEdge, System.Windows.Point[]> _edgeRoutes;
        public IDictionary<TEdge, System.Windows.Point[]> EdgeRoutes { get { return _edgeRoutes; }}
        
        public System.Windows.Point[] ComputeSingle(TEdge edge) { return null; }

        public void UpdateVertexData(TVertex vertex, System.Windows.Point position, System.Windows.Rect size) { }
    }

Last edited May 10, 2013 at 10:06 PM by panthernet, version 14