Hi Thomas,
this looks quite cool!
There is a place on
XWiki.org for this kind of contributions (
http://www.xwiki.org/xwiki/bin/view/Code/), it would be very cool if you
could add it there with a step by step explanation of how to use it (for
instance in my case I have no idea where I am supposed to put the Java code
- though I'm not actually a developer).
Even better would be to export the XAR of your XWiki, customize it to keep
only the Main.TagCloud , Panels.TagCloud
(and other pages required to make it work) and then upload it to
XWiki.orglike it is done for other applications already. To do so
easily you can even
download first the Packager Application here:
http://www.xwiki.org/xwiki/bin/view/Code/PackagerApplication and use it to
generate your XAR (which at the same time gives you an example of the page
you could create for yours :-)
Funny thing is that I was wondering about tag cluds this afternoon but had
no idea how to implement one :-) Thanks!
Guillaume
On 30/05/07, Thomas Drevon <thomas.drevon(a)intermedia.uio.no> wrote:
Hi!
Tag clouds (
http://en.wikipedia.org/wiki/Tag_cloud) seem so in these
days, so I made a simple implementation using the Main.Tags in xwiki.
The styling isn't too sexy, but that should be easy to configure.
Here is the code for use in a panel or similar place:
#panelheader('Tag cloud')
#set($query = "select elements(prop.list) from BaseObject as obj,
DBStringListProperty as prop where obj.className='XWiki.TagClass' and
obj.id=prop.id.id and prop.id.name='tags'")
#set( $allTags = $xwiki.sort($xwiki.search($query)))
#set( $tagsWithCount = $xwiki.metawiki.getTagsWithCount($allTags))
#set($query = "select distinct elements(prop.list) from BaseObject as
obj, DBStringListProperty as prop where obj.className='XWiki.TagClass'
and obj.id=prop.id.id and prop.id.name='tags'")
#set( $tagsDistinct = $xwiki.sort($xwiki.search($query)))
#foreach($tag in $tagsDistinct)
<span style="#getStyle($tagsWithCount.get($tag))"><a
href="$xwiki.getURL("Main.Tags", "view",
"tag=$tag")")>$tag</a></span>
#end
#panelfooter()
#macro( getStyle $count )
#if ($count < 2) "font-size: 0.80em;"
#elseif ($count < 3) font-size: 1.00em; }
#elseif ($count < 4) font-size: 1.20em; }
#elseif ($count < 5) font-size: 1.40em; }
#elseif ($count < 6) font-size: 1.60em; }
#elseif ($count < 7) font-size: 1.80em; }
#elseif ($count < 8) font-size: 2.00em; }
#else font-size: 2.50em; }
#end
#end
And here's the java code invoked:
public static HashMap<String, Integer>
getTagsWithCount(ArrayList<String> allTags) {
String tag = null;
String previousTag = null;
HashMap<String, Integer> tagsWithCount = new HashMap<String, Integer>();
int count = 1;
for (int i = 0; i < allTags.size(); i++) {
previousTag = tag;
tag = allTags.get(i);
if (tag.equals(previousTag)) {
count++;
} else {
count = 1;
previousTag = null;
}
tagsWithCount.put(tag, new Integer(count));
}
return tagsWithCount;
}
Is this anything you would want to include in xwiki, or is it too
trivial to bother with? See the attached file for a sample screenshot.
best regards :-)
Thomas Drevon
--
You receive this message as a subscriber of the xwiki-dev(a)objectweb.orgmailing list.
To unsubscribe: mailto:xwiki-dev-unsubscribe@objectweb.org
For general help: mailto:sympa@objectweb.org?subject=help
ObjectWeb mailing lists service home page:
http://www.objectweb.org/wws
--
http://wikibc.blogspot.com/