/src/main/webapp/public/js/ie.tagcloud.js

http://thoughtsite.googlecode.com/ · JavaScript · 62 lines · 28 code · 3 blank · 31 comment · 7 complexity · 2aead0c57359891cb92ab9eeefddd129 MD5 · raw file

  1. /* Copyright 2010 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS.
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License
  14. */
  15. /**
  16. * Library for ideaexchange js Tag cloud
  17. *
  18. * @author Abhishek
  19. */
  20. ie.TagCloud = {
  21. /** @Private */
  22. maxSize : 10,
  23. /** @Private */
  24. miSize : 1,
  25. /** @Private */
  26. maxWeight : 10,
  27. /** @Private */
  28. minWeight : 1
  29. };
  30. /**
  31. * prepare tag cloud
  32. */
  33. ie.TagCloud.render = function(jsonData, weights, directive, options) {
  34. if (undefined != weights.maxWeight) {
  35. this.maxWeight = weights.maxWeight;
  36. }
  37. if (undefined != weights.minWeight) {
  38. this.minWeight = weights.minWeight;
  39. }
  40. // ((M-m)/100)*p + m
  41. // TODO: Abhishek, Need to do in exponential series which will work better
  42. var outpuTagCloudHtml = '';
  43. if (0 < jsonData.length) {
  44. // calculate maxWeight and minWeight for tags
  45. for ( var i in jsonData) {
  46. var actualSize = Math.ceil(((jsonData[i][directive['weightage']]/this.maxWeight)*100)/10);
  47. outpuTagCloudHtml += '<a href="';
  48. outpuTagCloudHtml += options.url + jsonData[i][directive['title']];
  49. outpuTagCloudHtml += '" class="' + directive['css']
  50. + actualSize + '">';
  51. outpuTagCloudHtml += jsonData[i][directive['title']];
  52. outpuTagCloudHtml += '(' + jsonData[i][directive['weightage']] + ')</a> ';
  53. }
  54. } else {
  55. // return blank string as no need to generate html
  56. // TODO: Abhishek, Need to define message
  57. }
  58. return outpuTagCloudHtml;
  59. }