Esempio n. 1
0
    /// <inheritdoc cref="ILayout"/>
    /// <summary>
    /// Arranges the words on the graphics engine.
    /// </summary>
    /// <param name="words">The words.</param>
    /// <param name="graphicEngine">The graphics engine.</param>
    /// <returns>The word count.</returns>
    /// <seealso cref="ILayout"/>
    public int Arrange(IEnumerable <IWord> words, IGraphicEngine graphicEngine)
    {
        if (words == null)
        {
            throw new ArgumentNullException(nameof(words));
        }

        var enumerable = words as IWord[] ?? words.ToArray();

        if (enumerable.First() == null)
        {
            return(0);
        }

        foreach (var word in enumerable)
        {
            var size = graphicEngine.Measure(word.Text, word.Occurrences);

            if (!this.TryFindFreeRectangle(size, out var freeRectangle))
            {
                break;
            }

            var item = new LayoutItem(freeRectangle, word);
            this.QuadTree.Insert(item);
            graphicEngine.Draw(item);
        }

        return(this.QuadTree.Count);
    }
Esempio n. 2
0
        public int Arrange(IEnumerable <IWord> words, IGraphicEngine graphicEngine)
        {
            if (words == null)
            {
                throw new ArgumentNullException("words");
            }

            if (words.First() == null)
            {
                return(0);
            }


            foreach (IWord word in words)
            {
                Size      size = graphicEngine.Measure(word.Text, word.Occurrences);
                Rectangle freeRectangle;
                if (!TryFindFreeRectangle(size, out freeRectangle))
                {
                    break;
                }
                LayoutItem item = new LayoutItem(freeRectangle, word);
                QuadTree.Insert(item);
            }
            return(QuadTree.Count);
        }
Esempio n. 3
0
        public override int Arrange(IEnumerable <IWord> words, IGraphicEngine graphicEngine)
        {
            if (words == null)
            {
                throw new ArgumentNullException("words");
            }

            // See if all the words will fit on the page
            words = words.SortByText();
            int maxWords = words.Count();
            int numWords = base.Arrange(words, graphicEngine);

            if (m_SavingToImage || (numWords >= maxWords))
            {
                return(numWords);
            }

            // else
            while (numWords < maxWords)
            {
                // Remove the 'extra' tasks and see if what's left fits
                var temp = new List <IWord>(words.SortByOccurrences());
                temp.RemoveRange(numWords, (maxWords - numWords));

                Reset();

                words = temp.SortByText();

                maxWords = numWords;
                numWords = base.Arrange(words, graphicEngine);
            }

            return(numWords);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (m_Words == null || !m_Words.Any())
            {
                return;
            }
            if (m_Layout == null)
            {
                return;
            }

            IEnumerable <LayoutItem> wordsToRedraw = m_Layout.GetWordsInArea(e.ClipRectangle);

            using (IGraphicEngine graphicEngine =
                       NewGraphicEngine(e.Graphics, this.Font.FontFamily, FontStyle.Regular, m_Palette, MinFontSize, MaxFontSize, m_MinWordWeight, m_MaxWordWeight))
            {
                foreach (LayoutItem currentItem in wordsToRedraw)
                {
                    if (m_ItemUnderMouse == currentItem)
                    {
                        graphicEngine.DrawEmphasized(currentItem);
                    }
                    else
                    {
                        graphicEngine.Draw(currentItem);
                    }
                }
            }
        }
        virtual public int Arrange(IEnumerable <IWord> words, IGraphicEngine graphicEngine)
        {
            if (words == null)
            {
                throw new ArgumentNullException("words");
            }

            int numWords = 0;

            foreach (IWord word in words)
            {
                SizeF      size = graphicEngine.Measure(word);
                RectangleF freeRectangle;

                if (!TryFindFreeRectangle(size, out freeRectangle))
                {
                    break;
                }

                // else
                LayoutItem item = new LayoutItem(freeRectangle, word);
                QuadTree.Insert(item);
                numWords++;
            }

            return(numWords);
        }
Esempio n. 6
0
 public WordCloudGenerator(WordCloudInput wordCloud,
                           IGraphicEngine <TBitmap> engine, ILayout layout)
 {
     this.wordCloud = wordCloud;
     this.engine    = engine;
     this.layout    = layout;
 }
Esempio n. 7
0
 public int Arrange(IEnumerable <WordCloudEntry> entries, IGraphicEngine engine)
 {
     foreach (var entry in entries)
     {
         RectangleD measured = engine.Measure(entry.Word, entry.Count);
         if (!TryFindFreeRectangle(measured.Size, out var freeRectangle))
         {
             break;
         }
         QuadTree.Insert(new LayoutItem(entry, freeRectangle.Location, measured));
     }
     return(QuadTree.Count);
 }
Esempio n. 8
0
        public void Arrange(IEnumerable <ITerm> terms, IGraphicEngine graphicEngine)
        {
            if (terms == null)
            {
                throw new ArgumentNullException("terms");
            }

            foreach (ITerm term in terms)
            {
                SizeF      size = graphicEngine.Measure(term.Text, term.Occurrences);
                RectangleF freeRectangle;
                if (!TryFindFreeRectangle(size, out freeRectangle))
                {
                    return;
                }
                LayoutItem item = new LayoutItem(freeRectangle, term);
                QuadTree.Insert(item);
            }
        }
Esempio n. 9
0
        public void Arrange(IEnumerable<IWord> words, IGraphicEngine graphicEngine)
        {
            if (words == null)
            {
                throw new ArgumentNullException("words");
            }

            foreach (IWord word in words)
            {
                SizeF size = graphicEngine.Measure(word.Text, word.Occurrences);
                RectangleF freeRectangle;
                if (!TryFindFreeRectangle(size, out freeRectangle))
                {
                    return;
                }
                LayoutItem item = new LayoutItem(freeRectangle, word);
                QuadTree.Insert(item);
            }
        }
Esempio n. 10
0
        public void Arrange(IEnumerable <IWord> words, IGraphicEngine graphicEngine)
        {
            if (words == null)
            {
                throw new ArgumentNullException("words");
            }

            foreach (IWord word in words)
            {
                SizeF      size = graphicEngine.Measure(word);
                RectangleF freeRectangle;
                if (!TryFindFreeRectangle(size, out freeRectangle))
                {
                    return;
                }
                LayoutItem item = new LayoutItem(freeRectangle, word);
                QuadTree.Insert(item);
            }
        }
Esempio n. 11
0
 public static void initializeEngines(IGraphicEngine graphicEngine,
     IGeometryEngine geometryEngine)
 {
     _graphicEngine = graphicEngine;
     _geometryEngine = geometryEngine;
 }
Esempio n. 12
0
 public static void initializeEngines(IGraphicEngine graphicEngine,
                                      IGeometryEngine geometryEngine)
 {
     _graphicEngine  = graphicEngine;
     _geometryEngine = geometryEngine;
 }