do { Engine.BlogAbout(".NET","Silverlight"); } while ( alive );  

Mark Monster

Mark Monster  

The advantage of the TagCloud

While looking at the TagCloud below I thought, there are some things that can be done better. The article on the original TagCloud can be found here.Like:

  • A middle alignment for all items in a row
  • An equal divided space between items in a row

The old TagCloud.

So what I did is take the original code from the WrapPanel and did some refactoring first. I changed the ArrangeOverride method to become a two phase step. The first step is to determine which items become in which row. I put those items in a two-dimensional collection. The next step is the actual arranging of the elements. One of the pieces of code for the arrange does determine which element is the largest in Height in a specific row. Besides this it also measures the total width of the elements in the row which is use to calculate the space needed between the elements.

1 double largestHeightInRow = elementsRow.Max(element => element.DesiredSize.Height); 2 double widthOfRow = elementsRow.Sum(element => element.DesiredSize.Width); 3 double betweenElements = (finalSize.Width-widthOfRow)/(elementsRow.Count + 1);

This all combined results in the following TagCloud.

The new TagCloud.

The updated source can be found here.

3 Responses to “The advantage of the TagCloud”

  1. unruledboy Says:

    good update, maybe allow specifying text color will be better

  2. Silverlight Travel Says:

    I think it is better to let it like it is. With colors you will disturb the visibility.

  3. Silverlight Cream for August 25, 2008 -- #355 Says:

    [...] In this first one, he deals with syndication in Silverlight, but still using Drupal for the data. The advantage of the TagCloud Mark Monster revisits his Silverlight Tag Cloud and provides some nice modifications. Cutting Shapes [...]

Leave a Reply