Пример #1
0
        /// <summary>
        /// Shows a separate window that allows to visualize the shortest path between any two nodes.
        /// </summary>
        private async void ShowPathViewer(INode n)
        {
            // Create a small window to choose the target for the shortest path search
            using (var dialog = new ShortestPathDialog(n, Graph.Nodes.ToList())) {
                var result = dialog.ShowDialog(this);
                if (result == DialogResult.OK)
                {
                    try {
                        var(nodes, edges) = await LoadDataFromDatabaseAsync(
                            $"MATCH (n1),(n2), path = shortestPath((n1)-[*..100]-(n2)) WHERE id(n1) = {dialog.FromItem.Id} AND id(n2) = {dialog.ToItem.Id} RETURN path",
                            ConnectionInfo);

                        if (nodes.Count == 0)
                        {
                            MessageBox.Show("No path found!");
                            return;
                        }

                        using (var pathViewer = new PathViewerDialog(nodes, edges)) {
                            pathViewer.ShowDialog(this);
                        }
                    } catch (Exception e) {
                        MessageBox.Show("Could not load the graph. Please check the database or the query.\n\n" + e.Message);
                        connectionInfoPanel.ShowDialog(this);
                        Connect_OnClick(null, null);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Shows a separate window that allows to visualize the shortest path between any two nodes.
        /// </summary>
        private async void ShowPathViewer(INode n)
        {
            // Create a small window to choose the target for the shortest path search
            var dialog = new ShortestPathDialog(n, Graph.Nodes.ToList());

            if (dialog.ShowDialog() == true)
            {
                try {
                    var(nodes, edges) = await LoadDataFromDatabaseAsync(
                        $"MATCH (n1),(n2), path = shortestPath((n1)-[*..100]-(n2)) WHERE id(n1) = {dialog.FromItem.Id} AND id(n2) = {dialog.ToItem.Id} RETURN path",
                        ConnectionInfo);

                    if (nodes.Count == 0)
                    {
                        MessageBox.Show("No path found!");
                        return;
                    }

                    var pathViewer = new PathViewer(nodes, edges);
                    pathViewer.Show();
                } catch (Exception e) {
                    MessageBox.Show("Could not load the graph. Please check the database or the query.\n\n" + e.Message);
                    ConnectionInfoPanel.Visibility = Visibility.Visible;
                }
            }
        }
        /// <summary>
        /// Gets the preferred size, i.e. the size which is large enough to render all properties.
        /// </summary>
        /// <param name="node">The node to get the size for.</param>
        /// <returns>The preferred size</returns>
        public SizeD GetPreferredSize(INode node)
        {
            // the height is insets + id + label + properties
            var item       = GetItem(node);
            var textHeight = keyFont.GetHeight();
            var height     = 15 + (item.Properties.Count + 2) * textHeight;

            // the width is the current width
            return(new SizeD(node.Layout.Width, height));
        }
        /// <summary>
        /// Creates the visualization.
        /// </summary>
        /// <param name="context">The render context.</param>
        /// <param name="node">The node to render.</param>
        /// <returns>The visual representation of the node.</returns>
        protected override VisualGroup CreateVisual(IRenderContext context, INode node)
        {
            var layout = node.Layout;
            var box    = layout.ToRectD();

            if (box.IsEmpty)
            {
                return(null);
            }

            // get the Neo4J node which is represented by the node
            var item = GetItem(node);

            var group = new VisualGroup();

            // draw the background
            group.Add(new RoundedRectangleVisual(layout, 7)
            {
                Brush = Brushes.White
            });

            // the box is the rectangle which contains the content: reduce by insets
            box = box.GetReduced(new InsetsD(5, 10, 5, 5));

            // draw ID and first label
            box = DrawProperty(context, group, "ID", item.Id.ToString(), box);
            box = DrawProperty(context, group, "Label", item.Labels[0], box);

            // draw the properties
            foreach (var property in item.Properties)
            {
                box = DrawProperty(context, group, property, box);
                if (box.Y + keyFont.GetHeight() > layout.GetMaxY())
                {
                    // stop if the next property will be drawn outside the box
                    break;
                }
            }

            // draw the outline
            group.Add(new RoundedRectangleVisual(layout, 7)
            {
                Pen = outlinePen
            });

            // add the type indicator stripe at the top
            var pathVisual  = new GraphicsPathVisual(GetHalfRoundedRect(layout, 7));
            var headerBrush = GetHeaderBrush(item.Labels);

            pathVisual.Brush = headerBrush;
            pathVisual.Pen   = new Pen(headerBrush);
            group.Add(pathVisual);

            return(group);
        }
Пример #5
0
        /// <summary>
        ///  Callback used by the decorator in <see cref="CreateEditorMode"/>
        /// </summary>
        private IPortCandidateProvider GetPortCandidateProvider(INode forNode)
        {
            var model = new MyNodePortLocationModel {
                Inset = 10
            };

            return(PortCandidateProviders.FromCandidates(
                       new DefaultPortCandidate(forNode, model.CreateParameter(PortLocation.Center)),
                       new DefaultPortCandidate(forNode, model.CreateParameter(PortLocation.North)),
                       new DefaultPortCandidate(forNode, model.CreateParameter(PortLocation.East)),
                       new DefaultPortCandidate(forNode, model.CreateParameter(PortLocation.South)),
                       new DefaultPortCandidate(forNode, model.CreateParameter(PortLocation.West))));
        }
Пример #6
0
        /// <summary>
        /// Loads neighbors of the given node and shows them in the graph.
        /// </summary>
        private async Task LoadNeighbors(INode n)
        {
            var id = ((INeo4jNode)n.Tag).Id;

            incrementalNodes.Clear();
            incrementalNodes.Add(n);
            try {
                await LoadGraphAsync(
                    $"MATCH (n1)-[r]-(n2) WHERE id(n1) = {id} AND NOT type(r) = 'SIMILAR_JACCARD' RETURN n1,r,n2",
                    ConnectionInfo, false, n.Layout.GetCenter());
            } catch (Exception e) {
                MessageBox.Show("Could not load the graph. Please check the database or the query.\n\n" + e.Message);
                ConnectionInfoPanel.Visibility = Visibility.Visible;
            }
        }
 /// <summary>
 /// Get the Neo4J node which is represented by the given yFiles node.
 /// </summary>
 /// <param name="node">The node to get the item for.</param>
 /// <returns>The item for the node.</returns>
 private INeo4jNode GetItem(INode node)
 {
     return((INeo4jNode)node.Tag);
 }