Exemplo n.º 1
0
 public static RadDiagramShape CreateShape(this RadDiagram diagram, string title = null, string name = null)
 {
     if (string.IsNullOrEmpty(title)) title = "Shape";
     if (string.IsNullOrEmpty(name)) name = "Shape_" + Rand.Next(665686356);
     var shape = new RadDiagramShape
     {
         Width = 80,
         Height = 50,
         Name = name,
         Geometry = ShapeFactory.GetShapeGeometry(CommonShapeType.RectangleShape),
         Background = new SolidColorBrush(Windows8Palette.Palette.AccentColor),
         Content = title,
         Stroke = new SolidColorBrush(Colors.DarkGray),
         StrokeThickness = 0,
         Position = new Point(50 + Rand.Next(800), 50 + Rand.Next(600))
     };
     diagram.AddShape(shape);
     return shape;
 }
Exemplo n.º 2
0
 public static void CreateGraph(this RadDiagram diagram, GraphGenerationSpecifications specs, CreateShapeDelegate createShape)
 {
     diagram.Clear();
     if (specs.Connections)
     {
         var g = specs.Connected ? GraphExtensions.CreateRandomConnectedGraph(specs.NodeCount, 4, specs.TreeGraph) : GraphExtensions.CreateRandomGraph(specs.NodeCount, 4, specs.TreeGraph);
         diagram.CreateDiagram(g, GraphExtensions.CreateShape, specs.RandomShapeSize);
     }
     else
     {
         for (var i = 0; i < specs.NodeCount; i++)
         {
             var shape = createShape(new Node(i, false), specs.RandomShapeSize, null);
             diagram.AddShape(shape);
         }
     }
 }
Exemplo n.º 3
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, null);
                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;
        }
Exemplo n.º 4
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, null);

                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;
        }
Exemplo n.º 5
0
        public static IContainerShape CreateContainerShape(this RadDiagram diagram, string title = null, string name = null)
        {
            if (string.IsNullOrEmpty(title)) title = "Container";
            if (string.IsNullOrEmpty(name)) name = "Container_" + Rand.Next(665686356);
            var shape = new RadDiagramContainerShape
            {
                Width = 250,
                Height = 150,
                Name = name,
                Content = title,
                //Stroke = Brushes.DimGray,
                IsCollapsible = true,
                StrokeThickness = 1,

                CollapsedContent = null,
            };
            diagram.AddShape(shape);
            return shape;
        }