Simple tag cloud


/ Published in: Groovy
Save to your folder(s)



Copy this code and paste it in your HTML
  1. static final popularityMap = [(0..9):'notPopular',(10..29):'notVeryPopular',(30..49):'popular',(50..100):'veryPopular',(101..Integer.MAX_VALUE):'ultraPopular']
  2.  
  3. tags = []
  4. 9.times { tags << 'tag1' }
  5. 12.times { tags << 'tag2' }
  6. 44.times { tags << 'tag3' }
  7. 50.times { tags << 'tag4' }
  8. 233.times { tags << 'tag5' }
  9.  
  10. tagsByPopularity = [:]
  11. tags.sort().each { item ->
  12. if(!tagsByPopularity[item]) {
  13. count = tags.count(item)
  14. popularityMap.each { k,v ->
  15. tagsByPopularity[item] = v
  16. }
  17. }
  18. }
  19.  
  20. println tagsByPopularity

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.