Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tag cloud font size calculation logic

Tags:

c#

.net

asp.net

This is driving me insane. I am displaying a tag cloud based on the count of a tag in the database based on a % value. I noticed that when one tag was retrived, the associated font size was huge (because 100% was retrieved), so some suggested I do this:

var tagSummaryNegative = from af in db.AgileFactors
                     join psf in db.ProjectStoryFactors on af.AgileFactorID equals psf.AgileFactorID
                     join s in db.Stories on psf.StoryID equals s.StoryID
                     join pim in db.ProjectIterationMembers on s.ProjectIterationMemberID equals pim.ProjectIterationMemberID
                     join it in db.Iterations on pim.ProjectIterationID equals it.ProjectIterationID
                     join pro in db.Projects on it.ProjectID equals pro.ProjectID
                     where pro.ProjectID == pro_id &&
                           pro.ProjectID == it.ProjectID &&
                           it.ProjectIterationID == pim.ProjectIterationID &&
                           pim.ProjectIterationMemberID == s.ProjectIterationMemberID && s.StoryCategoryID == 1 &&
                           s.StoryID == psf.StoryID &&
                           psf.AgileFactorID == af.AgileFactorID
                     group af by af.Name into tagGroup

                     select new
                     {

                         Tag = tagGroup.Key,
                         tagCount = tagGroup.Count()

                     };

int maxTagFrequencyNegative = (from t in tagSummaryNegative select (int?)t.tagCount).Max() ?? 0;

var tagCloudNegative = from af in db.AgileFactors
                   join psf in db.ProjectStoryFactors on af.AgileFactorID equals psf.AgileFactorID
                   join s in db.Stories on psf.StoryID equals s.StoryID
                   join pim in db.ProjectIterationMembers on s.ProjectIterationMemberID equals pim.ProjectIterationMemberID
                   join it in db.Iterations on pim.ProjectIterationID equals it.ProjectIterationID
                   join pro in db.Projects on it.ProjectID equals pro.ProjectID
                   where pro.ProjectID == pro_id &&
                         pro.ProjectID == it.ProjectID &&
                         it.ProjectIterationID == pim.ProjectIterationID &&
                         pim.ProjectIterationMemberID == s.ProjectIterationMemberID && s.StoryCategoryID == 1 &&
                         s.StoryID == psf.StoryID &&
                         psf.AgileFactorID == af.AgileFactorID
                   group af by af.Name into tagGroup
                   select new
                   {

                       Tag = tagGroup.Key,
                       **weight = (tagGroup.Count() == 1) ? (double)1 : ((double)tagGroup.Count() / maxTagFrequencyNegative * 100)**
                   };

Now, when count is 1, font is small, but when 2, it's back to being huge again. The tags with the smaller count get smaller relative to the tag with the largest count - but I need it to start small and keep growing. Please help!

public string GetTagSize(double weight)
{

    if (weight >= 99)
        return "36pt";
    else if (weight >= 80)
        return "29pt";
    else if (weight >= 64)
        return "23pt";
    else if (weight >= 48)
        return "18pt";
    else if (weight >= 32)
        return "14pt";
    else if (weight >= 10)
        return "11pt";
    else
        return "8pt";
}
like image 772
Aligator3000 Avatar asked Feb 25 '11 18:02

Aligator3000


1 Answers

You can use Rad Tag Cloud Control and you work will be easier. Try this.

like image 72
Mohan Sharma Avatar answered Sep 29 '22 05:09

Mohan Sharma