标记云字体大小计算逻辑

时间:2011-02-25 18:11:41

标签: c# .net asp.net

这让我疯了。我根据%值显示基于数据库中标签计数的标签云。我注意到,当一个标签被重新启动时,相关的字体大小很大(因为100%被检索),所以有人建议我这样做:

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)**
                   };

现在,当count为1时,字体很小,但是当它为2时,它又回到了巨大的状态。具有较小计数的标签相对于具有最大计数的标签变小 - 但我需要它从小开始并继续增长。请帮忙!

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";
}

3 个答案:

答案 0 :(得分:1)

您可以使用Rad Tag Cloud Control,您的工作将变得更加轻松。 试试这个。

答案 1 :(得分:0)

尝试使用

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";

这个想法是你得到1到0之间的标签的相对大小,然后乘以预期的大小。

希望有所帮助

答案 2 :(得分:0)

您的问题似乎是maxTagFrequencyNegative的价值。

根据您的代码: 当重量> 98,字体大小应该是它最大的。 当重量< 10,字体大小最小。

尝试以下方法:

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

其中maxTagCount是任何给定标记的最大标记数。

要对此进行测试,请尝试手动将maxTagCount设置为接近最大标记数的值,并查看结果是否合理。