PageRenderTime 243ms CodeModel.GetById 120ms app.highlight 4ms RepoModel.GetById 117ms app.codeStats 0ms

/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/**
17 * Library for ideaexchange js Tag cloud
18 * 
19 * @author Abhishek
20 */
21ie.TagCloud = {
22    /** @Private */
23    maxSize : 10,
24    /** @Private */
25    miSize : 1,
26    /** @Private */
27    maxWeight : 10,
28    /** @Private */
29    minWeight : 1
30};
31
32/**
33 * prepare tag cloud
34 */
35ie.TagCloud.render = function(jsonData, weights, directive, options) {
36    if (undefined != weights.maxWeight) {
37        this.maxWeight = weights.maxWeight;
38    }
39    if (undefined != weights.minWeight) {
40        this.minWeight = weights.minWeight;
41    }
42    // ((M-m)/100)*p + m
43    // TODO: Abhishek, Need to do in exponential series which will work better
44    var outpuTagCloudHtml = '';
45    if (0 < jsonData.length) {
46        // calculate maxWeight and minWeight for tags
47
48        for ( var i in jsonData) {
49            var actualSize = Math.ceil(((jsonData[i][directive['weightage']]/this.maxWeight)*100)/10);
50            outpuTagCloudHtml += '<a href="';
51            outpuTagCloudHtml += options.url + jsonData[i][directive['title']];
52            outpuTagCloudHtml += '" class="' + directive['css']
53                    + actualSize + '">';
54            outpuTagCloudHtml += jsonData[i][directive['title']];
55            outpuTagCloudHtml += '(' + jsonData[i][directive['weightage']] + ')</a> ';
56        }
57    } else {
58        // return blank string as no need to generate html
59        // TODO: Abhishek, Need to define message
60    }
61    return outpuTagCloudHtml;
62}