示例#1
0
        private void AddNewGraphEdge(Color colour, Model from, Model to)
        {
            MuseoNode fromNode = new MuseoNode(colour, from);

            fromNode.AddChild(new MuseoNode(colour, to));
            _graph.AddNode(fromNode);
        }
示例#2
0
        public Museomix()
            : base()
        {
            _graphics = new GraphicsDeviceManager(this);
            _graphics.PreferredBackBufferWidth  = 1080;
            _graphics.PreferredBackBufferHeight = 1080;
            _graphics.IsFullScreen = false;
            Content.RootDirectory  = "Content";
            _graph = new Diagram();
            var models = _repository.Models;
            //var pointDic = new Dictionary<Model, System.Windows.Point>();
            //var pointSize = new Dictionary<Model, Size>();
            float center = _graphics.PreferredBackBufferHeight / 2.0f;

            foreach (var m in models)
            {
                _graph.AddNode(new MuseoNode(Color.White, m));
                //pointDic.Add(m, new System.Windows.Point(center, center));
                //pointSize.Add(m , new Size(64, 64));
            }

            //var layoutCtx = new LayoutContext<Model, MuseomixEdge, MuseomixGraph>(_graph, pointDic, pointSize, LayoutMode.Simple);
            //StandardLayoutAlgorithmFactory<Model, MuseomixEdge, MuseomixGraph> factory = new StandardLayoutAlgorithmFactory<Model, MuseomixEdge, MuseomixGraph>();
            //_algo = factory.CreateAlgorithm("Circular", layoutCtx, new CircularLayoutParameters());
            //_algo.Compute();
        }
        /// <inheritdoc/>
        public Action Execute(object parameter)
        {
            if (parameter is Node node)
            {
                _diagram.RemoveNode(node);
                return(() => _diagram.AddNode(node));
            }

            return(() => { });
        }
示例#4
0
        public void BeginInsertingNode(Node node, bool insertCopy = false)
        {
            var nodeTypeName = node.GetType().FullName;
            var nodeToInsert = insertCopy ? _nodeProvider.CreateNodeFromName(nodeTypeName) : node;

            AutoWireTerminals(nodeToInsert);
            nodeToInsert.Visible = false;
            nodeToInsert.Model.X = _diagram.GetDiagramPointFromViewPointX(X);
            nodeToInsert.Model.Y = _diagram.GetDiagramPointFromViewPointX(Y);
            _diagram.AddNode(nodeToInsert);
            ContextTerminal = null;
        }
        private void CreateInputs(Diagram diagram, Diagram outerDiagram, IEnumerable <WireState> inputWireStates, DiagramNode diagramNode)
        {
            foreach (var inputWireState in inputWireStates)
            {
                var inputNode = _nodeProvider.CreateNodeFromName(typeof(DiagramInputNode).FullName) as DiagramInputNode;
                inputNode.X = inputWireState.SourceTerminal.ParentNode.X;
                inputNode.Y = inputWireState.SourceTerminal.ParentNode.Y;
                diagram.AddNode(inputNode);

                var wireCommand = new WireToTerminalCommand(diagram, inputNode.Terminals.First().Model);
                wireCommand.Execute(inputWireState.SinkTerminal);

                var newDiagramNodeTerminal = diagramNode.Terminals.Last().Model;
                wireCommand = new WireToTerminalCommand(outerDiagram, newDiagramNodeTerminal);
                wireCommand.Execute(inputWireState.SourceTerminal);
            }
        }
示例#6
0
        protected void UpdateDirectedGraph()
        {
            mDiagram.Clear();
            parsedKeywords.Clear();

            string ctrSentence = FirstThreeWords(pageSentences[displayedSentenceIndices[0]]);
            Node   node        = new TextNode(surface, ctrSentence);

            ((TextNode)node).Brush = surface.greenBrush;
            mDiagram.AddNode(node);

            // Get the keywords of all sentences for the current sentence or sentences containing the selected keyword.
            List <SentenceInfo> keywords = GetSentencesKeywords();

            keywords = keywords.RemoveDuplicates((si1, si2) => si1.Keyword.ToLower() == si2.Keyword.ToLower()).ToList();
            parsedKeywords.AddRange(keywords.Select(si => si.Keyword.ToLower()));
            AddKeywordsToGraphNode(node, keywords, 0);
            mDiagram.Arrange();
        }
        private void layoutButton_Click(object sender, RoutedEventArgs e)
        {
            var diagram = new Diagram();
            var nodes   = new Dictionary <PlanetDrawing, SpotNode>();

            // add all nodes representing planets to the diagram
            foreach (var planetDrawing in galaxyDrawing.PlanetDrawings)
            {
                var node = new SpotNode();
                diagram.AddNode(node);
                nodes[planetDrawing] = node;
            }
            // add planet links to the diagram
            foreach (var link in galaxyDrawing.LinkDrawings)
            {
                nodes[link.Planet1].AddParent(nodes[link.Planet2]);
            }
            // create the layout
            diagram.Arrange();

            // set planet positions, from their nodes
            var bounds = diagram.GetDiagramBounds();

            foreach (var kvp in nodes)
            {
                var node          = kvp.Value;
                var planetDrawing = kvp.Key;
                // get relative coordinates (0 to 1)
                var x = ((double)node.X - bounds.Left) / bounds.Width;
                var y = ((double)node.Y - bounds.Top) / bounds.Height;
                // add some space between the border and planets
                x = x * 0.8 + 0.1;
                y = y * 0.8 + 0.1;
                // set the planet position
                planetDrawing.Planet.X = x;
                planetDrawing.Planet.Y = y;
                planetDrawing.Position = new Point(x * galaxyDrawing.ImageSource.Width, y * galaxyDrawing.ImageSource.Height);
            }
        }
示例#8
0
        private void GraphDrawing_Load(object sender, EventArgs e)
        {
            List <Node> list = new List <Node>();

            for (int i = 0; i < m_model.States.Count; i++)
            {
                if (m_model.States[i] == null)
                {
                    list.Add(null);
                    continue;
                }
                Node n = new SpotNode(Color.Blue);
                list.Add(n);
                n.ID = i;
            }

            for (int i = 0; i < m_model.States.Count; i++)
            {
                if (m_model.States[i] == null)
                {
                    continue;
                }
                for (int j = 0; j < m_model.States[i].Count; j++)
                {
                    if (m_model.States[i][j] == null)
                    {
                        continue;
                    }
                    list[i].AddChild(list[m_model[i, j].sP]);
                }
            }
            di.AddNode(list[0]);

            Thread bg = new Thread(Draw);

            bg.IsBackground = true;
            bg.Start();
            Thread.Sleep(20);
        }
示例#9
0
 public override void HandleDiagramClick(Point location)
 {
     Diagram.AddNode(nodeBehaviour.CreateNode(location), location);
 }
示例#10
0
        // We will have 3 panels:
        // 1. event type
        // 2. language
        // 3. word cloud of each project description

        protected void Setup()
        {
            rnd = new Random();

            diagramEvents = new Diagram();
            diagramEvents.Arrange();

            diagramDescriptions = new Diagram();
            diagramDescriptions.Arrange();

            diagramLanguages = new Diagram();
            diagramLanguages.Arrange();

            timer          = new System.Windows.Forms.Timer();
            timer.Interval = 1000 / 20;                         // 20 times a second, in milliseconds.
            timer.Tick    += (sender, args) =>
            {
                pnlEvents.Invalidate(true);
                pnlDescriptions.Invalidate(true);
                pnlLanguages.Invalidate(true);
            };

            // Redraw the events word cloud.
            pnlEvents.Paint += (sender, args) =>
            {
                Graphics gr = args.Graphics;
                gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                lock (this)
                {
                    diagramEvents.Iterate(Diagram.DEFAULT_DAMPING, Diagram.DEFAULT_SPRING_LENGTH, Diagram.DEFAULT_MAX_ITERATIONS);
                    diagramEvents.Draw(gr, Rectangle.FromLTRB((int)(pnlEvents.Width * .10), 10, (int)(pnlEvents.Width - pnlEvents.Width * .10), pnlEvents.Height - 20));
                }
            };

            // Redraw the descriptions word cloud.
            pnlDescriptions.Paint += (sender, args) =>
            {
                Graphics gr = args.Graphics;
                gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                lock (this)
                {
                    diagramDescriptions.Iterate(Diagram.DEFAULT_DAMPING, Diagram.DEFAULT_SPRING_LENGTH, Diagram.DEFAULT_MAX_ITERATIONS);
                    diagramDescriptions.Draw(gr, Rectangle.FromLTRB((int)(pnlDescriptions.Width * .10), 10, (int)(pnlDescriptions.Width - pnlDescriptions.Width * .10), pnlDescriptions.Height - 20));
                }
            };

            // Redraw the languages word cloud.
            pnlLanguages.Paint += (sender, args) =>
            {
                Graphics gr = args.Graphics;
                gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                lock (this)
                {
                    diagramLanguages.Iterate(Diagram.DEFAULT_DAMPING, Diagram.DEFAULT_SPRING_LENGTH, Diagram.DEFAULT_MAX_ITERATIONS);
                    diagramLanguages.Draw(gr, Rectangle.FromLTRB((int)(pnlLanguages.Width * .10), 10, (int)(pnlLanguages.Width - pnlLanguages.Width * .10), pnlLanguages.Height - 20));
                }
            };

            // Resize the panel when the form changes.
            SizeChanged += (sender, args) =>
            {
                int w3 = Width / 3 - 30;
                int h3 = Height - 30;

                pnlEvents.Size           = new Size(w3, h3);
                pnlDescriptions.Location = new Point(10 + w3, 10);
                pnlDescriptions.Size     = new Size(w3, h3);

                pnlLanguages.Location = new Point(20 + w3 * 2, 10);
                pnlLanguages.Size     = new Size(w3, h3);
            };

            rootNodeEvents       = new SpotNode(Color.Black);
            rootNodeDescriptions = new SpotNode(Color.Black);
            rootNodeLanguages    = new SpotNode(Color.Black);

            diagramEvents.AddNode(rootNodeEvents);
            diagramDescriptions.AddNode(rootNodeDescriptions);
            diagramLanguages.AddNode(rootNodeLanguages);

            timer.Start();
        }
示例#11
0
        protected void Setup()
        {
            diagram = new Diagram(this);
            rnd     = new Random();
            bool overrun = false;

            diagram.Arrange();

            timer          = new System.Windows.Forms.Timer();
            timer.Interval = 1000 / 20;                         // 20 times a second, in milliseconds.
            timer.Tick    += (sender, args) => pnlCloud.Invalidate(true);

            pnlCloud.Paint += (sender, args) =>
            {
                Graphics gr = args.Graphics;
                gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                ++paintIteration;
                // ReduceCounts();

                if (!overrun)
                {
                    overrun = true;
                    int maxTweets = 20;

                    // We assume here that we can parse the data faster than the incoming stream hands it to us.
                    // But we put in a safety check to handle only 20 tweets.
                    while (tweetQueue.Count > 0 && (--maxTweets > 0))
                    {
                        string tweet;

                        lock (this)
                        {
                            tweet = tweetQueue.Dequeue();
                        }

                        SynchronousUpdate(tweet);
                    }

                    // gr.Clear(Color.White);
                    diagram.Iterate(Diagram.DEFAULT_DAMPING, Diagram.DEFAULT_SPRING_LENGTH, Diagram.DEFAULT_MAX_ITERATIONS);
                    diagram.Draw(gr, Rectangle.FromLTRB(12, 24, pnlCloud.Width - 12, pnlCloud.Height - 36));

                    // gr.DrawString(paintIteration.ToString() + "  " + diagram.Nodes.Count.ToString() + "  " + tweetQueue.Count.ToString() + "  " + diagram.layout.Count.ToString(), font, brushBlack, new Point(3, 3));

                    overrun = false;
                }
                else
                {
                    gr.DrawString("overrun", font, brushBlack, new Point(3, 3));
                }
            };

            pnlCloud.MouseMove  += OnMouseMove;
            pnlCloud.MouseLeave += (sender, args) =>
            {
                if (tweetForm != null)
                {
                    tweetForm.Close();
                    tweetForm = null;
                    mouseWord = String.Empty;
                }
            };

            timer.Start();

            Node node = new SpotNode(Color.Black);

            rootNode = node;
            diagram.AddNode(node);
        }