chart_pieDisplays a pie chart representing the distribution of syntaxes for pages on the current wiki
Developed by

Jerome, Vincent Massol

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1

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}}

Result:

syntaxDistribution61.png

Here's a version for XWiki >= 6.1 that displays the syntax distribution for all wiki in the current XWiki instance (Can take time to execute if you have lots of subwikis):

{{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}}

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}}

Lists all pages in XWiki Syntax 1.0

{{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}

Result:

syntaxDistribution.png

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}

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Created by Jerome on 2009/04/18 14:01
     

Get Connected