|
Hi Nazar,
well on first look, everythings ok. I used your SVG in my
program and got all Bounding-Boxes as I'm used to.
Two things: First of all, you only operate on elements
containing an "activity-label"-attribute An second try to call your visit-function with
the root-Node of your SVGDocument.
visit((Node) doc.getRootElement(), 0);
Perhaps that helps
Florian From: Nazar Stasiv (Lohika, Inc) [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 15, 2006 2:10 PM To: [email protected] Subject: Re: SVGOMGElement and coordinates? Pepping, Florian wrote: Attached diagram.zip archive which contains svg resource well the recursion is pretty basic. Here is how I do it public static SVGDocument installScript(SVGDocument doc, Collection<String> labels) { // add to dom tree element with id=background to use it in draggable // functions Element parent = doc.createElement("g"); parent.setAttribute("id", "background"); Element svg = doc.getRootElement(); NodeList children = svg.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node n = children.item(i); svg.removeChild(n); parent.appendChild(n); } svg.appendChild(parent); // Append script element with reference to library file Element sc = doc.createElementNS(svgns, "script"); sc.setAttributeNS(svgns, "language", "text/ecmascript"); sc.setAttributeNS(xlinkns, "href", "svg-common.js"); doc.getDocumentElement().appendChild(sc); // add onload attribute to svg element NodeList list = doc.getElementsByTagNameNS(null, "svg"); Element svgNode = (Element) list.item(0); svgNode.setAttributeNS(svgns, "onload", "init(evt);"); // Append array of activities to be highlighted Element data = "" "script"); data.setAttributeNS(svgns, "language", "text/ecmascript"); StringBuilder sb = new StringBuilder(); sb.append("var labels = [ "); for (String label : labels) { sb.append("'"); sb.append(label); sb.append("',"); } sb.replace(sb.length() - 1, sb.length(), "];"); CDATASection cdata = doc.createCDATASection(sb.toString()); data.appendChild(cdata); doc.getDocumentElement().appendChild(data); // HERE I START WALKING THE DOM TREE visit(doc, 0); return doc; } public static void visit(Node node, int level) { // Process node if (node instanceof Element) { Element e = (Element) node; if (e.hasAttributeNS("http://www.example.com/bpms", "activity-label")) { // I love painting in red String style = e.getAttribute("style"); Pattern pattern = Pattern.compile("fill:([a-zA-Z])*;"); Matcher m = pattern.matcher(style); e.setAttribute("style", m.replaceAll("fill:red;")); if (e instanceof SVGLocatable) { SVGLocatable l = (SVGLocatable) node; if (svgTagSet.contains(node.getNodeName())) { SVGRect r = l.getBBox(); try { float x = r.getX(); float y = r.getY(); // setting onclick attribute is only for testing here e.setAttribute("onclick", "drawMarker(evt,'sampletext','" + x + "','" + y + "');"); } catch(Exception e ){ e.printStackTrace(); } } } } } // If there are any children, visit each one NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { // Get child node Node childNode = list.item(i); // Visit child node visit(childNode, level + 1); } }
|
- RE: SVGOMGElement and coordinates? Pepping, Florian
- Re: SVGOMGElement and coordinates? Nazar Stasiv (Lohika, Inc)
- RE: SVGOMGElement and coordinates? Pepping, Florian
- Re: SVGOMGElement and coordinates? Nazar Stasiv (Lohika, Inc)
- Re: SVGOMGElement and coordinates? thomas . deweese
- RE: SVGOMGElement and coordinates? Pepping, Florian
- Re: SVGOMGElement and coordinates? Nazar Stasiv (Lohika, Inc)
- Re: SVGOMGElement and coordinates? Nazar Stasiv (Lohika, Inc)
- Re: SVGOMGElement and coordinates? thomas . deweese
- RE: SVGOMGElement and coordinates? Pepping, Florian
- RE: SVGOMGElement and coordinates? Pepping, Florian
- Re: SVGOMGElement and coordinates? Nazar Stasiv (Lohika, Inc)
- Re: SVGOMGElement and coordinates? thomas . deweese
- Re: SVGOMGElement and coordinates? Nazar Stasiv (Lohika, Inc)
