barchart.xsl 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  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:svg="http://www.w3.org/2000/svg"
  19. xmlns:system_cache__dita="http://biuro.biall-net.pl/xmlschema_procesy5/default_db_xml_cache/dita.xsd"
  20. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  21. <xsl:import href="common.xsl" />
  22. <xsl:import href="../../default_db_xml_cache.public/default_db/dateTime.xsl"/>
  23. <!-- Constants -->
  24. <xsl:variable name="MIN_VERTICAL_SPAN" select="75" />
  25. <xsl:template name="p5gnuplot:SvgCharts4Xsl" >
  26. <!--<xsl:param name="xData" />-->
  27. <xsl:param name="xData.name" />
  28. <xsl:param name="xData.postition"/>
  29. <xsl:param name="yData" />
  30. <xsl:param name="y2Data" />
  31. <xsl:param name="yData.attr" />
  32. <xsl:param name="yData.attr.title"/>
  33. <xsl:param name="y2Data.attr" />
  34. <xsl:param name="y2Data.attr.title"/>
  35. <xsl:param name="width" select="'50%'" />
  36. <xsl:param name="height" select="'50%'" />
  37. <xsl:param name="viewBoxWidth" select="300" />
  38. <xsl:param name="viewBoxHeight" select="300" />
  39. <xsl:param name="barWidth" select="30" />
  40. <xsl:param name="leftPadding" select="50" />
  41. <xsl:param name="rightPadding" select="10" />
  42. <xsl:param name="topPadding" select="25" />
  43. <xsl:param name="verticalSpan" select="100" />
  44. <!--<xsl:variable name="xCount" select="count($xData)" />-->
  45. <xsl:variable name="xData.name.Count" select="count($xData.name)" />
  46. <xsl:variable name="xData.postition.Count" select="count($xData.postition)" />
  47. <xsl:variable name="yCount" >
  48. <xsl:choose>
  49. <xsl:when test="$yData">
  50. <xsl:value-of select="count($yData)"/>
  51. </xsl:when>
  52. <xsl:otherwise>
  53. <xsl:value-of select="count($yData.attr)"/>
  54. </xsl:otherwise>
  55. </xsl:choose>
  56. </xsl:variable>
  57. <xsl:variable name="y2Count" >
  58. <xsl:choose>
  59. <xsl:when test="$y2Data">
  60. <xsl:value-of select="count($y2Data)"/>
  61. </xsl:when>
  62. <xsl:otherwise>
  63. <xsl:value-of select="count($y2Data.attr)"/>
  64. </xsl:otherwise>
  65. </xsl:choose>
  66. </xsl:variable>
  67. <xsl:variable name="yAllCount" select="(($yCount+$y2Count) div 2)" />
  68. <xsl:variable name="Data.analyzed" >
  69. <Data.analyzed>
  70. <xsl:for-each select="$xData.name">
  71. <xData.name pos="{position()}">
  72. <xsl:value-of select="text()"/>
  73. </xData.name>
  74. </xsl:for-each>
  75. <xsl:for-each select="$xData.postition">
  76. <xData.postition pos="{position()}">
  77. <xsl:choose>
  78. <xsl:when test="min($xData.postition) = number(.)">
  79. <xsl:attribute name="min" select="number(.)"/>
  80. <xsl:attribute name="minX" select="number(.)"/>
  81. </xsl:when>
  82. </xsl:choose>
  83. <xsl:choose>
  84. <xsl:when test="max($xData.postition) = number(.)">
  85. <xsl:attribute name="min" select="number(.)"/>
  86. <xsl:attribute name="maxX" select="number(.)"/>
  87. </xsl:when>
  88. </xsl:choose>
  89. <xsl:value-of select="."/>
  90. </xData.postition>
  91. </xsl:for-each>
  92. <xsl:choose>
  93. <xsl:when test="$yData">
  94. <xsl:for-each select="$yData">
  95. <yData.postition pos="{position()}">
  96. <xsl:choose>
  97. <xsl:when test="min($yData/number(.)) = number(.)">
  98. <xsl:attribute name="min" select="number(.)"/>
  99. <xsl:choose>
  100. <xsl:when test="number(.) &lt;=min($y2Data/number(.))">
  101. <xsl:attribute name="minY" select="number(.)"/>
  102. </xsl:when>
  103. </xsl:choose>
  104. </xsl:when>
  105. </xsl:choose>
  106. <xsl:choose>
  107. <xsl:when test="max($yData/number(text())) = number(.)">
  108. <xsl:attribute name="max" select="number(.)"/>
  109. <xsl:choose>
  110. <xsl:when test="number(current()) &gt;= max($y2Data/number(text()))">
  111. <xsl:attribute name="maxY" select="number(.)"/>
  112. </xsl:when>
  113. </xsl:choose>
  114. </xsl:when>
  115. </xsl:choose>
  116. <xsl:value-of select="."/>
  117. </yData.postition>
  118. </xsl:for-each>
  119. </xsl:when>
  120. <xsl:when test="$yData.attr">
  121. <xsl:for-each select="$yData.attr">
  122. <yData.postition pos="{position()}" >
  123. <xsl:attribute name="leadingTimeDate.int" select="replace(.,'-','')"/>
  124. <xsl:attribute name="system_cache__dita:year-timestamp-day" select="system_cache__dita:year-timestamp-day(.)"/>
  125. <xsl:attribute name="system_cache__dita:year-quarter" select="system_cache__dita:year-quarter(.)"/>
  126. <xsl:if test="$yData.attr.title[ position()=current()/position()]">
  127. <xsl:attribute name="yData.attr.title" select="$yData.attr.title[position()=current()/position()]/text()"/>
  128. <xsl:attribute name="yData.attr.title_ALL">
  129. <xsl:copy-of select="$yData.attr.title"></xsl:copy-of>
  130. </xsl:attribute>
  131. </xsl:if>
  132. <xsl:choose>
  133. <xsl:when test="min($yData.attr/number(replace(.,'-',''))) = number(replace(.,'-',''))">
  134. <xsl:attribute name="min" select="number(replace(.,'-',''))"/>
  135. <xsl:choose>
  136. <xsl:when test="number(replace(.,'-','')) &lt;= min($y2Data.attr/number(replace(.,'-','')))">
  137. <xsl:attribute name="minY" select="number(replace(.,'-',''))"/>
  138. </xsl:when>
  139. </xsl:choose>
  140. </xsl:when>
  141. </xsl:choose>
  142. <xsl:choose>
  143. <xsl:when test="max($yData.attr/number(replace(.,'-',''))) = number(replace(.,'-',''))">
  144. <xsl:attribute name="max" select="number(replace(.,'-',''))"/>
  145. <xsl:choose>
  146. <xsl:when test="number(replace(.,'-','')) &gt;= max($y2Data.attr/number(replace(.,'-','')))">
  147. <xsl:attribute name="maxY" select="number(replace(.,'-',''))"/>
  148. </xsl:when>
  149. </xsl:choose>
  150. </xsl:when>
  151. </xsl:choose>
  152. <xsl:value-of select="replace(.,'-','')"/>
  153. </yData.postition>
  154. </xsl:for-each>
  155. </xsl:when>
  156. </xsl:choose>
  157. <xsl:choose>
  158. <xsl:when test="$y2Data">
  159. <xsl:for-each select="$y2Data">
  160. <y2Data.postition pos="{position()}">
  161. <xsl:choose>
  162. <xsl:when test="min($y2Data/number(text())) = number(.)">
  163. <xsl:attribute name="min" select="number(.)"/>
  164. <xsl:choose>
  165. <xsl:when test="number(current()) &lt;=min($yData/number(text()))">
  166. <xsl:attribute name="minY" select="number(.)"/>
  167. </xsl:when>
  168. </xsl:choose>
  169. </xsl:when>
  170. </xsl:choose>
  171. <xsl:choose>
  172. <xsl:when test="max($y2Data/number(text())) = number(.)">
  173. <xsl:attribute name="max" select="number(.)"/>
  174. <xsl:choose>
  175. <xsl:when test="number(current()) &gt;=max($yData/number(text()))">
  176. <xsl:attribute name="maxY" select="number(.)"/>
  177. </xsl:when>
  178. </xsl:choose>
  179. </xsl:when>
  180. </xsl:choose>
  181. <xsl:value-of select="."/>
  182. </y2Data.postition>
  183. </xsl:for-each>
  184. </xsl:when>
  185. <xsl:when test="$y2Data.attr">
  186. <xsl:for-each select="$y2Data.attr">
  187. <y2Data.postition pos="{position()}" deb_max="{number(replace(.,'-',''))}" deb_max2="{max($yData.attr/number(replace(.,'-','')))}">
  188. <xsl:attribute name="leadingTimeDate.int" select="replace(.,'-','')"/>
  189. <xsl:attribute name="system_cache__dita:year-timestamp-day" select="system_cache__dita:year-timestamp-day(.)"/>
  190. <xsl:if test="$y2Data.attr.title[ position()=current()/position()]">
  191. <xsl:attribute name="y2Data.attr.title" select="$y2Data.attr.title[ position()=current()/position()]"/>
  192. </xsl:if>
  193. <xsl:choose>
  194. <xsl:when test="min($y2Data.attr/number(replace(.,'-',''))) = number(replace(.,'-',''))">
  195. <xsl:attribute name="min" select="number(replace(.,'-',''))"/>
  196. <xsl:choose>
  197. <xsl:when test="number(.) &lt;=min($yData.attr/number(.))">
  198. <xsl:attribute name="minY" select="number(replace(.,'-',''))"/>
  199. </xsl:when>
  200. </xsl:choose>
  201. </xsl:when>
  202. </xsl:choose>
  203. <xsl:choose>
  204. <xsl:when test="max($y2Data.attr/number(replace(.,'-',''))) = number(replace(.,'-',''))">
  205. <xsl:attribute name="max" select="number(replace(.,'-',''))"/>
  206. <xsl:choose>
  207. <xsl:when test="number(replace(.,'-','')) &gt;= max($yData.attr/number(replace(.,'-','')))">
  208. <xsl:attribute name="maxY" select="number(replace(.,'-',''))"/>
  209. </xsl:when>
  210. </xsl:choose>
  211. </xsl:when>
  212. </xsl:choose>
  213. <xsl:value-of select="replace(.,'-','')"/>
  214. </y2Data.postition>
  215. </xsl:for-each>
  216. </xsl:when>
  217. </xsl:choose>
  218. </Data.analyzed>
  219. </xsl:variable>
  220. <xsl:copy-of select="$Data.analyzed"></xsl:copy-of>
  221. <!--<xsl:comment>199
  222. $xData.postition = <xsl:value-of select="$xData.postition"/>
  223. <xsl:for-each select="$Data.analyzed/descendant-or-self::*">
  224. name()=<xsl:value-of select="name()"/>
  225. <xsl:for-each select="@*">
  226. @<xsl:value-of select="name()"/>=<xsl:value-of select="."/><xsl:text> , </xsl:text>
  227. </xsl:for-each>
  228. </xsl:for-each>
  229. </xsl:comment>-->
  230. <xsl:variable name="_verticalSpan">
  231. <xsl:choose>
  232. <xsl:when test="$verticalSpan &lt; $MIN_VERTICAL_SPAN">
  233. <xsl:value-of select="$MIN_VERTICAL_SPAN" />
  234. </xsl:when>
  235. <xsl:otherwise>
  236. <xsl:value-of select="$verticalSpan" />
  237. </xsl:otherwise>
  238. </xsl:choose>
  239. </xsl:variable>
  240. <svg:svg version="1.1" width="{$width}" height="{$height}" preserveAspectRatio="xMinYMin" viewBox="0 0 {$viewBoxWidth} {$viewBoxHeight}"
  241. xmlns:svg="http://www.w3.org/2000/svg">
  242. <!--<xsl:variable name="test.max">
  243. <xsl:choose>
  244. <xsl:when test="max($Data.analyzed//yData.postition/number()) &gt; 0 and
  245. max($Data.analyzed//yData.postition/number()) &gt; 0
  246. ">1</xsl:when>
  247. <xsl:otherwise>0</xsl:otherwise>
  248. </xsl:choose>
  249. </xsl:variable>-->
  250. <!--<xsl:variable name="y2DataMin">
  251. <xsl:call-template name="minimum">
  252. <xsl:with-param name="numbers" select="$y2Data" />
  253. </xsl:call-template>
  254. </xsl:variable>-->
  255. <xsl:choose>
  256. <xsl:when test="1=1"><!--$yData $xData.postition --><!-- max($Data.analyzed//yData.postition/number(@pos)) &gt; 0 and
  257. max($Data.analyzed//y2Data.postition/number(@pos)) &gt; 0
  258. -->
  259. <xsl:variable name="yDataMin" >
  260. <xsl:for-each select="$Data.analyzed//yData.postition/@min">
  261. <xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
  262. </xsl:for-each>
  263. </xsl:variable>
  264. <xsl:variable name="yAllDataMin" >
  265. <xsl:for-each select="$Data.analyzed//@minY">
  266. <xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
  267. </xsl:for-each>
  268. </xsl:variable>
  269. <xsl:variable name="y2DataMin" >
  270. <xsl:for-each select="$Data.analyzed//y2Data.postition/@min">
  271. <xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
  272. </xsl:for-each>
  273. </xsl:variable>
  274. <xsl:variable name="yDataMax" >
  275. <xsl:for-each select="$Data.analyzed//yData.postition/@max">
  276. <xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
  277. </xsl:for-each>
  278. </xsl:variable>
  279. <xsl:variable name="yAllDataMax" >
  280. <xsl:for-each select="$Data.analyzed//@maxY">
  281. <xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
  282. </xsl:for-each>
  283. </xsl:variable>
  284. <xsl:variable name="y2DataMax" >
  285. <xsl:for-each select="$Data.analyzed//y2Data.postition/@max">
  286. <xsl:if test="position()=1"><xsl:value-of select="."/></xsl:if>
  287. </xsl:for-each>
  288. </xsl:variable>
  289. <xsl:variable name="yScale" select="$_verticalSpan div ($yDataMax - $yDataMin)" />
  290. <xsl:variable name="y2Scale" select="$_verticalSpan div ($y2DataMax - $y2DataMin)" />
  291. <xsl:variable name="yAllScale" select="$_verticalSpan div ($yAllDataMax - $yAllDataMin)" />
  292. <xsl:variable name="yDelta" select="round(($yDataMax - $yDataMin) div $yCount)*2" />
  293. <xsl:variable name="y2Delta" select="round(($y2DataMax - $y2DataMin) div $y2Count)*2" />
  294. <xsl:variable name="yAllDelta" select="round(($yAllDataMax - $yAllDataMin) div $yAllCount)*2" />
  295. <xsl:variable name="xMin" select="$leftPadding" />
  296. <xsl:variable name="xMax" select="$xMin+count($yData)*$barWidth+$rightPadding" />
  297. <xsl:variable name="yMin">
  298. <xsl:choose>
  299. <xsl:when test="$yDataMin &lt; 0">
  300. <xsl:value-of select="$yDataMin - $yDelta" />
  301. </xsl:when>
  302. <xsl:otherwise>
  303. <xsl:value-of select="0" />
  304. </xsl:otherwise>
  305. </xsl:choose>
  306. </xsl:variable>
  307. <xsl:variable name="y2Min">
  308. <xsl:choose>
  309. <xsl:when test="$y2DataMin &lt; 0">
  310. <xsl:value-of select="$y2DataMin - $y2Delta" />
  311. </xsl:when>
  312. <xsl:otherwise>
  313. <xsl:value-of select="0" />
  314. </xsl:otherwise>
  315. </xsl:choose>
  316. </xsl:variable>
  317. <xsl:variable name="yAllMin">
  318. <xsl:choose>
  319. <xsl:when test="$yAllDataMin &lt; 0">
  320. <xsl:value-of select="$yAllDataMin - $yAllDelta" />
  321. </xsl:when>
  322. <xsl:otherwise>
  323. <xsl:value-of select="0" />
  324. </xsl:otherwise>
  325. </xsl:choose>
  326. </xsl:variable>
  327. <xsl:variable name="yMax" select="$yDataMax+$yDelta" />
  328. <xsl:variable name="y2Max" select="$y2DataMax+$y2Delta" />
  329. <xsl:variable name="yAllMax" select="$yAllDataMax+$yAllDelta" />
  330. <xsl:variable name="bottom">
  331. <xsl:choose>
  332. <xsl:when test="$yDataMin &lt; 0">
  333. <xsl:value-of select="- $_verticalSpan" />
  334. </xsl:when>
  335. <xsl:otherwise>
  336. <xsl:value-of select="0" />
  337. </xsl:otherwise>
  338. </xsl:choose>
  339. </xsl:variable>
  340. <xsl:variable name="bottom2">
  341. <xsl:choose>
  342. <xsl:when test="$y2DataMin &lt; 0">
  343. <xsl:value-of select="- $_verticalSpan" />
  344. </xsl:when>
  345. <xsl:otherwise>
  346. <xsl:value-of select="0" />
  347. </xsl:otherwise>
  348. </xsl:choose>
  349. </xsl:variable>
  350. <xsl:variable name="bottomAll">
  351. <xsl:choose>
  352. <xsl:when test="$yAllDataMin &lt; 0">
  353. <xsl:value-of select="- $_verticalSpan" />
  354. </xsl:when>
  355. <xsl:otherwise>
  356. <xsl:value-of select="0" />
  357. </xsl:otherwise>
  358. </xsl:choose>
  359. </xsl:variable>
  360. <xsl:variable name="yStep" select="$yDelta*$yScale" />
  361. <xsl:variable name="y2Step" select="$y2Delta*$y2Scale" />
  362. <xsl:variable name="yAllStep" select="$yAllDelta*$yAllScale" />
  363. <xsl:variable name="totalHeight" select="floor($_verticalSpan+$bottom+2*$yStep)" />
  364. <xsl:variable name="totalHeight2" select="floor($_verticalSpan+$bottom2+2*$y2Step)" />
  365. <xsl:variable name="totalHeightAll" select="floor($_verticalSpan+$bottomAll+2*$yAllStep)" />
  366. <xsl:variable name="yStart">
  367. <xsl:choose>
  368. <xsl:when test="$yDataMin &lt; 0">
  369. <xsl:value-of select="$bottom - $yStep" />
  370. </xsl:when>
  371. <xsl:otherwise>
  372. <xsl:value-of select="$bottom" />
  373. </xsl:otherwise>
  374. </xsl:choose>
  375. </xsl:variable>
  376. <xsl:variable name="y2Start">
  377. <xsl:choose>
  378. <xsl:when test="$y2DataMin &lt; 0">
  379. <xsl:value-of select="$bottom2 - $y2Step" />
  380. </xsl:when>
  381. <xsl:otherwise>
  382. <xsl:value-of select="$bottom2" />
  383. </xsl:otherwise>
  384. </xsl:choose>
  385. </xsl:variable>
  386. <xsl:variable name="yAllStart">
  387. <xsl:choose>
  388. <xsl:when test="$yAllDataMin &lt; 0">
  389. <xsl:value-of select="$bottomAll - $yAllStep" />
  390. </xsl:when>
  391. <xsl:otherwise>
  392. <xsl:value-of select="$bottomAll" />
  393. </xsl:otherwise>
  394. </xsl:choose>
  395. </xsl:variable>
  396. <xsl:variable name="yCentre">
  397. <xsl:choose>
  398. <xsl:when test="$yMin &lt; 0">
  399. <xsl:value-of select="floor($yScale*($yMax + $yDelta div 2))" />
  400. </xsl:when>
  401. <xsl:otherwise>
  402. <xsl:value-of select="floor($yScale*$yMax)" />
  403. </xsl:otherwise>
  404. </xsl:choose>
  405. </xsl:variable>
  406. <xsl:variable name="y2Centre">
  407. <xsl:choose>
  408. <xsl:when test="$y2Min &lt; 0">
  409. <xsl:value-of select="floor($y2Scale*($y2Max + $y2Delta div 2))" />
  410. </xsl:when>
  411. <xsl:otherwise>
  412. <xsl:value-of select="floor($y2Scale*$y2Max)" />
  413. </xsl:otherwise>
  414. </xsl:choose>
  415. </xsl:variable>
  416. <xsl:variable name="yAllCentre">
  417. <xsl:choose>
  418. <xsl:when test="$yAllMin &lt; 0">
  419. <xsl:value-of select="floor($yAllScale*($yAllMax + $yAllDelta div 2))" />
  420. </xsl:when>
  421. <xsl:otherwise>
  422. <xsl:value-of select="floor($yAllScale*$yAllMax)" />
  423. </xsl:otherwise>
  424. </xsl:choose>
  425. </xsl:variable>
  426. <!-- Print centre -->
  427. <svg:circle cx="{$xMin}" cy="{$totalHeightAll}" r="1" /><!-- $yCentre $yAllCentre -->
  428. <xsl:variable name="labelDelta" select="number($FONT_SIZE) div 2" />
  429. <!-- Print y-axis -->
  430. <xsl:comment>130 printYAxis
  431. yDataMin = <xsl:value-of select="$yDataMin"/> - <xsl:value-of select="$yDataMin"/>
  432. yDataMax = <xsl:value-of select="$yDataMax"/>
  433. y2DataMax = <xsl:value-of select="$y2DataMax"/>
  434. $xMin = <xsl:value-of select="$xMin"/>
  435. $yDataMax = <xsl:value-of select="$yDataMax"/>
  436. $y2DataMax = <xsl:value-of select="$y2DataMax"/>
  437. $yAllDataMax = <xsl:value-of select="$yAllDataMax"/>
  438. $_verticalSpan = <xsl:value-of select="$_verticalSpan"/>
  439. $topPadding = <xsl:value-of select="$topPadding"/>
  440. yDelta = <xsl:value-of select="$yDelta"/>
  441. y2Delta = <xsl:value-of select="$y2Delta"/>
  442. yAllDelta = <xsl:value-of select="$yAllDelta"/> = roundO($yAllDataMax - $yAllDataMin) div $yAllCount)*2
  443. $yDataMin = <xsl:value-of select="$yDataMin"/>
  444. $y2DataMin = <xsl:value-of select="$y2DataMin"/>
  445. $yAllDataMin = <xsl:value-of select="$yAllDataMin"/>
  446. $xData.name = <xsl:value-of select="$xData.name"/>
  447. $yScale = <xsl:value-of select="$yScale"/>
  448. $y2Scale = <xsl:value-of select="$y2Scale"/>
  449. $yAllScale = <xsl:value-of select="$yAllScale"/> = $_verticalSpan=<xsl:value-of select="$_verticalSpan"/> div ( $yAllDataMax=<xsl:value-of select="$yAllDataMax"/> - $yAllDataMin=<xsl:value-of select="$yAllDataMin"/> )
  450. $labelDelta = <xsl:value-of select="$labelDelta"/>
  451. $yMin = <xsl:value-of select="$yMin"/>
  452. $y2Min = <xsl:value-of select="$y2Min"/>
  453. $yAllMin = <xsl:value-of select="$yAllMin"/>
  454. $xMax = <xsl:value-of select="$xMax"/>
  455. $yMax = <xsl:value-of select="$yMax"/>
  456. $y2Max = <xsl:value-of select="$y2Max"/>
  457. $yAllMax = <xsl:value-of select="$yAllMax"/>
  458. $leftPadding = <xsl:value-of select="$leftPadding"/>
  459. $bottom = <xsl:value-of select="$bottom"/>
  460. $bottom2 = <xsl:value-of select="$bottom2"/>
  461. $bottomAll = <xsl:value-of select="$bottomAll"/>
  462. $yStep = <xsl:value-of select="$yStep"/>
  463. $y2Step = <xsl:value-of select="$y2Step"/>
  464. $yAllStep = <xsl:value-of select="$yAllStep"/>
  465. $totalHeight = <xsl:value-of select="$totalHeight"/>
  466. $totalHeight2 = <xsl:value-of select="$totalHeight2"/>
  467. $totalHeightAll = <xsl:value-of select="$totalHeightAll"/>
  468. $yStart = <xsl:value-of select="$yStart"/>
  469. $y2Start = <xsl:value-of select="$y2Start"/>
  470. $yAllStart = <xsl:value-of select="$yAllStart"/>
  471. $yCentre = <xsl:value-of select="$yCentre"/>
  472. $y2Centre = <xsl:value-of select="$y2Centre"/>
  473. $yAllCentre = <xsl:value-of select="$yAllCentre"/>
  474. $yCount = <xsl:value-of select="$yCount"/>
  475. $y2Count = <xsl:value-of select="$y2Count"/>
  476. $yAllCount = <xsl:value-of select="$yAllCount"/>
  477. </xsl:comment>
  478. <!--<xsl:variable name="step" select="$yDelta"/>-->
  479. <!--<xsl:for-each select="$Data.analyzed//xData.name">
  480. <xsl:variable name="index" select="number(@pos)+$step"/>
  481. <xsl:variable name="y">
  482. <xsl:choose>
  483. <xsl:when test="$yMin &lt; 0">
  484. <xsl:value-of select="floor($yScale*($yMax - $index + $step div 2))" />
  485. </xsl:when>
  486. <xsl:otherwise>
  487. <xsl:value-of select="floor($yScale*($yMax - $index))" />
  488. </xsl:otherwise>
  489. </xsl:choose>
  490. </xsl:variable>
  491. <!-\-<svg:text x="{($xMin - 5)}"
  492. y="{($y + number($labelDelta))}"
  493. text-anchor="end"
  494. fill="black"
  495. font-family="{$FONT}"
  496. font-weight="bold"
  497. font-size="{$FONT_SIZE}"
  498. xmlns:svg="http://www.w3.org/2000/svg">
  499. <xsl:value-of select="text()" /><!-\\- testf="{floor($yScale*($yMax - $index))}"
  500. testf2="{($yMax - $index)}"
  501. testf3="{$yMax}"
  502. index="{$index}" -\\->
  503. </svg:text>-\->
  504. </xsl:for-each>-->
  505. <xsl:call-template name="p5gnuplot:printYAxis">
  506. <xsl:with-param name="totalHeightAll" select="$totalHeightAll"/>
  507. <xsl:with-param name="yDelta" select="$yDelta"/>
  508. <xsl:with-param name="y2Delta" select="$y2Delta"/>
  509. <xsl:with-param name="yAllDelta" select="$yAllDelta"/>
  510. <xsl:with-param name="index" select="$yMin" />
  511. <xsl:with-param name="index2" select="$y2Min" />
  512. <xsl:with-param name="step" select="$yDelta" />
  513. <xsl:with-param name="step2" select="$y2Delta" />
  514. <xsl:with-param name="stepAll" select="$yAllDelta" />
  515. <xsl:with-param name="viewBoxHeight" select="$viewBoxHeight"/>
  516. <xsl:with-param name="xMin" select="$xMin" />
  517. <xsl:with-param name="xMax" select="$xMax" />
  518. <xsl:with-param name="yMin" select="$yMin" />
  519. <xsl:with-param name="y2Min" select="$y2Min" />
  520. <xsl:with-param name="yAllMin" select="$yAllMin" />
  521. <xsl:with-param name="yAllDataMin" select="$yAllDataMin"/>
  522. <xsl:with-param name="yMax" select="$yMax" />
  523. <xsl:with-param name="y2Max" select="$y2Max" />
  524. <xsl:with-param name="yAllMax" select="$yAllMax" />
  525. <xsl:with-param name="yAllDataMax" select="$yAllDataMax"/>
  526. <xsl:with-param name="yScale" select="$yScale" />
  527. <xsl:with-param name="y2Scale" select="$y2Scale" />
  528. <xsl:with-param name="yAllScale" select="$yAllScale" />
  529. <xsl:with-param name="Data.analyzed" select="$Data.analyzed" tunnel="yes"/>
  530. </xsl:call-template>
  531. <xsl:comment>#253 after text</xsl:comment>
  532. <svg:g transform="translate(0 {$totalHeight}) scale(1 -1)">
  533. <svg:line x1="{$xMin}" y1="{$yStart}" x2="{$xMin}" y2="{$totalHeight}"
  534. deb="569_os_pion_1"
  535. stroke="black" stroke-width="2" />
  536. </svg:g>
  537. <!--<xsl:call-template name="printYAxis">
  538. <xsl:with-param name="index" select="$yMin" />
  539. <xsl:with-param name="step" select="$yDelta" />
  540. <xsl:with-param name="xMin" select="$xMin" />
  541. <xsl:with-param name="xMax" select="$xMax" />
  542. <xsl:with-param name="yMin" select="$yMin" />
  543. <xsl:with-param name="yMax" select="$yMax" />
  544. <xsl:with-param name="yScale" select="$yScale" />
  545. </xsl:call-template>-->
  546. <!--<svg:g transform="translate(0 {$totalHeight}) scale(1 -1)">
  547. <svg:line x1="{$xMin}" y1="{$yStart}" x2="{$xMin}" y2="{$totalHeight}"
  548. stroke="black" stroke-width="2" />
  549. </svg:g>-->
  550. <xsl:comment>#301 after text</xsl:comment>
  551. <!-- Print bars -->
  552. <svg:g transform="translate(0 {$totalHeightAll}) scale(1 -1)"><!-- $yCentre -->
  553. <xsl:for-each select="$Data.analyzed//xData.name">
  554. <xsl:variable name="colour">
  555. <xsl:call-template name="colour">
  556. <xsl:with-param name="index" select="number(@pos)" /><!-- position() -->
  557. </xsl:call-template>
  558. </xsl:variable>
  559. <!--<xsl:variable name="height" select="$Data.analyzed//yData.postition[@pos=current()/@pos]/number()*$yScale" />-->
  560. <!-- x0 , y250
  561. x50, y0
  562. -->
  563. <xsl:variable name="index.context.value.y" select="$Data.analyzed//yData.postition[@pos=current()/@pos]/number()"/>
  564. <xsl:variable name="index.context.value.y2" select="$Data.analyzed//y2Data.postition[@pos=current()/@pos]/number()"/>
  565. <xsl:variable name="y" select="$viewBoxHeight - (( $viewBoxHeight div $yAllDataMax ) * $index.context.value.y)"/><!-- $totalHeightAll - (( $totalHeightAll div ($yAllDataMax - $yAllDataMin) ) * $index.context.value.y) -->
  566. <xsl:variable name="y2" select="(( $totalHeightAll div ($yAllDataMax - $yAllDataMin) ) * ($index.context.value.y - $index.context.value.y2 ))"/>
  567. <!--<xsl:variable name="height2" select="$y2Scale * $index.context.value.y2" />--><!--$Data.analyzed//y2Data.postition[@pos=current()/@pos]/number()*$yAllScale $y2Scale -->
  568. <xsl:variable name="y">
  569. <xsl:call-template name="absolute">
  570. <xsl:with-param name="number" select="$y" /><!-- - number($topPadding) -->
  571. </xsl:call-template>
  572. </xsl:variable>
  573. <xsl:variable name="y2.as.height" select="((( $totalHeightAll div $yAllDataMax ) * (($index.context.value.y - $index.context.value.y2) )) ) " />
  574. <xsl:variable name="y2.as.height">
  575. <xsl:call-template name="absolute">
  576. <xsl:with-param name="number" select="floor($y2.as.height) " /><!-- - number($topPadding) -->
  577. </xsl:call-template>
  578. </xsl:variable>
  579. <!--<xsl:variable name="absoluteHeight2">
  580. <xsl:call-template name="absolute">
  581. <xsl:with-param name="number" select="floor($height2)" />
  582. </xsl:call-template>
  583. </xsl:variable>-->
  584. <!--<xsl:variable name="y">
  585. <xsl:choose>
  586. <xsl:when test="$Data.analyzed//yData.postition[@pos=current()/@pos]/number()">
  587. <xsl:value-of select="$Data.analyzed//yData.postition[@pos=current()/@pos]/number()*$yAllScale"/><!-\- $yScale -\->
  588. </xsl:when>
  589. <!-\-<xsl:when test="$height &gt;= 0">
  590. <xsl:value-of select="0" />
  591. </xsl:when>-\->
  592. <!-\-<xsl:otherwise>
  593. <xsl:value-of select="$height" />
  594. </xsl:otherwise>-\->
  595. <xsl:otherwise>
  596. <xsl:message terminate="yes">330 error</xsl:message>
  597. </xsl:otherwise>
  598. </xsl:choose>
  599. </xsl:variable>-->
  600. <svg:rect x="{$xMin+(position() - 1)*$barWidth}" y="{abs($y - $topPadding)}" rx="2" ry="2"
  601. width="{$barWidth}" height="{abs($y2.as.height - 5)}" deb="#620 grafy $y2Scale={$y2Scale} all {$yAllScale} pos{position()} valy={$index.context.value.y} valy2={$index.context.value.y2} y2.as.height={$y2.as.height} $totalHeight={$totalHeight} $yAllCentre={$yAllCentre} $yAllDataMax{$yAllDataMax} $topPadding={$topPadding}"
  602. fill="{$colour}" stroke="black" stroke-width="1" />
  603. </xsl:for-each>
  604. </svg:g>
  605. <xsl:comment>#334 after bars</xsl:comment>
  606. <!-- Print x-axis -->
  607. <svg:g transform="translate(0 {$totalHeightAll})"><!-- $yAllCentre $yCentre -->
  608. <!--<xsl:call-template name="p5gnuplot:printXAxis">
  609. <xsl:with-param name="xData" select="$Data.analyzed//xData.postition" /><!-\- $xData.postition -\->
  610. <xsl:with-param name="step" select="$barWidth" />
  611. <xsl:with-param name="xMin" select="$xMin+$barWidth div 2" />
  612. <xsl:with-param name="xMax" select="$yCount" />
  613. <xsl:with-param name="Data.analyzed" select="$Data.analyzed" tunnel="yes"/><!-\- $Data.analyzed -\->
  614. </xsl:call-template>-->
  615. <xsl:call-template name="p5gnuplot:printXAxis">
  616. <xsl:with-param name="xData" select="$Data.analyzed//xData.postition" /><!-- $xData.postition -->
  617. <xsl:with-param name="step" select="$barWidth" />
  618. <xsl:with-param name="xMin" select="$xMin+$barWidth div 2" />
  619. <xsl:with-param name="xMax" select="$yCount" />
  620. <xsl:with-param name="Data.analyzed" select="$Data.analyzed" tunnel="yes"/><!-- $Data.analyzed -->
  621. </xsl:call-template>
  622. <xsl:comment>#352 after </xsl:comment>
  623. <svg:line x1="{$xMin}" y1="0" x2="{$xMax}" y2="0" stroke="black" stroke-width="2" deb="#647"/>
  624. </svg:g>
  625. <xsl:comment>#355 test
  626. <xsl:for-each select="$Data.analyzed//xData.postition">
  627. pos=<xsl:value-of select="position()"/>
  628. </xsl:for-each>
  629. </xsl:comment>
  630. </xsl:when>
  631. <xsl:otherwise>
  632. <xsl:comment>#466 error max($Data.analyzed//yData.postition/number()) &gt; 0 and
  633. max($Data.analyzed//y2Data.postition/number()) &gt; 0
  634. </xsl:comment>
  635. </xsl:otherwise>
  636. </xsl:choose>
  637. </svg:svg>
  638. </xsl:template>
  639. <!-- Prints a simple bar chart with grid -->
  640. <!--<xsl:template name="barChart">
  641. <xsl:param name="xData" />
  642. <xsl:param name="yData" />
  643. <xsl:param name="width" select="'100%'" />
  644. <xsl:param name="height" select="'100%'" />
  645. <xsl:param name="viewBoxWidth" select="300" />
  646. <xsl:param name="viewBoxHeight" select="300" />
  647. <xsl:param name="barWidth" select="15" />
  648. <xsl:param name="leftPadding" select="20" />
  649. <xsl:param name="rightPadding" select="10" />
  650. <xsl:param name="verticalSpan" select="100" />
  651. <xsl:variable name="xCount" select="count($xData)" />
  652. <xsl:variable name="yCount" select="count($yData)" />
  653. <xsl:variable name="_verticalSpan">
  654. <xsl:choose>
  655. <xsl:when test="$verticalSpan &lt; $MIN_VERTICAL_SPAN">
  656. <xsl:value-of select="$MIN_VERTICAL_SPAN" />
  657. </xsl:when>
  658. <xsl:otherwise>
  659. <xsl:value-of select="$verticalSpan" />
  660. </xsl:otherwise>
  661. </xsl:choose>
  662. </xsl:variable>
  663. <svg:svg version="1.1" width="{$width}" height="{$height}" preserveAspectRatio="xMinYMin" viewBox="0 0 {$viewBoxWidth} {$viewBoxHeight}"
  664. xmlns:svg="http://www.w3.org/2000/svg">
  665. <xsl:if test="$xCount &gt; 0 and $yCount &gt; 0">
  666. <xsl:variable name="yDataMin">
  667. <xsl:call-template name="minimum">
  668. <xsl:with-param name="numbers" select="$yData" />
  669. </xsl:call-template>
  670. </xsl:variable>
  671. <xsl:variable name="yDataMax">
  672. <xsl:call-template name="maximum">
  673. <xsl:with-param name="numbers" select="$yData" />
  674. </xsl:call-template>
  675. </xsl:variable>
  676. <xsl:variable name="yScale" select="$_verticalSpan div ($yDataMax - $yDataMin)" />
  677. <xsl:variable name="yDelta" select="round(($yDataMax - $yDataMin) div $yCount)*2" />
  678. <xsl:variable name="xMin" select="$leftPadding" />
  679. <xsl:variable name="xMax" select="$xMin+count($yData)*$barWidth+$rightPadding" />
  680. <xsl:variable name="yMin">
  681. <xsl:choose>
  682. <xsl:when test="$yDataMin &lt; 0">
  683. <xsl:value-of select="$yDataMin - $yDelta" />
  684. </xsl:when>
  685. <xsl:otherwise>
  686. <xsl:value-of select="0" />
  687. </xsl:otherwise>
  688. </xsl:choose>
  689. </xsl:variable>
  690. <xsl:variable name="yMax" select="$yDataMax+$yDelta" />
  691. <xsl:variable name="bottom">
  692. <xsl:choose>
  693. <xsl:when test="$yDataMin &lt; 0">
  694. <xsl:value-of select="- $_verticalSpan" />
  695. </xsl:when>
  696. <xsl:otherwise>
  697. <xsl:value-of select="0" />
  698. </xsl:otherwise>
  699. </xsl:choose>
  700. </xsl:variable>
  701. <xsl:variable name="yStep" select="$yDelta*$yScale" />
  702. <xsl:variable name="totalHeight" select="floor($_verticalSpan+$bottom+2*$yStep)" />
  703. <xsl:variable name="yStart">
  704. <xsl:choose>
  705. <xsl:when test="$yDataMin &lt; 0">
  706. <xsl:value-of select="$bottom - $yStep" />
  707. </xsl:when>
  708. <xsl:otherwise>
  709. <xsl:value-of select="$bottom" />
  710. </xsl:otherwise>
  711. </xsl:choose>
  712. </xsl:variable>
  713. <xsl:variable name="yCentre">
  714. <xsl:choose>
  715. <xsl:when test="$yMin &lt; 0">
  716. <xsl:value-of select="floor($yScale*($yMax + $yDelta div 2))" />
  717. </xsl:when>
  718. <xsl:otherwise>
  719. <xsl:value-of select="floor($yScale*$yMax)" />
  720. </xsl:otherwise>
  721. </xsl:choose>
  722. </xsl:variable>
  723. <!-\- Print centre -\->
  724. <!-\-<svg:circle cx="{$xMin}" cy="{$yCentre}" r="1" />-\->
  725. <!-\- Print y-axis -\->
  726. <!-\-<xsl:call-template name="printYAxis">
  727. <xsl:with-param name="index" select="$yMin" />
  728. <xsl:with-param name="step" select="$yDelta" />
  729. <xsl:with-param name="xMin" select="$xMin" />
  730. <xsl:with-param name="xMax" select="$xMax" />
  731. <xsl:with-param name="yMin" select="$yMin" />
  732. <xsl:with-param name="yMax" select="$yMax" />
  733. <xsl:with-param name="yScale" select="$yScale" />
  734. </xsl:call-template>-\->
  735. <!-\-<svg:g transform="translate(0 {$totalHeight}) scale(1 -1)">
  736. <svg:line x1="{$xMin}" y1="{$yStart}" x2="{$xMin}" y2="{$totalHeight}"
  737. stroke="black" stroke-width="2" />
  738. </svg:g>-\->
  739. <!-\- Print bars -\->
  740. <!-\-<svg:g transform="translate(0 {$yCentre}) scale(1 -1)">
  741. <xsl:for-each select="$yData">
  742. <xsl:variable name="colour">
  743. <xsl:call-template name="colour">
  744. <xsl:with-param name="index" select="position()" />
  745. </xsl:call-template>
  746. </xsl:variable>
  747. <xsl:variable name="height" select=".*$yScale" />
  748. <xsl:variable name="absoluteHeight">
  749. <xsl:call-template name="absolute">
  750. <xsl:with-param name="number" select="floor($height)" />
  751. </xsl:call-template>
  752. </xsl:variable>
  753. <xsl:variable name="y">
  754. <xsl:choose>
  755. <xsl:when test="$height &gt;= 0">
  756. <xsl:value-of select="0" />
  757. </xsl:when>
  758. <xsl:otherwise>
  759. <xsl:value-of select="$height" />
  760. </xsl:otherwise>
  761. </xsl:choose>
  762. </xsl:variable>
  763. <svg:rect x="{$xMin+(position() - 1)*$barWidth}" y="{$y}" rx="2" ry="2"
  764. width="{$barWidth}" height="{$absoluteHeight}"
  765. fill="{$colour}" stroke="black" stroke-width="1" />
  766. </xsl:for-each>
  767. </svg:g>-\->
  768. <!-\- Print x-axis -\->
  769. <!-\-<svg:g transform="translate(0 {$yCentre})">
  770. <xsl:call-template name="printXAxis">
  771. <xsl:with-param name="xData" select="$xData" />
  772. <xsl:with-param name="step" select="$barWidth" />
  773. <xsl:with-param name="xMin" select="$xMin+$barWidth div 2" />
  774. <xsl:with-param name="xMax" select="$yCount" />
  775. </xsl:call-template>
  776. <svg:line x1="{$xMin}" y1="0" x2="{$xMax}" y2="0" stroke="black" stroke-width="2" />
  777. </svg:g>-\->
  778. </xsl:if>
  779. </svg:svg>
  780. </xsl:template>-->
  781. </xsl:stylesheet>