Syntaxes Distribution Chart
Last modified by Vincent Massol on 2021/03/18 11:28
Displays a pie chart representing the distribution of syntaxes for pages on the current wiki |
Type | Snippet |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Table of contents
Description
Code in XWiki Syntax 2.0
Graph distribution
For XE versions >= 6.1:
{{velocity}}
## Get all available syntaxes for writing a wiki page
#set($syntaxes = $services.rendering.availableParserSyntaxes)
## For each syntax count the number of pages written in that syntax and save the result in a map for later use in the chart macro.
#set ($results = {})
#foreach($syntax in $syntaxes)
#set ($count = $services.query.xwql('where doc.syntaxId=:syntaxId').bindValue('syntaxId', $syntax.toIdString()).count())
#if ($mathtool.toInteger($count) > 0)
#set ($discard = $results.put($syntax.toIdString(), $count))
#end
#end
## Use the chart macro to display the results
{{chart type="pie" source="inline" params="range:B1-B${results.size()};series:columns;pie_label_format:{0} = {1} ({2})" title="Syntax Distribution" width="600" height="400"}}
#foreach($result in $results.keySet())
|$result|$results.get($result)
#end
{{/chart}}
{{/velocity}}
## Get all available syntaxes for writing a wiki page
#set($syntaxes = $services.rendering.availableParserSyntaxes)
## For each syntax count the number of pages written in that syntax and save the result in a map for later use in the chart macro.
#set ($results = {})
#foreach($syntax in $syntaxes)
#set ($count = $services.query.xwql('where doc.syntaxId=:syntaxId').bindValue('syntaxId', $syntax.toIdString()).count())
#if ($mathtool.toInteger($count) > 0)
#set ($discard = $results.put($syntax.toIdString(), $count))
#end
#end
## Use the chart macro to display the results
{{chart type="pie" source="inline" params="range:B1-B${results.size()};series:columns;pie_label_format:{0} = {1} ({2})" title="Syntax Distribution" width="600" height="400"}}
#foreach($result in $results.keySet())
|$result|$results.get($result)
#end
{{/chart}}
{{/velocity}}
Result:
Here's a version for XWiki >= 6.1 that displays the syntax distribution for all wiki in the current XWiki instance (
):{{velocity}}
#macro (graphSyntaxes $wiki)
## Get all available syntaxes for writing a wiki page
#set($syntaxes = $services.rendering.availableParserSyntaxes)
## For each syntax count the number of pages written in that syntax and save the result in a map for later use in the chart macro.
#set ($results = {})
#foreach($syntax in $syntaxes)
#set ($count = $services.query.xwql('where doc.syntaxId=:syntaxId').bindValue('syntaxId', $syntax.toIdString()).setWiki($wiki).count())
#if ($mathtool.toInteger($count) > 0)
#set ($discard = $results.put($syntax.toIdString(), $count))
#end
#end
## Use the chart macro to display the results
{{chart type="pie" source="inline" params="range:B1-B${results.size()};series:columns;pie_label_format:{0} = {1} ({2})" title="Syntax Distribution" width="600" height="400"}}
#foreach($result in $results.keySet())
|$result|$results.get($result)
#end
{{/chart}}
#end
#foreach ($wikiId in $services.wiki.getAllIds())
* $wikiId(((
#graphSyntaxes($wikiId)
)))
#end
{{/velocity}}
#macro (graphSyntaxes $wiki)
## Get all available syntaxes for writing a wiki page
#set($syntaxes = $services.rendering.availableParserSyntaxes)
## For each syntax count the number of pages written in that syntax and save the result in a map for later use in the chart macro.
#set ($results = {})
#foreach($syntax in $syntaxes)
#set ($count = $services.query.xwql('where doc.syntaxId=:syntaxId').bindValue('syntaxId', $syntax.toIdString()).setWiki($wiki).count())
#if ($mathtool.toInteger($count) > 0)
#set ($discard = $results.put($syntax.toIdString(), $count))
#end
#end
## Use the chart macro to display the results
{{chart type="pie" source="inline" params="range:B1-B${results.size()};series:columns;pie_label_format:{0} = {1} ({2})" title="Syntax Distribution" width="600" height="400"}}
#foreach($result in $results.keySet())
|$result|$results.get($result)
#end
{{/chart}}
#end
#foreach ($wikiId in $services.wiki.getAllIds())
* $wikiId(((
#graphSyntaxes($wikiId)
)))
#end
{{/velocity}}
For XE versions >= 2.3M1:
{{velocity}}
#set($syntaxes = $services.rendering.availableParserSyntaxes)
{{chart type="pie" source="inline" params="range:B1-B${syntaxes.size()};series:columns;" title="Syntax Distribution"}}
#foreach($syntax in $syntaxes)
|$syntax.toIdString()|$xwiki.countDocuments("where doc.syntaxId='$syntax.toIdString()'")
#end
{{/chart}}
{{/velocity}}
#set($syntaxes = $services.rendering.availableParserSyntaxes)
{{chart type="pie" source="inline" params="range:B1-B${syntaxes.size()};series:columns;" title="Syntax Distribution"}}
#foreach($syntax in $syntaxes)
|$syntax.toIdString()|$xwiki.countDocuments("where doc.syntaxId='$syntax.toIdString()'")
#end
{{/chart}}
{{/velocity}}
For XE version < 2.3M1:
{{velocity}}
#set($syntaxes = $syntaxFactory.getAvailableSyntaxes())
{{chart type="pie" source="inline" params="range:B1-B${syntaxes.size()};series:columns;" title="Syntax Distribution"}}
#foreach($syntax in $syntaxes)
|$syntax.toIdString()|$xwiki.countDocuments("where doc.syntaxId='$syntax.toIdString()'")
#end
{{/chart}}
{{/velocity}}
#set($syntaxes = $syntaxFactory.getAvailableSyntaxes())
{{chart type="pie" source="inline" params="range:B1-B${syntaxes.size()};series:columns;" title="Syntax Distribution"}}
#foreach($syntax in $syntaxes)
|$syntax.toIdString()|$xwiki.countDocuments("where doc.syntaxId='$syntax.toIdString()'")
#end
{{/chart}}
{{/velocity}}
Lists all pages in XWiki Syntax 1.0
{{velocity}}
#foreach($item in $xwiki.searchDocuments("where doc.syntaxId='xwiki/1.0'"))
* $item
#end
{{/velocity}}
#foreach($item in $xwiki.searchDocuments("where doc.syntaxId='xwiki/1.0'"))
* $item
#end
{{/velocity}}
Code in XWiki Syntax 1.0
For XE versions >= 2.3M1:
#set($syntaxes = $services.rendering.availableParserSyntaxes)
<div class="hidden">
{table}
Syntax|Number of pages
#foreach($syntax in $syntaxes)
$syntax.toIdString()|$xwiki.countDocuments("where doc.syntaxId='$syntax.toIdString()'")
#end
{table}
</div>
{chart:source=type:table;|type=pie|renderer=pie|title=Syntax Distribution}
<div class="hidden">
{table}
Syntax|Number of pages
#foreach($syntax in $syntaxes)
$syntax.toIdString()|$xwiki.countDocuments("where doc.syntaxId='$syntax.toIdString()'")
#end
{table}
</div>
{chart:source=type:table;|type=pie|renderer=pie|title=Syntax Distribution}
Result:
For XE version < 2.3M1:
#set($syntaxes = $syntaxFactory.getAvailableSyntaxes())
<div class="hidden">
{table}
Syntax|Number of pages
#foreach($syntax in $syntaxes)
$syntax.toIdString()|$xwiki.countDocuments("where doc.syntaxId='$syntax.toIdString()'")
#end
{table}
</div>
{chart:source=type:table;|type=pie|renderer=pie|title=Syntax Distribution}
<div class="hidden">
{table}
Syntax|Number of pages
#foreach($syntax in $syntaxes)
$syntax.toIdString()|$xwiki.countDocuments("where doc.syntaxId='$syntax.toIdString()'")
#end
{table}
</div>
{chart:source=type:table;|type=pie|renderer=pie|title=Syntax Distribution}