LinQ字体大小显示问题

发布于 2024-10-19 15:33:55 字数 3306 浏览 1 评论 0原文

好的,我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风筝有风,海豚有海 2024-10-26 15:33:55

尝试:

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

我不确定这是否正是您所需要的,但本质上您可以使用条件运算符来解决该问题。第一个参数是最小的字体,不知道它代表什么,所以我将其设置为 1。

Try:

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

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.

戏蝶舞 2024-10-26 15:33:55

只需使用 ?: 运算符:

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

Just use the ?: operator:

weight = (tagGroup.Count() == 1) ? smallestFont : ((double)tagGroup.Count() / maxTagFrequencyNegative * 100)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文