OK, so I’m using LINQ to generate a tag cloud based on tags in my database. I have a problem that I really can’t seem to figure out. The first time I add a tag, it displays in the biggest font (36pt) – I guess because of the % value calculated, weight takes on the value of 100 and is passed to GetTagSize(). Is there a way to place an if statement where I’m doing this: weight = (double)tagGroup.Count() / maxTagFrequencyNegative * 100
to check for count of 1 and display the smallest font? Thanks for your help!
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 = (double)tagGroup.Count() / maxTagFrequencyNegative * 100
};
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";
}
Try:
I’m not sure if this is exactly what you need, but essentially you could use the conditional operator to work around the issue. The first param would be the smallest font, didn’t know what represents it so I set it at 1.