Пример #1
0
        /// <summary>
        /// Creates a diagram or visual representation of the given incidence structure, returning in addition the association between the graph elements on the one hand
        /// and the visuals on the other.
        /// </summary>
        /// <param name="diagram">The diagram.</param>
        /// <param name="g">The graph to visualize.</param>
        /// <param name="nodeMap">The node map.</param>
        /// <param name="edgeMap">The edge map.</param>
        /// <returns></returns>
        /// <seealso cref="Parse"/>
        public static Graph CreateDiagram(this Telerik.Windows.Controls.RadDiagram diagram, Graph g, out Dictionary <Node, RadDiagramShape> nodeMap, out Dictionary <Edge, RadDiagramConnection> edgeMap, CreateShapeDelegate create, bool randomSize = false)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }
            diagram.Clear();

            var dic = new Dictionary <int, RadDiagramShape>();

            nodeMap = new Dictionary <Node, RadDiagramShape>();
            edgeMap = new Dictionary <Edge, RadDiagramConnection>();
            foreach (var node in g.Nodes)
            {
                var shape = create(node, randomSize);


                nodeMap.Add(node, shape);
                diagram.AddShape(shape);
                dic.Add(node.Id, shape);
            }
            foreach (Edge link in g.Links)
            {
                var con = diagram.AddConnection(dic[link.Source.Id], dic[link.Sink.Id]) as RadDiagramConnection;
                edgeMap.Add(link, con);
                con.TargetCapType = CapType.Arrow1Filled;
            }
            return(g);
        }
Пример #2
0
        /// <summary>
        /// Creates a diagram or visual representation of the given incidence structure.
        /// </summary>
        /// <param name="diagram">The diagram.</param>
        /// <param name="g">The graph structure.</param>
        /// <param name="create">The create.</param>
        /// <returns></returns>
        public static Graph CreateDiagram(this Telerik.Windows.Controls.RadDiagram diagram, Graph g, CreateShapeDelegate create = null, bool randomSize = false)
        {
            if (diagram == null)
            {
                throw new ArgumentNullException("diagram");
            }
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }
            diagram.Clear();

            var dic = new Dictionary <int, RadDiagramShape>();

            foreach (var node in g.Nodes)
            {
                var shape = create == null?CreateShape(node, randomSize) : create(node, randomSize);

                diagram.AddShape(shape);
                dic.Add(node.Id, shape);
            }
            foreach (var con in g.Links.Select(link => diagram.AddConnection(dic[link.Source.Id], dic[link.Sink.Id])))
            {
                con.TargetCapType = CapType.Arrow1Filled;
            }
            return(g);
        }