Changes for page Tag Cloud

Last modified by Tobias Wintrich on 2025/06/04 09:20

From version 4.1
edited by Tobias Wintrich
on 2023/03/20 11:07
Change comment: Install extension [org.xwiki.platform:xwiki-platform-tag-ui/15.1]
To version 3.1
edited by Tobias Wintrich
on 2022/10/28 15:29
Change comment: Install extension [org.xwiki.platform:xwiki-platform-tag-ui/14.9]

Summary

Details

XWiki.WikiMacroClass[0]
Macro code
... ... @@ -3,7 +3,6 @@
3 3  ## tagCloudSpace - the space to display the tag cloud for. If blank, display cloud for the whole wiki. Default is blank.
4 4  #set ($tagCloudSpace = $xcontext.macro.params.get('space'))
5 5  #set ($tagCloudSpaces = $xcontext.macro.params.get('spaces'))
6 -#set ($limit = $xcontext.macro.params.get('limit'))
7 7  ##
8 8  ## Configurable popularity levels. You must enter an even number of levels. Default: 6.
9 9  #set ($popularityLevels = ["notPopular", "notVeryPopular", "somewhatPopular", "popular", "veryPopular", "ultraPopular"])
... ... @@ -27,35 +27,22 @@
27 27   ## Get tag count map. Key: tag, value: number of occurrences.
28 28   #set ($tagCount = $xwiki.tag.getTagCount("$!tagCloudSpace"))
29 29  #end
30 -## Organize tags as a list of {name, count} object so that it is easier to handle (sorting, limiting, ...)
31 -#set ($tagCountList = [])
32 -#foreach ($tagName in $tagCount.keySet())
33 - #set ($discard = $tagCountList.add({
34 - "name": $tagName,
35 - "count": $tagCount[$tagName]
36 - }))
37 -#end
38 -## If a limit is set, only keep n most occurring tags
39 -## If tags have the same occurrence, limit them in alphabetical order
40 -#set ($tagCountListSorted = $collectiontool.sort($tagCountList, ['count:desc', 'name']))
41 -#if ("$!limit" != '')
42 - #set ($tagCountListSorted = $tagCountListSorted.subList(0, $limit))
43 -#end
44 44  ##
45 45  ## Only build popularity map if at least one tag exists
46 -#if ($tagCountListSorted.size() > 0)
31 +#if ($tagCount.size() > 0)
47 47   ##
48 48   ## Store the minimum and maximum number of occurrences.
49 - #set ($maxIndex = $tagCountListSorted.size() - 1)
50 - #set ($maxCount = $tagCountListSorted[0].count)
51 - #set ($minCount = $tagCountListSorted[$maxIndex].count)
34 + #set ($sortedTagCounts = $collectiontool.sort($tagCount.values()))
35 + #set ($maxIndex = $sortedTagCounts.size() - 1)
36 + #set ($minCount = $sortedTagCounts[0])
37 + #set ($maxCount = $sortedTagCounts[$maxIndex])
52 52   ##
53 53   ## Calculate the total number of tags in the wiki.
54 54   #set ($totalTagNumber = 0)
55 - #foreach ($currentTag in $tagCountListSorted)
56 - #set ($totalTagNumber = $totalTagNumber + $currentTag.count)
41 + #foreach ($currentTagCount in $sortedTagCounts)
42 + #set ($totalTagNumber = $totalTagNumber + $currentTagCount)
57 57   #end
58 - #set ($countAverage = $mathtool.div($totalTagNumber, $tagCountListSorted.size()))
44 + #set ($countAverage = $mathtool.div($totalTagNumber, $tagCount.size()))
59 59   ##
60 60   ## Build popularity map using the difference between minimum / maximum tag occurrences counts, and the average tag occurences count.
61 61   #set ($firstHalfIntervalSize = $mathtool.div($mathtool.sub($countAverage, $minCount), $levelsHalf))
... ... @@ -82,17 +82,17 @@
82 82  ##
83 83  ## Display tag cloud.
84 84  {{html}}
85 -#if ($tagCountListSorted.size() > 0)
71 +#if ($tagCount.size() > 0)
86 86   <ol class="tagCloud">
87 - #foreach ($tagEntry in $collectiontool.sort($tagCountListSorted, 'name'))
73 + #foreach ($tagEntry in $tagCount.entrySet())
88 88   #foreach ($popularityEntry in $popularityMap.entrySet())
89 - #if ($popularityEntry.Key >= $tagEntry.count)
75 + #if ($popularityEntry.Key >= $tagEntry.Value)
90 90   #set ($liClass = $popularityEntry.Value)
91 91   #break
92 92   #end
93 93   #end
94 94   <li class="$liClass">
95 - <a class="tag" href="$xwiki.getURL('Main.Tags', 'view', "do=viewTag&amp;tag=$escapetool.url($tagEntry.name)")" title="$services.localization.render('xe.tag.tooltip', [$tagEntry.count])">$escapetool.xml($tagEntry.name)</a>
81 + <a class="tag" href="$xwiki.getURL('Main.Tags', 'view', "do=viewTag&amp;tag=$escapetool.url($tagEntry.Key)")" title="$services.localization.render('xe.tag.tooltip', [$tagEntry.Value])">$escapetool.xml($tagEntry.Key)</a>
96 96   </li>
97 97   #end
98 98   </ol>
XWiki.WikiMacroParameterClass[2]
Parameter description
... ... @@ -1,1 +1,0 @@
1 -Max count of tags to be displayed in the cloud
Parameter mandatory
... ... @@ -1,1 +1,0 @@
1 -No
Parameter name
... ... @@ -1,1 +1,0 @@
1 -limit
Parameter type
... ... @@ -1,1 +1,0 @@
1 -java.lang.Integer