jquery - Javascript Tag cloud font size rolling over after 10 occurrances -


i have json string db gets fed script below, basic tag cloud font size being increased based on frequency. problem once frequency hits ten (10), font size goes same if one. i've had similar problems passing string in php instead of int, not case here.

{"tags":[{"tag":"programming","freq":11}]}

$(function() {    $.getjson("tagcloud.php", function(data) {      $("<ul>").attr("id", "taglist").appendto("#tagcloud");      //create tags     $.each(data.tags, function(i, val) {        //create item       var li = $("<li class=\"taginfo\">");        //create link       $("<a>").text(val.tag).attr({class:"a",href:"index.php?page=tagdata&tagname=" + val.tag }).appendto(li);        /*if set first equation more frequency (10000 here caution), works fine.         equation in line commented out `(val.freq / 10 < 1) not       giving me correct output.  missing ensuring variable        int in js after it's retrieved in json? */       li.children("a").css("fontsize", (val.freq / 10000 < 1) ? val.freq / 10 + 1 + "em": (val.freq / 10 > 2) ? "2em" : val.freq / 10 + "em");                              //li.children("a").css("fontsize", (val.freq / 10 < 1) ? val.freq / 10 + 1 + "em": (val.freq / 10 > 2) ? "2em" : val.freq / 10 + "em");                               //add list       li.appendto("#taglist");     });            }); }); 

try (never mind syntax changes -- it's readability):

li.children("a").css("fontsize",      ((val.freq / 20) <= 1 ? (val.freq / 20) + 1 :       (val.freq / 10) >= 2 ? 2 : (val.freq / 10)) + "em");  

why...

due initial use of less < expression, rather <=, algorithm negates 10 / 10 true , ends in "else" segment of ternary statement (returning 1em).

another issue going run you've limited small range of values -- in case, font sizes. currently, equation results in following:

 divisor | frequency | product | size (em) -------------------------------------------     10        1          0.1       1.1     10        2          0.2       1.2     10        3          0.3       1.3     10        4          0.4       1.4     10        5          0.5       1.5     10        6          0.6       1.6     10        7          0.7       1.7     10        8          0.8       1.8      10        9          0.9       1.9     10        10         1.0       1.0      10        11         0.1       1.1     10        12         0.2       1.2     ...       ...        ...       ... 

you can resolve issue scale up, 1.05em 2em (with increments of .05em), changing divisor 10, 20. make sure size keeps scaling until hits threshold, 2em.

i suggest marking of variables size scales every 1 hit, , stops scaling @ 20 hits. know, 20 -> 200, 10 -> 100. either way...


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -