Debian Codegraph @

contrib/charts/xsl/column.xsl

raw
1 <?xml version="1.0"?>
2
3 <!--
4
5 Licensed to the Apache Software Foundation (ASF) under one or more
6 contributor license agreements. See the NOTICE file distributed with
7 this work for additional information regarding copyright ownership.
8 The ASF licenses this file to You under the Apache License, Version 2.0
9 (the "License"); you may not use this file except in compliance with
10 the License. You may obtain a copy of the License at
11
12 http://www.apache.org/licenses/LICENSE-2.0
13
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19
20 -->
21
22 <!-- ====================================================================== -->
23 <!-- Generate a column graph (bars up the ways) -->
24 <!-- -->
25 <!-- @author [email protected] -->
26 <!-- @version $Id$ -->
27 <!-- ====================================================================== -->
28
29 <xsl:stylesheet version="1.0"
30 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
31
32 <xsl:variable name="height" select="graph/meta/column/height"/>
33 <xsl:variable name="width" select="graph/meta/column/width"/>
34
35 <xsl:variable name="margin">10</xsl:variable>
36 <xsl:variable name="labelWidthY">50</xsl:variable>
37 <xsl:variable name="labelWidthX">20</xsl:variable>
38
39 <xsl:variable name="chartHeight" select="$height - (2 * $margin) - $labelWidthX"/>
40 <xsl:variable name="chartWidth" select="$width - (2 * $margin) - $labelWidthY"/>
41
42 <xsl:variable name="barWidth" select="1 div count(//set)"/>
43
44 <xsl:variable name="verticalRangeMax">
45 <xsl:for-each select="//y">
46 <xsl:sort order="descending" data-type="number" select="text()"/>
47 <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
48 </xsl:for-each>
49 </xsl:variable>
50
51 <xsl:variable name="horizontalRangeMax">
52 <xsl:for-each select="//x">
53 <xsl:sort order="descending" data-type="number" select="text()"/>
54 <xsl:if test="position() = 1"><xsl:value-of select="text() + 1"/></xsl:if>
55 </xsl:for-each>
56 </xsl:variable>
57
58 <xsl:variable name="verticalScale">
59 <xsl:value-of select="$chartHeight div $verticalRangeMax"/>
60 </xsl:variable>
61
62 <xsl:variable name="horizontalScale">
63 <xsl:value-of select="$chartWidth div $horizontalRangeMax"/>
64 </xsl:variable>
65
66 <xsl:template match="graph">
67 <svg
68 width="{$width}"
69 height="{$height}">
70
71 <g transform="matrix(1 0 0 -1 {$margin + $labelWidthY} {$height - ($margin + $labelWidthX)})">
72 <xsl:call-template name="verticalGridlines">
73 <xsl:with-param name="value">0</xsl:with-param>
74 <xsl:with-param name="step">1</xsl:with-param>
75 </xsl:call-template>
76
77 <xsl:call-template name="horizontalGridlines">
78 <xsl:with-param name="value">0</xsl:with-param>
79 <xsl:with-param name="step">20000</xsl:with-param>
80 </xsl:call-template>
81
82 <xsl:apply-templates select="data/*"/>
83 </g>
84 </svg>
85 </xsl:template>
86
87 <xsl:template name="verticalGridlines">
88 <xsl:param name="value">0</xsl:param>
89 <xsl:param name="step"/>
90
91 <line
92 id="verticalGridline_{$value}"
93 x1="{$value * $horizontalScale}"
94 y1="-2"
95 x2="{$value * $horizontalScale}"
96 y2="{$verticalRangeMax * $verticalScale}"
97 style="fill:none;stroke:black;stroke-width:1"/>
98
99 <text
100 transform="matrix(1 0 0 -1 0 -{$labelWidthX})"
101 x="{$value * $horizontalScale}"
102 y="0"
103 style="font-size:12;fill:black">
104 <xsl:value-of select="//meta/axis/x/value[position() = $value + 1]"/>
105 </text>
106
107 <xsl:if test="$value + $step &lt;= $horizontalRangeMax">
108 <xsl:call-template name="verticalGridlines">
109 <xsl:with-param name="value"><xsl:value-of select="$value + $step"/></xsl:with-param>
110 <xsl:with-param name="step"><xsl:value-of select="$step"/></xsl:with-param>
111 </xsl:call-template>
112 </xsl:if>
113 </xsl:template>
114
115 <xsl:template name="horizontalGridlines">
116 <xsl:param name="value">0</xsl:param>
117 <xsl:param name="step"/>
118
119 <line
120 id="horizontalGridline_{$value}"
121 x1="-2"
122 y1="{$value * $verticalScale}"
123 x2="{$horizontalRangeMax * $horizontalScale}"
124 y2="{$value * $verticalScale}"
125 style="fill:none;stroke:black;stroke-width:1"/>
126
127 <text
128 transform="matrix(1 0 0 -1 -{$margin} -5)"
129 x="0"
130 y="-{$value * $verticalScale}"
131 style="text-anchor:end;font-size:12;fill:black">
132 <xsl:value-of select="$value"/>
133 </text>
134
135 <xsl:if test="$value + $step &lt;= $verticalRangeMax">
136 <xsl:call-template name="horizontalGridlines">
137 <xsl:with-param name="value"><xsl:value-of select="$value + $step"/></xsl:with-param>
138 <xsl:with-param name="step"><xsl:value-of select="$step"/></xsl:with-param>
139 </xsl:call-template>
140 </xsl:if>
141 </xsl:template>
142
143 <xsl:template match="set">
144 <xsl:variable name="red" select="colour/red/text()"/>
145 <xsl:variable name="green" select="colour/green/text()"/>
146 <xsl:variable name="blue" select="colour/blue/text()"/>
147
148 <xsl:variable name="label" select="label"/>
149 <xsl:variable name="col" select="position() - 1"/>
150
151 <xsl:for-each select="values/*">
152 <rect
153 id="{$label}-{generate-id(.)}"
154 x="{(x + ($barWidth * $col)) * $horizontalScale}"
155 y="0"
156 width="{$barWidth * $horizontalScale}"
157 height="{y * $verticalScale}"
158 rx="0"
159 ry="0"
160 style="stroke-width:1;stroke:rgb(0,0,0);fill:rgb({$red},{$green},{$blue})"/>
161 </xsl:for-each>
162
163 </xsl:template>
164
165 </xsl:stylesheet>