private bool TryPlaceWord(WordsStatistic wordsStatistic, out TagCloudElement tagCloudElement)
 {
     var font = GetFont(wordsStatistic.Count);
     var boundsRect = _measureString(wordsStatistic.Word, font);
     Point location;
     if (!TryGetLocationForRect(boundsRect, out location))
     {
         tagCloudElement = null;
         return false;
     }
     var position = new Rectangle(location, boundsRect);
     _badPlaces.Add(position);
     tagCloudElement = new TagCloudElement(wordsStatistic.Word, position, GetRandomColor(), font);
     return true;
 }
Example #2
0
    private void drawTable(TagCloudElement[] elements)
    {
        if (elements != null && elements.Length > 0)
        {
            StringBuilder sb = new StringBuilder();

            ComparerUtility comparer = new ComparerUtility();
            comparer.ObjectType = typeof(TagCloudElement);
            comparer.SortingOrder = (int)ComparerUtility.SortOrder.Ascending;
            comparer.SortProperty = "TagName";
            Array.Sort(elements, comparer);

            foreach (TagCloudElement tce in elements)
            {
                sb.Append("<a title='" + tce.TagName + "' ");
                sb.Append("class='").Append(getFontSize(tce.Importance)).Append(" ");
                sb.Append(getFontColor(tce.Recency)).Append("' ");
                if (IsSafari)
                {
                    string s = tce.TagName.Replace(" ", "%20").Replace("\"", "\\\"");

                    sb.Append("href=javascript:document.location=\"searchbytag.aspx?tag=\"+lambdaEncode(\"");
                    sb.Append(s);
                    sb.Append("\");>");
                }
                else
                {
                    string s = tce.TagName.Replace(" ", "%20").Replace("\"", "\\\"");

                    sb.Append("href=javascript:document.location=\"searchbytag.aspx?tag=\"+lambdaEncode(\"");
                    sb.Append(s);
                    sb.Append("\");>");
                }
                if (tce.IsDedicated)
                {
                    sb.Append("*").Append(tce.TagName);
                }
                else
                {
                    sb.Append(tce.TagName);
                }
                sb.Append("</a> ");
            }
            div = sb.ToString();
        }
    }