Cloud tag font size calculation logic

It drives me crazy. I am showing a tag cloud based on the number of tags in the database based on the% value. I noticed that when one tag was restored, the font size associated with it was huge (because 100% was received), 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, the font is small, but when 2, it becomes huge again. Tags with fewer samples become smaller than tags with the largest number, 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"; } 
+6
source share
3 answers

You can use Rad Tag Cloud Control, and it will be easier to work. Try it.

+1
source share

Try using

 int expectedSize = 36; //Or whatever the max size should be double size = weight / tagGroup.count(); size = max(0, min(size, 1); //bounds size to between 1 and 0 just incase //I'm assuming tagGroup.count() returns the number of tags. replace this as need size = size * expectedSize; return (int)size + "pt"; 

The idea is that you get the relative tag size between 1 and 0, and then multiply it by the expected size.

Hope that helps

0
source share

Your problem looks like maxTagFrequencyNegative value.

Based on your code: When wes> 98, the font size should be the largest for it. When weight <10, the font size is the smallest.

Try the following:

 weight = (tagGroup.Count() == 1) ? (double)1 : ((double)tagGroup.Count() / maxTagCount * 100) 

Where maxTagCount is the largest number of tags for any given tag.

To verify this, try manually setting maxTagCount yourself to something close to the largest tag count and see if your results are reasonable.

0
source share

All Articles