common.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Original Author: Frankline Francis
  4. Copyright (c) 2012, Imaginea. All rights reserved.
  5. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND DEVELOPERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  6. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  7. IN NO EVENT SHALL THE COPYRIGHT OWNER OR DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  8. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  9. OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  10. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  11. Redistribution and use, with or without modification, are permitted provided that the following conditions are met:
  12. # Redistribution of source code must retain the above copyright notice, this list of conditions and the disclaimer.
  13. # Neither the name of Imaginea nor the names of the developers may be used to endorse or promote products derived from
  14. this software without specific prior written permission.
  15. -->
  16. <xsl:stylesheet version="2.0"
  17. xmlns:p5gnuplot="http://biuro.biall-net.pl/WPS_Functions/graph_gnuplot"
  18. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  19. <!-- Constants -->
  20. <xsl:variable name="COLOURS" select="document('colours.xml')/colours/colour" />
  21. <xsl:variable name="FONT" select="'Arial'" />
  22. <xsl:variable name="FONT_SIZE" select="5" />
  23. <!-- Helper template to return the maximum of given items -->
  24. <xsl:template name="maximum">
  25. <xsl:param name="numbers" />
  26. <xsl:for-each select="$numbers">
  27. <xsl:sort select="." data-type="number" order="descending" />
  28. <xsl:if test="position()=1">
  29. <xsl:value-of select="." />
  30. </xsl:if>
  31. </xsl:for-each>
  32. </xsl:template>
  33. <!-- Helper template to return the minimum of given items -->
  34. <xsl:template name="minimum">
  35. <xsl:param name="numbers" />
  36. <xsl:for-each select="$numbers">
  37. <xsl:sort select="." data-type="number" order="ascending" />
  38. <xsl:if test="position()=1">
  39. <xsl:value-of select="." />
  40. </xsl:if>
  41. </xsl:for-each>
  42. </xsl:template>
  43. <!-- Helper template to return the absolute value -->
  44. <xsl:template name="absolute">
  45. <xsl:param name="number" />
  46. <xsl:choose>
  47. <xsl:when test="$number &gt;= 0">
  48. <xsl:value-of select="$number" />
  49. </xsl:when>
  50. <xsl:otherwise>
  51. <xsl:value-of select="- $number" />
  52. </xsl:otherwise>
  53. </xsl:choose>
  54. </xsl:template>
  55. <!-- Returns a named colour for the given index -->
  56. <xsl:template name="colour">
  57. <xsl:param name="index" />
  58. <xsl:value-of select="$COLOURS[@index=($index mod count($COLOURS))]" />
  59. </xsl:template>
  60. <!-- Helper template to print x-axis -->
  61. <xsl:template name="p5gnuplot:printXAxis">
  62. <xsl:param name="xData" />
  63. <xsl:param name="step" />
  64. <xsl:param name="xMin" />
  65. <xsl:param name="xMax" />
  66. <xsl:param name="Data.analyzed" required="yes" tunnel="yes"/>
  67. <xsl:for-each select="$Data.analyzed//xData.postition"><!-- $xData -->
  68. <xsl:choose>
  69. <xsl:when test="position() &lt;= $xMax">
  70. <svg:text writing-mode="tb" x="{$xMin+(position() - 1)*$step}"
  71. deb="#73 osie nazwy "
  72. dy="5" fill="black" font-family="{$FONT}" font-weight="bold"
  73. font-size="{$FONT_SIZE}" xmlns:svg="http://www.w3.org/2000/svg">
  74. <!--<xsl:value-of select="." />-->
  75. <xsl:value-of select="$Data.analyzed//xData.name[@pos = current()/@pos]"/>
  76. </svg:text>
  77. </xsl:when>
  78. <xsl:otherwise>
  79. <xsl:comment>#90 error position() = <xsl:value-of select="position()"/> lt <xsl:value-of select="$xMax"/> </xsl:comment>
  80. </xsl:otherwise>
  81. </xsl:choose>
  82. </xsl:for-each>
  83. </xsl:template>
  84. <xsl:template name="printXAxis">
  85. <xsl:param name="xData" />
  86. <xsl:param name="step" />
  87. <xsl:param name="xMin" />
  88. <xsl:param name="xMax" />
  89. <xsl:for-each select="$xData">
  90. <xsl:if test="position() &lt;= $xMax">
  91. <svg:text writing-mode="tb" x="{$xMin+(position() - 1)*$step}"
  92. dy="5" fill="black" font-family="{$FONT}" font-weight="bold"
  93. font-size="{$FONT_SIZE}" xmlns:svg="http://www.w3.org/2000/svg">
  94. <xsl:value-of select="." />
  95. </svg:text>
  96. </xsl:if>
  97. </xsl:for-each>
  98. </xsl:template>
  99. <!-- Helper template to print y-axis -->
  100. <xsl:template name="printYAxis">
  101. <xsl:param name="index" />
  102. <xsl:param name="step" />
  103. <xsl:param name="xMin" />
  104. <xsl:param name="xMax" />
  105. <xsl:param name="yMin" />
  106. <xsl:param name="yMax" />
  107. <xsl:param name="yScale" />
  108. <xsl:variable name="labelDelta" select="$FONT_SIZE div 2" />
  109. <xsl:if test="$index &lt; $yMax">
  110. <xsl:variable name="y">
  111. <xsl:choose>
  112. <xsl:when test="$yMin &lt; 0">
  113. <xsl:value-of select="floor($yScale*($yMax - $index + $step div 2))" />
  114. </xsl:when>
  115. <xsl:otherwise>
  116. <xsl:value-of select="floor($yScale*($yMax - $index))" />
  117. </xsl:otherwise>
  118. </xsl:choose>
  119. </xsl:variable>
  120. <svg:text x="{($xMin - 5)}" y="{($y + $labelDelta)}"
  121. text-anchor="end" fill="black" font-family="{$FONT}" font-weight="bold"
  122. font-size="{$FONT_SIZE}" xmlns:svg="http://www.w3.org/2000/svg">
  123. <xsl:value-of select="$index" />
  124. </svg:text>
  125. <svg:line x1="{$xMin}" y1="{$y}" x2="{$xMax}" y2="{$y}"
  126. stroke="grey" stroke-width="0.25" xmlns:svg="http://www.w3.org/2000/svg" />
  127. <xsl:call-template name="printYAxis">
  128. <xsl:with-param name="index" select="$index+$step" />
  129. <xsl:with-param name="step" select="$step" />
  130. <xsl:with-param name="xMin" select="$xMin" />
  131. <xsl:with-param name="xMax" select="$xMax" />
  132. <xsl:with-param name="yMin" select="$yMin" />
  133. <xsl:with-param name="yMax" select="$yMax" />
  134. <xsl:with-param name="yScale" select="$yScale" />
  135. </xsl:call-template>
  136. </xsl:if>
  137. </xsl:template>
  138. <xsl:template name="p5gnuplot:printYAxis">
  139. <xsl:param name="index.context.position" select="1"/>
  140. <xsl:param name="index" />
  141. <xsl:param name="index2" />
  142. <xsl:param name="step" />
  143. <xsl:param name="step2" />
  144. <xsl:param name="stepAll" />
  145. <xsl:param name="yDelta"/>
  146. <xsl:param name="y2Delta"/>
  147. <xsl:param name="yAllDelta"/>
  148. <xsl:param name="yAllDataMax" />
  149. <xsl:param name="xMin" />
  150. <xsl:param name="xMax" />
  151. <xsl:param name="yMin" />
  152. <xsl:param name="y2Min" />
  153. <xsl:param name="yAllMin" />
  154. <xsl:param name="yMax" />
  155. <xsl:param name="y2Max" />
  156. <xsl:param name="yAllMax" />
  157. <xsl:param name="viewBoxHeight"/>
  158. <xsl:param name="yAllDataMin"/>
  159. <xsl:param name="yScale" />
  160. <xsl:param name="y2Scale" />
  161. <xsl:param name="yAllScale" />
  162. <xsl:param name="totalHeightAll"/>
  163. <xsl:param name="Data.analyzed" required="yes" tunnel="yes"/>
  164. <xsl:variable name="labelDelta" select="$FONT_SIZE div 2" />
  165. <xsl:variable name="index.context.value.y" select="$Data.analyzed//yData.postition[@pos=$index.context.position]/text()"/>
  166. <xsl:variable name="index.context.value.y2" select="$Data.analyzed//y2Data.postition[@pos=$index.context.position]/text()"/>
  167. <xsl:if test="$Data.analyzed//yData.postition[@pos=$index.context.position]"><!-- $index &lt; $yMax -->
  168. <!--<xsl:variable name="y" select="$totalHeightAll - ($yDelta * $index.context.value.y) "/>-->
  169. <!--<xsl:variable name="y.test" select="$viewBoxHeight - (($viewBoxHeight div ($yAllDataMax - $yAllDataMin)) * ($index.context.value.y - $yAllDataMin))"/>-->
  170. <xsl:variable name="y" select="$viewBoxHeight - (($viewBoxHeight div ($yAllDataMax - $yAllDataMin)) * ($index.context.value.y - ($yAllDataMin )))">
  171. <!--<xsl:choose>
  172. <xsl:when test="$yAllMin &lt; 0"><!-\- $yMin -\->
  173. <xsl:value-of select="floor($yAllScale*($yAllMax - $index.context.value.y + $stepAll div 2))" /><!-\-$index $step $yMax $yScale-\->
  174. </xsl:when>
  175. <xsl:otherwise>
  176. <xsl:value-of select="floor($yAllScale*($yAllMax - $index.context.value.y))" /><!-\- $index$yMax $yScale -\->
  177. </xsl:otherwise>
  178. </xsl:choose>-->
  179. </xsl:variable>
  180. <xsl:variable name="y2.test" select="$viewBoxHeight - (( $viewBoxHeight div $yAllDataMax ) * $index.context.value.y2 ) "/>
  181. <xsl:variable name="y2" select="$viewBoxHeight - (($viewBoxHeight div ($yAllDataMax - $yAllDataMin)) * ( $index.context.value.y2 - $yAllDataMin )) "><!-- $totalHeightAll - ($y2Delta * $index.context.value.y2) -->
  182. <!--<xsl:choose>
  183. <xsl:when test="$yAllMin &lt; 0"><!-\- $y2Min -\->
  184. <xsl:value-of select="floor($yAllScale*($yAllMax - $index.context.value.y2 + $stepAll div 2))" /><!-\-$index2 $y2Max $yScale -\->
  185. </xsl:when>
  186. <xsl:otherwise>
  187. <xsl:value-of select="floor($yAllScale*($yAllMax - $index.context.value.y2))" /><!-\-$index2 $y2Max $y2Scale -\->
  188. </xsl:otherwise>
  189. </xsl:choose>-->
  190. </xsl:variable>
  191. <svg:text x="{($xMin - 5)}" y="{($y + $labelDelta)}"
  192. deb="178-do-y1 val={$index.context.value.y} pos.{$index.context.position}
  193. $viewBoxHeight={$viewBoxHeight}
  194. div={(($viewBoxHeight div $yAllDataMax) * $index.context.value.y)}
  195. tuned={($viewBoxHeight div ($yAllDataMax - $yAllDataMin))}
  196. Mx-Min={($yAllDataMax - $yAllDataMin)}
  197. Vb_div(Mx-Min)={($viewBoxHeight div ($yAllDataMax - $yAllDataMin))}
  198. V-Admin={($index.context.value.y - $yAllDataMin)}
  199. V-divAdmax={($index.context.value.y div $yAllDataMax)}
  200. "
  201. text-anchor="end" fill="black" font-family="{$FONT}" font-weight="bold"
  202. font-size="{$FONT_SIZE}" xmlns:svg="http://www.w3.org/2000/svg">
  203. <xsl:choose>
  204. <xsl:when test="$Data.analyzed//yData.postition[@pos=$index.context.position]/@yData.attr.title">
  205. <xsl:value-of select="$Data.analyzed//yData.postition[@pos=$index.context.position]/@yData.attr.title" />
  206. </xsl:when>
  207. <xsl:otherwise>
  208. <xsl:value-of select="$index.context.value.y" />
  209. </xsl:otherwise>
  210. </xsl:choose>
  211. <!--<xsl:value-of select="' $y '"/>
  212. <xsl:value-of select="$y"/>-->
  213. </svg:text>
  214. <svg:text x="{($xMin - 5)}" y="{($y2 + $labelDelta)}" deb="178-do-y2 $y2.test={$y2.test} val={$index.context.value.y2} pos.{$index.context.position}"
  215. text-anchor="end" fill="black" font-family="{$FONT}" font-weight="bold"
  216. font-size="{$FONT_SIZE}" xmlns:svg="http://www.w3.org/2000/svg">
  217. <xsl:choose>
  218. <xsl:when test="$Data.analyzed//y2Data.postition[@pos=$index.context.position]/@y2Data.attr.title">
  219. <xsl:value-of select="$Data.analyzed//y2Data.postition[@pos=$index.context.position]/@y2Data.attr.title" />
  220. </xsl:when>
  221. <xsl:otherwise>
  222. <xsl:value-of select="$index.context.value.y2" />
  223. </xsl:otherwise>
  224. </xsl:choose>
  225. <!--<xsl:value-of select="' $y2 '"/>
  226. <xsl:value-of select="$y2"/>-->
  227. </svg:text>
  228. <svg:line x1="{$xMin}" y1="{$y}" x2="{$xMax}" y2="{$y}" deb="#210A-all-os-tylko poziomy tik1"
  229. stroke="grey" stroke-width="0.25" xmlns:svg="http://www.w3.org/2000/svg" />
  230. <svg:line x1="{$xMin}" y1="{$y2}" x2="{$xMax}" y2="{$y2}" deb="#210B-all-os-tylko poziomy tik2"
  231. stroke="grey" stroke-width="0.25" xmlns:svg="http://www.w3.org/2000/svg" />
  232. <xsl:call-template name="p5gnuplot:printYAxis">
  233. <xsl:with-param name="index.context.position" select="$index.context.position + 1"/>
  234. <xsl:with-param name="index" select="$index+$step" />
  235. <xsl:with-param name="index2" select="$index2+$step2"/>
  236. <xsl:with-param name="step" select="$step" />
  237. <xsl:with-param name="step2" select="$step2" />
  238. <xsl:with-param name="stepAll" select="$stepAll" />
  239. <xsl:with-param name="xMin" select="$xMin" />
  240. <xsl:with-param name="xMax" select="$xMax" />
  241. <xsl:with-param name="yMin" select="$yMin" />
  242. <xsl:with-param name="y2Min" select="$y2Min"/>
  243. <xsl:with-param name="yAllMin" select="$yAllMin"/>
  244. <xsl:with-param name="yMax" select="$yMax" />
  245. <xsl:with-param name="y2Max" select="$y2Max" />
  246. <xsl:with-param name="yAllMax" select="$yAllMax" />
  247. <xsl:with-param name="yAllDataMax" select="$yAllDataMax"/>
  248. <xsl:with-param name="viewBoxHeight" select="$viewBoxHeight"/>
  249. <xsl:with-param name="yDelta" select="$yDelta"/>
  250. <xsl:with-param name="y2Delta" select="$y2Delta"/>
  251. <xsl:with-param name="yAllDelta" select="$yAllDelta"/>
  252. <xsl:with-param name="yAllDataMin" select="$yAllDataMin"/>
  253. <xsl:with-param name="totalHeightAll" select="$totalHeightAll"/>
  254. <xsl:with-param name="yScale" select="$yScale" />
  255. <xsl:with-param name="y2Scale" select="$y2Scale" />
  256. <xsl:with-param name="yAllScale" select="$y2Scale" />
  257. <xsl:with-param name="Data.analyzed" select="$Data.analyzed" tunnel="yes"/>
  258. </xsl:call-template>
  259. </xsl:if>
  260. </xsl:template>
  261. </xsl:stylesheet>