Чтобы сделать ответ @ Делана более понятным, я создал несколько примеров на языках, с которыми я знаком.
var tags =
[
{ Name: "c#", Uses: 100 },
{ Name: ".net", Uses: 75 },
{ Name: "typescript", Uses: 50 },
{ Name: "lua", Uses: 50 },
{ Name: "javascript", Uses: 25 },
{ Name: "jquery", Uses: 1 },
{ Name: "c++", Uses: 0 },
];
var max = 100; // Should be computed
var min = 0; // Should be computed
var fontMin = 10;
var fontMax = 20;
for (var i in tags)
{
var tag = tags[i];
var size = tag.Uses == min ? fontMin
: (tag.Uses / max) * (fontMax - fontMin) + fontMin;
}
Пример на C #
var tags = new List<Tag>
{
new Tag { Name = "c#", Uses = 100 },
new Tag { Name = ".net", Uses = 75 },
new Tag { Name = "typescript", Uses = 50 },
new Tag { Name = "lua", Uses = 50 },
new Tag { Name = "javascript", Uses = 25 },
new Tag { Name = "jquery", Uses = 5 },
new Tag { Name = "c++", Uses = 5 },
};
int max = tags.Max(o => o.Uses);
int min = tags.Min(o => o.Uses);
double fontMax = 20;
double fontMin = 10;
foreach (var tag in tags)
{
double size = tag.Uses == min ? fontMin
: (tag.Uses / (double)max) * (fontMax - fontMin) + fontMin;
}