Esempio n. 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 Neo4JNodeStyle();

            nodesSource.NodeCreator.Defaults.Style = nodeStyle;
            nodesSource.NodeCreator.Defaults.Size  = new SizeD(240, 80);
            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);

            builder.NodeCreated +=
                (sender, e) => {
                // Ensure that nodes have the correct size
                e.Graph.SetNodeLayout(e.Item, RectD.FromCenter(e.Item.Layout.GetCenter(), nodeStyle.GetPreferredSize(e.Item)));
            };
            return(builder, nodesSource, edgesSource);
        }
Esempio n. 2
0
        /// <summary>
        /// Called to render the combo box items.
        /// </summary>
        private void DrawComboBoxItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();
            var node      = Nodes[e.Index];
            var item      = (INeo4jNode)node.Tag;
            var style     = new Neo4JNodeStyle();
            var dummyNode = new SimpleNode {
                Layout = new RectD(0, 0, 240, 75), Tag = item, Style = style
            };
            var context = new RenderContext(e.Graphics, canvasControl);
            var visual  = style.Renderer.GetVisualCreator(dummyNode, style).CreateVisual(context);

            ((VisualGroup)visual).Transform = new Matrix();
            ((VisualGroup)visual).Transform.Translate(e.Bounds.X, e.Bounds.Y);
            visual.Paint(context, e.Graphics);
        }