| <?xml version="1.0" encoding="UTF-8"?> |
| |
| <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN" "http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd" > |
| |
| <!-- |
| |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| |
| --> |
| <!-- ====================================================================== --> |
| <!-- Modification of a polyline attributes --> |
| <!-- --> |
| <!-- @author nicolas.socheleau@bitflash.com --> |
| <!-- @version $Id$ --> |
| <!-- ====================================================================== --> |
| <?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?> |
| |
| <svg width="450" viewBox="0 0 450 500" height="500" id="body"> |
| <title><polyline> attributes 'onload'</title> |
| |
| <text x="50%" y="45" class="title"><polyline> getPoints() in 'onload' |
| </text> |
| <script type="text/ecmascript"><![CDATA[ |
| function getNumberOfItems(evt) |
| { |
| var elt = evt.target; |
| nb = elt.getPoints().getNumberOfItems(); |
| var text = elt.getOwnerDocument().getElementById('test1_text'); |
| text.getFirstChild().appendData(" "+nb+" points"); |
| } |
| function insertItemBefore(evt,fromIndex,index) |
| { |
| var elt = evt.target; |
| pointProvider = elt.getOwnerDocument().getElementById('test1'); |
| point = pointProvider.getPoints().getItem(fromIndex); |
| nb = elt.getPoints().insertItemBefore(point,index); |
| var text = elt.getOwnerDocument().getElementById('test4_text'); |
| text.getFirstChild().appendData(" ("+nb.getX()+","+nb.getY()+")"); |
| } |
| function replaceItem(evt,fromIndex,index) |
| { |
| var elt = evt.target; |
| pointProvider = elt.getOwnerDocument().getElementById('test1'); |
| point = pointProvider.getPoints().getItem(fromIndex); |
| nb = elt.getPoints().replaceItem(point,index); |
| var text = elt.getOwnerDocument().getElementById('test5_text'); |
| text.getFirstChild().appendData(" ("+nb.getX()+","+nb.getY()+")"); |
| } |
| |
| function initializeAppendItem(evt,fromIndex1,fromIndex2) |
| { |
| var elt = evt.target; |
| pointProvider = elt.getOwnerDocument().getElementById('test1'); |
| point = pointProvider.getPoints().getItem(fromIndex1); |
| nb = elt.getPoints().initialize(point); |
| var text = elt.getOwnerDocument().getElementById('test71_text'); |
| text.getFirstChild().appendData(" ("+nb.getX()+","+nb.getY()+")"); |
| point = pointProvider.getPoints().getItem(fromIndex2); |
| nb = elt.getPoints().appendItem(point); |
| text = elt.getOwnerDocument().getElementById('test72_text'); |
| text.getFirstChild().appendData(" ("+nb.getX()+","+nb.getY()+")"); |
| } |
| |
| function createNextSibling(evt){ |
| |
| var elt = evt.target; |
| var doc = elt.getOwnerDocument(); |
| |
| var polyline = doc.createElementNS(elt.getNamespaceURI(),"polyline"); |
| polyline.setAttribute("style","fill:#ffd700;stroke-width:4.0;stroke:#ffa500"); |
| var pointsList = polyline.getPoints(); |
| |
| var point = doc.getDocumentElement().createSVGPoint(); |
| |
| point.setX(219); |
| point.setY(175); |
| pointsList.appendItem(point); |
| point.setX(255); |
| point.setY(193); |
| pointsList.appendItem(point); |
| point.setX(268); |
| point.setY(235); |
| pointsList.appendItem(point); |
| point.setX(242); |
| point.setY(269); |
| pointsList.appendItem(point); |
| point.setX(199); |
| point.setY(270); |
| pointsList.appendItem(point); |
| point.setX(171); |
| point.setY(237); |
| pointsList.appendItem(point); |
| point.setX(179); |
| point.setY(195); |
| pointsList.appendItem(point); |
| |
| var text = elt.getOwnerDocument().getElementById('test8_text'); |
| text.getFirstChild().appendData(" "+pointsList.getNumberOfItems()+" points"); |
| |
| elt.getParentNode().insertBefore(polyline,elt.getNextSibling()); |
| } |
| ]]></script> |
| <g id="test-content" transform="matrix(1.0 0.0 0.0 1.0 -148.27586 -91.37931)"> |
| |
| <!-- onload="getNumberOfItems(evt)" --> |
| <text x="180" y="160" font-size="11">points provider</text> |
| <polyline style="opacity:0.5;fill:#eee; stroke:#aaa; stroke-width:4" points="219 175, 255 193, 268 235, 242 269, 199 270, 171 237, 179 195"/> |
| <polyline id="test1" style="fill:gold; stroke:orange; stroke-width:4" points="219 175, 255 193, 268 235, 242 269, 199 270, 171 237, 179 195" onload="getNumberOfItems(evt)"/> |
| <text x="160" font-size="9" y="290" id="test1_text"> |
| polyline with |
| </text> |
| |
| <g transform="translate(0,150)" > |
| <!-- onload="insertItemBefore(evt)" --> |
| <text x="180" y="160" font-size="11" >insertItemBefore</text> |
| <polyline style="opacity:0.5;fill:#eee; stroke:#aaa; stroke-width:4" points="219 175, 255 193, 268 235, 242 269, 199 270, 171 237, 179 195"/> |
| <polyline id="test4" fill="#ffd700" stroke-width="4.0" |
| points="200,200 200,250 250,250 250,200" |
| stroke="#ffa500" |
| onload="insertItemBefore(evt,5,1)" /> |
| <text x="160" font-size="9" y="290" id="test4_text"> |
| inserted point |
| </text> |
| </g> |
| |
| <g transform="translate(150,150)" > |
| <!-- onload="replaceItem(evt)" --> |
| <text x="180" y="160" font-size="11" >replaceItem</text> |
| <polyline style="opacity:0.5;fill:#eee; stroke:#aaa; stroke-width:4" points="219 175, 255 193, 268 235, 242 269, 199 270, 171 237, 179 195"/> |
| <polyline id="test5" fill="#ffd700" stroke-width="4.0" |
| points="200,200 200,250 250,250 250,200" |
| stroke="#ffa500" |
| onload="replaceItem(evt,4,1)" /> |
| <text x="160" font-size="9" y="290" id="test5_text"> |
| replaced point |
| </text> |
| </g> |
| |
| <g transform="translate(300,150)" > |
| <!-- onload="initialize/appendItem(evt)" --> |
| <text x="180" y="160" font-size="11" >initialize/appendItem</text> |
| <polyline style="opacity:0.5;fill:#eee; stroke:#aaa; stroke-width:4" points="219 175, 255 193, 268 235, 242 269, 199 270, 171 237, 179 195"/> |
| <polyline id="test7" fill="#ffd700" stroke-width="4.0" |
| points="200,200 200,250 250,250 250,200" |
| stroke="#ffa500" |
| onload="initializeAppendItem(evt,1,2)" /> |
| <text x="160" font-size="9" y="275" id="test71_text"> |
| intialized point |
| </text> |
| <text x="160" font-size="9" y="285" id="test72_text"> |
| appended point |
| </text> |
| </g> |
| |
| <g transform="translate(300,0)" > |
| <!-- onload="initialize/appendItem(evt)" --> |
| <text x="180" y="160" font-size="11" >new Polyline</text> |
| <polyline style="opacity:0.5;fill:#eee; stroke:#aaa; stroke-width:4" points="219 175, 255 193, 268 235, 242 269, 199 270, 171 237, 179 195" onload="createNextSibling(evt)"/> |
| <text x="160" font-size="9" y="285" id="test8_text"> |
| polyline with |
| </text> |
| </g> |
| |
| </g> |
| </svg> |