Beispiel #1
0
        /// <summary>
        /// Creates a GraphBuilder instance that's preconfigured with our demo's styles.
        /// </summary>
        internal static (GraphBuilder, NodesSource <INeo4jNode>, EdgesSource <IRelationship>) CreateGraphBuilder(GraphControl graphControl, IGraph graph, List <INeo4jNode> nodes, List <IRelationship> edges)
        {
            var builder     = new GraphBuilder(graph);
            var nodesSource = builder.CreateNodesSource(nodes, n => n.Id);

            nodesSource.NodeCreator.TagProvider = n => n;
            var nodeStyle = new NodeControlNodeStyle("NodeStyle");

            nodesSource.NodeCreator.Defaults.Style = nodeStyle;
            var edgesSource = builder.CreateEdgesSource(edges, e => e.StartNodeId, e => e.EndNodeId, e => e.Id);

            edgesSource.EdgeCreator.Defaults.Style = new BezierEdgeStyle {
                TargetArrow = Arrows.Default
            };
            var labelBinding = edgesSource.EdgeCreator.CreateLabelBinding(item => item.Type);

            labelBinding.Defaults.LayoutParameter = new EdgeSegmentLabelModel().CreateParameterFromSource(0, 0, EdgeSides.AboveEdge);

            var context = graphControl.CreateRenderContext();

            builder.NodeCreated +=
                (sender, e) => {
                // Ensure that nodes have the correct size
                e.Graph.SetNodeLayout(e.Item, RectD.FromCenter(e.Item.Layout.GetCenter(), nodeStyle.GetPreferredSize(context, e.Item)));
            };
            return(builder, nodesSource, edgesSource);
        }