Posted By

noah on 06/11/07


Tagged

qblog


Versions (?)

in Qblog Tag Browser, show tags grouped by frequency


 / Published in: JavaScript
 

more alpha code, some abstractions

  1. //Todo: persistent link to a permalink :)
  2.  
  3. //make a directory of tags by frequency
  4.  
  5. function sortByFrequencyII () {
  6. var tagsByFQ = {};
  7. var tagCount = [];
  8. var sortedTagsByFQ = {};
  9. //make a object whose keys are frequencies and whose values are lists of tag names
  10. for (var name in tags) {
  11. var count = tags[name].frequency;
  12. //acc.push([name, tags[name].frequency]);
  13. (typeof tagsByFQ[count] == 'object' ? tagsByFQ[count].push(name) : tagsByFQ[count] = [name]);
  14. }
  15. //sort the lists of tag names
  16. for (var frequency in tagsByFQ) {
  17. tagsByFQ[frequency].sort();
  18. tagCount.push(+frequency);
  19. }
  20. //sort the keys of the object by frequency
  21. tagCount.sort(asNumbers).reverse();
  22. for (var index=0; index< tagCount.length; index++){
  23. sortedTagsByFQ[tagCount[index]] = tagsByFQ[tagCount[index]];
  24. }
  25. return sortedTagsByFQ;
  26. }
  27.  
  28. showFQ(sortByFrequencyII());
  29.  
  30. function asNumbers (a,b) {
  31. return (a-b);
  32. }
  33.  
  34.  
  35. //frequency clouds
  36. function showFQ (tagsByFQ) {
  37. var html = '';
  38. for (var count in tagsByFQ) {
  39. html += '<br/><h3 style="display: inline; padding-right: 1em;">'+count+'</h3>';
  40. html += makeCloud(tagsByFQ[count]);
  41. }
  42. publishCloud(html);
  43. }
  44.  
  45. function publishCloud (string) {
  46. document.getElementById('display').innerHTML = string;
  47. activateCloud();
  48. }
  49.  
  50. function makeCloud (list) {
  51. var html = '';
  52. for (var i=0; i< list.length; i++) {
  53. var tag = list[i];
  54. html += cloudLink(tag); //cloudlink should be able to also print the related tags in the title, not the count
  55. }
  56. return html;
  57. }

Report this snippet  

You need to login to post a comment.