Error in Tagcloud Custom Control and SSJS
Frank van der Linden
3 November 2009 10:58:38
In some Xpage Applications I use the TagCloud Custom Control provided by IBM in the Discussion template. Today I found an error in the SSJS who generates the Tagcloud.
Problem:
In the SSJS 'xpTagClouds' there is a function 'createCloudFromView'.
In this function some variables will be calculated. Two of them are 'high' and 'low'.
These variable are used to calculate the weight of the tag.
When all tags has the same count in the database, the variables 'high' and 'low' will be the same.
var range:int = high-low;
will calculate = 0
Some rows further 'range' will be used to calculate the tag weight, see
cloud[i][TAG_WEIGHT] = Math.round(((ceil / range) * cloud[i][TAG_COUNT]) + (high - factor) / range);
The result of this calculation = NaN.
In the Custom Control cloudArray[TAG_WEIGHT] will be used to define the right Style Class
xspFontSize" + parseInt(cloudArray[TAG_WEIGHT]);
this will result in the Style Class = xspFontSizeNaN.
This Style Class is not defined in the Stylesheet.
Solution:
1) add in Stylesheet a new style class
a.xspFontSizeNaN, a.xspFontSizeNaN:visited{font-size:80%;color:#7bbce7;}
2)avoid NaN calculation in the SSJS and add to the Stylesheeta new style class
SSJS code
if(range =0){
cloud[i][TAG_WEIGHT] 0;
}else{
cloud[i][TAG_WEIGHT] = Math.round(((ceil / range) * cloud[i][TAG_COUNT]) + (high - factor) / range);
}
Stylesheet
a.xspFontSize0, a.xspFontSize0:visited{font-size:80%;color:#7bbce7;}
if(range =0){
cloud[i][TAG_WEIGHT] 0;
}else{
cloud[i][TAG_WEIGHT] = Math.round(((ceil / range) * cloud[i][TAG_COUNT]) + (high - factor) / range);
}
Stylesheet
a.xspFontSize0, a.xspFontSize0:visited{font-size:80%;color:#7bbce7;}
- Comments [2]

