Skip to content

Commit

Permalink
Merge pull request #1202 from naokiy/same_tag_count
Browse files Browse the repository at this point in the history
Fix the problem that occurs when every tag has the same number of posts.
  • Loading branch information
tommy351 committed Apr 15, 2015
2 parents 2f0a24c + 83842f6 commit 56bfc43
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/plugins/helper/tagcloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ function tagcloudHelper(tags, options){
var length = sizes.length - 1;

tags.forEach(function(tag){
var index = sizes.indexOf(tag.length);
var size = min + (max - min) / length * index;
var ratio = length? (sizes.indexOf(tag.length) / length): 0;
var size = min + (max - min) * ratio;
var style = 'font-size: ' + parseFloat(size.toFixed(2)) + unit + ';';

if (color){
var midColor = startColor.mix(endColor, index / length);
var midColor = startColor.mix(endColor, ratio);
style += ' color: ' + midColor.toString();
}

Expand Down
28 changes: 28 additions & 0 deletions test/scripts/helpers/tagcloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ describe('tagcloud', function(){
].join(''));
});

it('font size - when every tag has the same number of posts, font-size should be minimum.', function() {
var result = tagcloud(Tag.find({
name: /abc/
}), {
min_font: 15,
max_font: 30
});

result.should.eql([
'<a href="/tags/abc/" style="font-size: 15px;">abc</a>'
].join(''));
});

it('font unit', function(){
var result = tagcloud({
unit: 'em'
Expand Down Expand Up @@ -199,4 +212,19 @@ describe('tagcloud', function(){
'<a href="/tags/def/" style="font-size: 10px; color: rgba(70, 130, 180, 0.3)">def</a>'
].join(''));
});

it('color - when every tag has the same number of posts, start_color should be used.', function() {
var result = tagcloud(Tag.find({
name: /abc/
}), {
color: true,
start_color: 'red',
end_color: 'pink'
});

result.should.eql([
'<a href="/tags/abc/" style="font-size: 10px; color: #f00">abc</a>'
].join(''));
});

});

0 comments on commit 56bfc43

Please sign in to comment.