Hi,
I have some observations:
- The java code can be transformed into a velocity macro. You can
create a hashmap with $xwiki.getHashMap(), and you have #foreach, #if
and #set. So there's no need for java or groovy code
- The style isn't that extensible (1..8 as possible repetitions). You
could also compute the maximum occurance count, and then use relative
importance expressed as relative font size. For example, set font-size
for the surrounding div to 3em, and for each tag
font-size=<crtTagCount>*100/<maxTagCount> %. I think this should work.
- Something I was saying just yesterday when discussing tag suggest,
we need a cache for the tags, as the query is resource hungry when you
have a large wiki (think flickr size...). This is something a bit
harder, and you don't have to do it. It will have to be integrated
later.
Anyway, great initiative, and good job!
Sergiu
On 5/31/07, Vincent Massol <vincent(a)massol.net> wrote:
Hi Thomas,
I didn't see your email below (was it sent to the list?).
I'm all for offering a default tag cloud page/panel.
The notion of tag is not something known to XWiki core. Currently tags are
only known at the level of the default wiki so we should probably put the
tag cloud code there. As your code below requires some logic, maybe the best
is to use Groovy to replace the Java part. You could then have everything
located on a single page.
The next question is: a Panel or a Page?
I'm tempted to say both. I think we should include the tag cloud in the
Main.Tags page and we could provide a Panel too.
WDYT?
I have created a jira issue for this:
http://jira.xwiki.org/jira/browse/XWIKI-1311
Would you be interested in working on this and finishing this?
If so, could you please attach the result to that JIRA issue for inclusion
in SVN?
Thanks a lot
-Vincent
On May 31, 2007, at 1:42 AM, Guillaume Lerouge wrote:
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.org
like 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:
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
>