Modifications pour le document Nuage de tags
Modifié par Jip-jan Alunkel le septembre 23, 13:41
Depuis la version 1.1
modifié par Jip-jan Alunkel
sur février 05, 16:43
sur février 05, 16:43
Commentaire de modification :
Install extension [org.xwiki.platform:xwiki-platform-tag-ui/15.0]
À la version 3.1
modifié par Jip-jan Alunkel
sur septembre 23, 13:41
sur septembre 23, 13:41
Commentaire de modification :
Install extension [org.xwiki.platform:xwiki-platform-tag-ui/15.7]
Résumé
-
Objets (2 modifications, 1 ajouts, 0 suppressions)
Détails
- XWiki.RequiredRightClass[0]
-
- level
-
... ... @@ -1,0 +1,1 @@ 1 +edit
- XWiki.WikiMacroClass[0]
-
- Code de la macro
-
... ... @@ -3,6 +3,10 @@ 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 +#if ("$!limit" != '' && $limit < 0) 8 + #set ($limit = 0) 9 +#end 6 6 ## 7 7 ## Configurable popularity levels. You must enter an even number of levels. Default: 6. 8 8 #set ($popularityLevels = ["notPopular", "notVeryPopular", "somewhatPopular", "popular", "veryPopular", "ultraPopular"]) ... ... @@ -26,22 +26,35 @@ 26 26 ## Get tag count map. Key: tag, value: number of occurrences. 27 27 #set ($tagCount = $xwiki.tag.getTagCount("$!tagCloudSpace")) 28 28 #end 33 +## Organize tags as a list of {name, count} object so that it is easier to handle (sorting, limiting, ...) 34 +#set ($tagCountList = []) 35 +#foreach ($tagName in $tagCount.keySet()) 36 + #set ($discard = $tagCountList.add({ 37 + "name": $tagName, 38 + "count": $tagCount[$tagName] 39 + })) 40 +#end 41 +## If a limit is set, only keep n most occurring tags 42 +## If tags have the same occurrence, limit them in alphabetical order 43 +#set ($tagCountListSorted = $collectiontool.sort($tagCountList, ['count:desc', 'name'])) 44 +#if ("$!limit" != '') 45 + #set ($tagCountListSorted = $tagCountListSorted.subList(0, $mathtool.min($tagCountListSorted.size(), $limit))) 46 +#end 29 29 ## 30 30 ## Only build popularity map if at least one tag exists 31 -#if ($tagCount.size() > 0) 49 +#if ($tagCountListSorted.size() > 0) 32 32 ## 33 33 ## Store the minimum and maximum number of occurrences. 34 - #set ($sortedTagCounts = $collectiontool.sort($tagCount.values())) 35 - #set ($maxIndex = $sortedTagCounts.size() - 1) 36 - #set ($minCount = $sortedTagCounts[0]) 37 - #set ($maxCount = $sortedTagCounts[$maxIndex]) 52 + #set ($maxIndex = $tagCountListSorted.size() - 1) 53 + #set ($maxCount = $tagCountListSorted[0].count) 54 + #set ($minCount = $tagCountListSorted[$maxIndex].count) 38 38 ## 39 39 ## Calculate the total number of tags in the wiki. 40 40 #set ($totalTagNumber = 0) 41 - #foreach ($currentTag Countin $sortedTagCounts)42 - #set ($totalTagNumber = $totalTagNumber + $currentTag Count)58 + #foreach ($currentTag in $tagCountListSorted) 59 + #set ($totalTagNumber = $totalTagNumber + $currentTag.count) 43 43 #end 44 - #set ($countAverage = $mathtool.div($totalTagNumber, $tagCount.size())) 61 + #set ($countAverage = $mathtool.div($totalTagNumber, $tagCountListSorted.size())) 45 45 ## 46 46 ## Build popularity map using the difference between minimum / maximum tag occurrences counts, and the average tag occurences count. 47 47 #set ($firstHalfIntervalSize = $mathtool.div($mathtool.sub($countAverage, $minCount), $levelsHalf)) ... ... @@ -68,17 +68,17 @@ 68 68 ## 69 69 ## Display tag cloud. 70 70 {{html}} 71 -#if ($tagCount.size() > 0) 88 +#if ($tagCountListSorted.size() > 0) 72 72 <ol class="tagCloud"> 73 - #foreach ($tagEntry in $tagCount .entrySet())90 + #foreach ($tagEntry in $collectiontool.sort($tagCountListSorted, 'name')) 74 74 #foreach ($popularityEntry in $popularityMap.entrySet()) 75 - #if ($popularityEntry.Key >= $tagEntry. Value)92 + #if ($popularityEntry.Key >= $tagEntry.count) 76 76 #set ($liClass = $popularityEntry.Value) 77 77 #break 78 78 #end 79 79 #end 80 80 <li class="$liClass"> 81 - <a class="tag" href="$xwiki.getURL('Main.Tags', 'view', "do=viewTag&tag=$escapetool.url($tagEntry. Key)")" title="$services.localization.render('xe.tag.tooltip', [$tagEntry.Value])">$escapetool.xml($tagEntry.Key)</a>98 + <a class="tag" href="$xwiki.getURL('Main.Tags', 'view', "do=viewTag&tag=$escapetool.url($tagEntry.name)")" title="$services.localization.render('xe.tag.tooltip', [$tagEntry.count])">$escapetool.xml($tagEntry.name)</a> 82 82 </li> 83 83 #end 84 84 </ol>
- XWiki.WikiMacroParameterClass[2]
-
- Nom du paramètre
-
... ... @@ -1,0 +1,1 @@ 1 +limit - Description du paramètre
-
... ... @@ -1,0 +1,1 @@ 1 +Max count of tags to be displayed in the cloud - Type du paramètre
-
... ... @@ -1,0 +1,1 @@ 1 +java.lang.Integer - Paramètre obligatoire
-
... ... @@ -1,0 +1,1 @@ 1 +Non