2011-02-25 74 views
6

這讓我瘋狂。我正在基於%值基於數據庫中標記的計數顯示標記雲。我注意到,當一個標籤被retrived,相關的字體大小是巨大的(因爲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)** 
        }; 

現在,當計數爲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"; 
} 
+0

'maxTagFrequencyNegative'的值是什麼?爲什麼你會用一個負值來分割? – Justin 2011-02-25 18:16:11

+0

這不是一個負值 - 我使用的是LINQ ... maxTagFrequencyNegative只是帶有相關負面故事的標籤的別名... – user618616 2011-02-25 18:18:12

+0

+1對於推薦對人們很好,它只會鼓勵一個良好的社區,如果您獎勵回答你喜歡/用過 – 2011-02-25 18:23:34

回答

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之間的標籤的相對大小然後通過預期的大小相乘這一點。

希望幫助

0

您的問題似乎是maxTagFrequencyNegative值。

根據您的代碼: 當體重> 98時,字體大小應該是最大的。 當重量爲< 10時,字體大小最小。

嘗試以下操作:

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

哪裏maxTagCount是最大數量的標籤,對於任何給定的標籤。

要測試此操作,請嘗試手動將自己設置爲maxTagCount以接近最大標記計數,並查看您的結果是否合理。

1

您可以使用Rad Tag Cloud Control,您的工作會更輕鬆。 試試這個。