コード例 #1
0
        void SaveXps(string filename)
        {
            Package package = Package.Open(filename, FileMode.Create);
            var     xpsDoc  = new XpsDocument(package);

            XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);

            // zero the VisualOffset
            Size      s = diagram.RenderSize;
            Transform t = diagram.LayoutTransform;
            Point     p = t.Transform(new Point(s.Width, s.Height));

            diagram.Arrange(new Rect(0, 0, p.X, p.Y));
            graphScroller.Content = null;

            var fp = new FixedPage {
                Width = p.X, Height = p.Y
            };

            // Must add the inherited styles before we add the diagram child!
            fp.Resources.MergedDictionaries.Add(Resources);
            fp.Children.Add(diagram);
            xpsWriter.Write(fp);

            // put the diagram back into the scroller.
            fp.Children.Remove(diagram);
            graphScroller.Content = diagram;

            package.Close();
        }
コード例 #2
0
ファイル: Museomix.cs プロジェクト: paulbaron/museomix-ICube
        private void UpdateCriterias()
        {
            var models = _repository.Models;

            _graph.Clear();
            foreach (var c in _criterias)
            {
                switch (c.Name)
                {
                case Model.CriteriaName.Couleur:
                {
                    foreach (var m1 in models)
                    {
                        var sameColours = from m in models where m.Colour == m1.Colour select m;
                        foreach (var m2 in sameColours)
                        {
                            AddNewGraphEdge(c.Colour, m1, m2);
                        }
                    }
                }
                break;

                case Model.CriteriaName.Date:
                {
                    foreach (var m1 in models)
                    {
                        var sameArtists = from m in models where m.Date == m1.Date select m;
                        foreach (var m2 in sameArtists)
                        {
                            AddNewGraphEdge(c.Colour, m1, m2);
                        }
                    }
                }
                break;

                case Model.CriteriaName.Materiau:
                {
                    foreach (var m1 in models)
                    {
                        var sameMaterial = from m in models where m.Material == m1.Material select m;
                        foreach (var m2 in sameMaterial)
                        {
                            AddNewGraphEdge(c.Colour, m1, m2);
                        }
                    }
                }
                break;
                }
            }
            _graph.Arrange();
        }
コード例 #3
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();
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        void Save(string filename)
        {
            try
            {
                BitmapEncoder enc = null;
                string        ext = System.IO.Path.GetExtension(filename);

                switch (ext.ToLower())
                {
                case ".bmp":
                    enc = new BmpBitmapEncoder();
                    break;

                case ".gif":
                    enc = new GifBitmapEncoder();
                    break;

                case ".xaml":
                    using (StreamWriter sw = new StreamWriter(filename, false, System.Text.Encoding.UTF8))
                    {
                        XamlWriter.Save(diagram, sw);
                    }
                    break;

                case ".xps":
                    SaveXps(filename);
                    break;

                case ".png":
                    enc = new PngBitmapEncoder();
                    break;

                case ".jpg":
                    enc = new JpegBitmapEncoder();
                    break;

                case ".dot":
                    break;
                }
                if (enc != null)
                {
                    // reset VisualOffset to (0,0).
                    Size s = this.diagram.RenderSize;
                    diagram.Arrange(new Rect(0, 0, s.Width, s.Height));

                    Transform          t   = this.diagram.LayoutTransform;
                    Point              p   = t.Transform(new Point(s.Width, s.Height));
                    RenderTargetBitmap rmi = new RenderTargetBitmap((int)p.X, (int)p.Y, 1 / 96, 1 / 96, PixelFormats.Pbgra32);
                    rmi.Render(this.diagram);

                    // fix the VisualOffset so diagram doesn't move inside scroller.
                    this.graphScroller.Content = null;
                    this.graphScroller.Content = diagram;

                    using (FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        enc.Frames.Add(BitmapFrame.Create(rmi));
                        enc.Save(fs);
                    }
                }
            }
            catch (System.Exception e)
            {
                MessageBox.Show(e.ToString(), "Save Failed", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #6
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();
        }
コード例 #7
0
ファイル: GraphDrawing.cs プロジェクト: efeysoy/rl_smdp
 private void Draw()
 {
     di.Arrange();
     Invalidate();
 }
コード例 #8
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);
        }