Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/delibero.git

Updated comments, removed unused items.

Author Dave Jarvis <email>
Date 2014-07-31 22:03:46 GMT-0700
Commit 6b138cf5de60bcfd3e2e367d6304215b60d41369
Parent b3c5920
xml/chart.xsl
<xsl:variable name="base_colour" select="'46A5E5'" />
- <!-- Convert XML data into a Pie Chart. -->
+ <!-- Convert XML data into a pie chart. -->
<xsl:template match="dataset" mode="piechart">
<xsl:variable name="pie_width">100</xsl:variable>
<xsl:variable name="pie_height" select="$pie_width - $PI" />
- <!-- Number of pie pieces -->
+ <!-- Number of pie pieces. -->
<xsl:variable name="pieces" select="count(data)" />
- <!-- Calculate the total value for all pieces -->
+ <!-- Calculate the total value for all pieces (for percentages). -->
<xsl:variable name="total" select="sum(//value)" />
<div class="chart">
<svg:svg width="30%" height="30%" viewBox="0 0 {$pie_width} {$pie_height}" version="1.1">
<svg:g stroke-width="0" fill="#000" stroke="#000">
<xsl:for-each select="data">
<xsl:variable name="piece" select="position()" />
- <!-- Calculate pie piece colour -->
+ <!-- Calculate pie piece fill colour. -->
<xsl:variable name="fill">
<xsl:call-template name="fill">
<xsl:with-param name="piece" select="$piece" />
<xsl:with-param name="pieces" select="$pieces" />
<xsl:with-param name="colour" select="$base_colour" />
</xsl:call-template>
</xsl:variable>
<xsl:for-each select="value">
- <xsl:variable name="row" select="position()" />
+ <!-- Pie piece item number. -->
+ <xsl:variable name="item" select="position()" />
<xsl:variable name="title"><xsl:value-of select="../name" /></xsl:variable>
<xsl:variable name="deg">
<xsl:choose>
+ <!-- Whole pie. -->
<xsl:when test="$piece = 1">360</xsl:when>
<xsl:otherwise>
- <xsl:value-of select="360 * (1-sum(//data[position() &lt;=$piece -1]/value[position() = $row]) div $total)" />
+ <xsl:value-of select="360 * (1 - sum(//data[position() &lt;= $piece -1]/value[position() = $item]) div $total)" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
- <xsl:variable name="deg2" select="360 * (1-sum(//data[position() &lt;=$piece]/value[position() = $row]) div $total)" />
+ <xsl:variable name="deg2" select="360 * (1 - sum(//data[position() &lt;= $piece]/value[position() = $item]) div $total)" />
<xsl:variable name="c2">
<xsl:call-template name="sine">
</xsl:variable>
- <xsl:variable name="opt">
- <xsl:choose>
- <xsl:when test="$deg - $deg2 &lt; 180">0</xsl:when>
- <xsl:otherwise>1</xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
<!-- Fill the pie piece. -->
- <svg:path fill="{$fill}" title="{$percent}" stroke="white" stroke-width="0.5" d="{concat('M',$x+$rx,' ',$y+$ry,'L',$x+$rx+$rx*$c2,' ',$y+$ry+$ry*$s2,'A',$rx,' ',$ry,' 0 ',$opt,' 1 ',$x+$rx + $rx * $c,' ',$y+$ry +$ry*$s,'z')}" />
+ <svg:path fill="{$fill}" title="{$percent}" stroke="white" stroke-width="0.5" d="{concat('M',$x+$rx,' ',$y+$ry,'L',$x+$rx+$rx*$c2,' ',$y+$ry+$ry*$s2,'A',$rx,' ',$ry,' 0 ',0,' 1 ',$x+$rx + $rx * $c,' ',$y+$ry +$ry*$s,'z')}" />
</xsl:for-each>
</xsl:for-each>
<xsl:for-each select="//name">
- <!-- Select legend colour for corresponding pie piece -->
+ <!-- Select legend colour for corresponding pie piece. -->
<xsl:variable name="fill">
<xsl:call-template name="fill">
<xsl:with-param name="piece" select="position()" />
<xsl:with-param name="pieces" select="$pieces" />
<xsl:with-param name="colour" select="$base_colour" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="dy" select="position() * ($font_size + $line_space)" />
-
+ <xsl:variable name="percent" select="concat(.,' (',format-number(. div $total, '0.00%'),')')" />
+
<svg:rect x="0" y="{$dy - 2 * $line_space}" width="5" height="5" fill="{$fill}" />
- <svg:text x="10" y="{$dy}" font-size="{$font_size}"><xsl:value-of select="." /></svg:text>
+ <svg:text x="10" y="{$dy}" font-size="{$font_size}"><xsl:value-of select="$percent" /></svg:text>
</xsl:for-each>
</svg:svg>
</div>
</xsl:template>
<!-- http://en.wikipedia.org/wiki/HSL_and_HSV -->
- <xsl:template name="fill">
+ <xsl:template name="fill">
<xsl:param name="piece" />
<xsl:param name="pieces" />
- <xsl:param name="colour" select="'8A56E2'" />
+ <xsl:param name="colour" />
<xsl:variable name="r">
<xsl:with-param name="b" select="$max_gb" />
</xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="saturation">
- <xsl:if test="$value = 0">0</xsl:if>
- <xsl:if test="$value != 0"><xsl:value-of select="$chroma div $value" /></xsl:if>
</xsl:variable>
</xsl:choose>
</xsl:template>
-
</xsl:stylesheet>
Delta 16 lines added, 26 lines removed, 10-line decrease