Created
October 3, 2019 15:55
-
-
Save Defcoq/c5d3519e982f8b247ed961b91d5740cb to your computer and use it in GitHub Desktop.
the tagcloud class for view components demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TagCloud | |
{ | |
public int MaxSize { get; set; } | |
public int MinSize { get; set; } | |
public string BaseLinkClassName { get; set; } | |
public string ContainerClassName { get; set; } | |
private List<TagCloudItem> _Items { get; set; } | |
private int minRank = 1; | |
private int maxRank = 1; | |
public ReadOnlyCollection<TagCloudItem> Items | |
{ | |
get | |
{ | |
if (_Items != null) | |
{ | |
var readOnlyCollection = new ReadOnlyCollection<TagCloudItem>(_Items); | |
return readOnlyCollection; | |
} | |
return null; | |
} | |
} | |
public void AddItem(TagCloudItem item) | |
{ | |
_Items.Add(item); | |
minRank = _Items.Min(x => x.Weight); | |
maxRank = _Items.Max(x => x.Weight); | |
} | |
public TagCloud() | |
{ | |
MaxSize = 10; | |
MinSize = 1; | |
BaseLinkClassName = "linkLevel-"; | |
ContainerClassName = "tagcloud"; | |
_Items = new List<TagCloudItem>(); | |
} | |
public string GetLinkItemClassName(TagCloudItem item) | |
{ | |
int itemCount = Items.Count; | |
if (maxRank == MaxSize && minRank == MinSize) | |
{ | |
return string.Concat(BaseLinkClassName, item.Weight); | |
} | |
int normalizedRank = 1 + (item.Weight - minRank) * | |
(MaxSize - 1) / (maxRank - minRank); | |
return string.Concat(BaseLinkClassName, normalizedRank); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment