LinQ字体大小显示问题
好的,我正在使用 LINQ 根据数据库中的标签生成标签云。我有一个问题,我似乎真的无法弄清楚。我第一次添加标签时,它以最大的字体(36pt)显示 - 我猜由于计算的%值,权重的值为100并传递给GetTagSize()。有没有办法在我这样做的地方放置 if 语句:weight = (double)tagGroup.Count() / maxTagFrequencyNegative * 100 检查计数是否为 1 并显示最小字体?感谢您的帮助!
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";
}
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";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
我不确定这是否正是您所需要的,但本质上您可以使用条件运算符来解决该问题。第一个参数是最小的字体,不知道它代表什么,所以我将其设置为 1。
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.
只需使用
?:
运算符:Just use the
?:
operator: