Debian Codegraph @

test_non_regression/fail/na/script/extend-namespace-01-f.svg

raw
1 <svg version="1.1" baseProfile="full" onload="onLoad(evt)" id="svg-root"
2 width="100%" height="100%" viewBox="0 0 480 360"
3 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
4 <!--======================================================================-->
5 <!--= SVG 1.1 2nd Edition Test Case =-->
6 <!--======================================================================-->
7 <!--= Copyright 2009 World Wide Web Consortium, (Massachusetts =-->
8 <!--= Institute of Technology, European Research Consortium for =-->
9 <!--= Informatics and Mathematics (ERCIM), Keio University). =-->
10 <!--= All Rights Reserved. =-->
11 <!--= See http://www.w3.org/Consortium/Legal/. =-->
12 <!--======================================================================-->
13 <d:SVGTestCase xmlns:d="http://www.w3.org/2000/02/svg/testsuite/description/"
14 template-version="1.4" reviewer="SVGWG" author="Jon Ferraiolo" status="accepted"
15 version="$Revision: 1.8 $" testname="$RCSfile: extend-namespace-01-f.svg,v $">
16 <d:testDescription xmlns="http://www.w3.org/1999/xhtml" href="http://www.w3.org/TR/SVG11/extend.html#ForeignNamespaces">
17 <p>
18 Test mixing a business data namespace with elements in SVG namespace.
19 </p>
20 <p>
21 The test case uses a different namespace to hold fake sales data.
22 Using ECMAScript to make calls to the DOM, the test case extracts
23 the sales data and then makes calls to the SVG DOM to build up
24 a 'path' element and a 'text' element for each individual pie slice.
25 </p>
26 </d:testDescription>
27 <d:operatorScript xmlns="http://www.w3.org/1999/xhtml">
28 <p>
29 Run the test. No interaction required.
30 </p>
31 </d:operatorScript>
32 <d:passCriteria xmlns="http://www.w3.org/1999/xhtml">
33 <p>
34 The result should show five pie slices.
35 The first pie slice should be exploded, with a pink fill and a blue border.
36 The other pie slices should have various levels of gray fill and black borders.
37 The name of each region should appear in black towards the center of
38 the pie slice.
39 </p>
40 </d:passCriteria>
41 </d:SVGTestCase>
42 <title id="test-title">$RCSfile: extend-namespace-01-f.svg,v $</title>
43 <defs>
44 <font-face font-family="SVGFreeSansASCII" unicode-range="U+0-7F">
45 <font-face-src>
46 <font-face-uri xlink:href="../resources/SVGFreeSans.svg#ascii"/>
47 </font-face-src>
48 </font-face>
49 </defs>
50 <g id="test-body-content" font-family="SVGFreeSansASCII,sans-serif" font-size="18">
51 <g xmlns:bd="http://example.org/ExampleBusinessData" xmlns="http://www.w3.org/2000/svg">
52 <defs>
53 <script type="text/ecmascript">
54 var svg_ns = "http://www.w3.org/2000/svg";
55 var bd_ns = "http://example.org/ExampleBusinessData";
56 function onLoad(evt){
57 // Get Document
58 var svgElement = evt.target;
59 var doc = svgElement.ownerDocument;
60
61 var resultsElement = doc.getElementById('results');
62 var gElement = doc.getElementById('PieParent');
63
64 // Count the number of regions.
65 RegionNodeList = doc.getElementsByTagNameNS(bd_ns, "Region");
66 regionCount = RegionNodeList.length;
67
68 // Get the region data.
69 RegionNameNodeList = doc.getElementsByTagNameNS(bd_ns, "RegionName");
70 RegionResultNodeList = doc.getElementsByTagNameNS(bd_ns, "RegionResult");
71
72 // Get the sum of the values of the regions.
73 var total = 0;
74 for (regionIndex = 0; regionIndex &lt; regionCount; regionIndex++)
75 total = total + Number(RegionResultNodeList.item(regionIndex).firstChild.nodeValue);
76
77 // Build a pie chart.
78 var startAngle = 0;
79 for (regionIndex = 0; regionIndex &lt; regionCount; regionIndex++) {
80 regionName = RegionNameNodeList.item(regionIndex).firstChild.nodeValue;
81 regionResult = Number(RegionResultNodeList.item(regionIndex).firstChild.nodeValue);
82
83 // Build the pie slice.
84 textElement = doc.createElementNS(svg_ns, "text");
85 textNode = doc.createTextNode(regionName);
86 textElement.appendChild(textNode);
87 pathElement = doc.createElementNS(svg_ns, "path");
88
89 endAngle = startAngle - regionResult * Math.PI * 2 / total;
90 dAttribute = "M240,170 L";
91 gray = Math.round(Number(255 * (regionIndex+2)) / (regionCount+2));
92 midAngle = (startAngle + endAngle) / 2;
93 textElement.setAttributeNS(null, "x", Math.round(240+65*Math.cos(midAngle)));
94 textElement.setAttributeNS(null, "y", Math.round(170+65*Math.sin(midAngle)));
95
96 dAttribute = dAttribute + Math.round(240+100*Math.cos(startAngle));
97 dAttribute = dAttribute + ',';
98 dAttribute = dAttribute + Math.round(170+100*Math.sin(startAngle));
99 dAttribute = dAttribute + ' A100,100 0 0,0 ';
100 dAttribute = dAttribute + Math.round(240+100*Math.cos(endAngle));
101 dAttribute = dAttribute + ',';
102 dAttribute = dAttribute + Math.round(170+100*Math.sin(endAngle));
103 dAttribute = dAttribute + 'z';
104 pathElement.setAttributeNS(null, "d", dAttribute);
105 pathElement.setAttributeNS(null, "fill", "rgb("+gray+","+gray+","+gray+")");
106 pathElement.setAttributeNS(null, "stroke", "black");
107 pathElement.setAttributeNS(null, "stroke-width", "2");
108
109 // Temporary, for CSS styling.
110 pathElement.setAttributeNS(null, "fill", "rgb("+gray+","+gray+","+gray+")");
111 pathElement.setAttributeNS(null, "stroke", "black");
112 pathElement.setAttributeNS(null, "stroke-width", "2");
113
114 if (regionIndex == 0) {
115 var firstSliceOffset = 30;
116 var transformValue = "translate(" +
117 Math.round(firstSliceOffset * Math.cos(midAngle)) +
118 "," +
119 Math.round(firstSliceOffset * Math.sin(midAngle)) +
120 ")";
121 pathElement.setAttributeNS(null, "transform", transformValue);
122 textElement.setAttributeNS(null, "transform", transformValue);
123 pathElement.setAttributeNS(null, "fill", "#FF6666");
124 pathElement.setAttributeNS(null, "stroke", "#0000FF");
125 pathElement.setAttributeNS(null, "stroke-width", "3");
126
127 // Temporary, for CSS styling.
128 pathElement.setAttributeNS(null, "fill", "#FF8888");
129 pathElement.setAttributeNS(null, "stroke", "#0000FF");
130 pathElement.setAttributeNS(null, "stroke-width", "3");
131
132 }
133 gElement.appendChild(pathElement);
134 gElement.appendChild(textElement);
135 startAngle = endAngle;
136 }
137 }
138 </script>
139 </defs>
140 <bd:Results id="results">
141 <bd:Region>
142 <bd:RegionName>East</bd:RegionName>
143 <bd:RegionResult>3</bd:RegionResult>
144 </bd:Region>
145 <bd:Region>
146 <bd:RegionName>North</bd:RegionName>
147 <bd:RegionResult>4</bd:RegionResult>
148 </bd:Region>
149 <bd:Region>
150 <bd:RegionName>West</bd:RegionName>
151 <bd:RegionResult>5</bd:RegionResult>
152 </bd:Region>
153 <bd:Region>
154 <bd:RegionName>Central</bd:RegionName>
155 <bd:RegionResult>3.2</bd:RegionResult>
156 </bd:Region>
157 <bd:Region>
158 <bd:RegionName>South</bd:RegionName>
159 <bd:RegionResult>6</bd:RegionResult>
160 </bd:Region>
161 </bd:Results>
162 <text font-family="Arial" font-size="16" text-anchor="middle" x="240" y="30">
163 Pie chart built from data in a different namespace.
164 </text>
165 </g>
166 <g id="PieParent" font-family="Arial" text-anchor="middle" font-size="14">
167 <desc>Pie chart is built within this 'g' element</desc>
168 </g>
169 </g>
170 <g font-family="SVGFreeSansASCII,sans-serif" font-size="32">
171 <text id="revision" x="10" y="340" stroke="none" fill="black">$Revision: 1.8 $</text>
172 </g>
173 <rect id="test-frame" x="1" y="1" width="478" height="358" fill="none" stroke="#000000"/>
174 <!-- comment out this watermark once the test is approved -->
175 <!--<g id="draft-watermark">
176 <rect x="1" y="1" width="478" height="20" fill="red" stroke="black" stroke-width="1"/>
177 <text font-family="SVGFreeSansASCII,sans-serif" font-weight="bold" font-size="20" x="240"
178 text-anchor="middle" y="18" stroke-width="0.5" stroke="black" fill="white">DRAFT</text>
179 </g>-->
180 </svg>