Loading ...
Sorry, an error occurred while loading the content.

Re: please help with the GRAPH generation in apache batik

Expand Messages
  • Frank Bruder
    ... In your sample code I do not see where you get the input data. Without knowing which variables hold the data and in what format I can only guess how this
    Message 1 of 2 , Apr 23 5:29 PM
      --- In svg-developers@yahoogroups.com, "Nitya" <nityavyas@...> wrote:
      > Hi all,
      > I am trying to create an SVG file that will have a graph that i can display. i am using the DOM implementation as shown below to generate the elements of the graph. Then i want to join them with the edges... but the problem is that as u can see in the below code i have to give x, y coordinates in the program and that is very very difficult when i want to join two elements with an EDGE.

      In your sample code I do not see where you get the input data. Without knowing which variables hold the data and in what format I can only guess how this is supposed to work, but I try to comment.

      > String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
      > DOMImplementation impl = new SVGDOMImplementation();
      > Document doc = impl.createDocument(svgNS, "svg", null);
      > Element svgRoot = doc.getDocumentElement(); etc....
      > Element ellipse = doc.createElementNS(svgNS, "circle");
      > ellipse.setAttributeNS(null, "cx", String.valueOf(xPoint));
      > ellipse.setAttributeNS(null, "cy", String.valueOf(yPoint));

      String.valueOf() returns the value of the String constructor. What you want is probably

      > ellipse.setAttributeNS(null, "r", "25");
      > ellipse.setAttributeNS(null, "fill", "red");
      > ellipse.setAttributeNS(null, "stroke-width", "2");

      I suppose

      will be called somewhere.

      > Element edge = doc.createElementNS(svgNS, "g");
      > edge.setAttributeNS(null, "class", "edge");
      > Element title = doc.createElementNS(svgNS, "title");
      > title.setTextContent(node1Index + "&" + node2Index);

      The escape sequence "&" is used to represent data as text in xml files. When you interact with the DOM representation you don't use escape sequences (except for what the programming language requires to be escaped). You just write "&" here, or else it would result in the literal text "&".

      > Element path = doc.createElementNS(svgNS, "path");
      > path.setAttributeNS(null, "style", "fill:none;stroke:black;");
      > path.setAttributeNS(null, "d", "M"+edgeX1+" "+edgeY1+"L"+edgeX2+" "+edgeY2);
      > as u can see in the code of path, i have to get x1,y1 and x2,y2 ... which does not work.. is there a workaround for this???

      Now I don't understand where your data is. For the ellipse you had variables xPoint and yPoint, and now you have edgeX1, edgeY1, edgeX2, edgeY2. I suppose you want to draw circle markers at specific points and draw edges connecting the same points, but in your sample code there are only DOM manipulations but none of your data structures or control structures. I don't see what you're trying there.

      If you want to connect a sequence of points, you could do it like this:

      var polyline = doc.createElementNS( svgNS, 'polyline' );
      function addPoint (x, y) {
      var point = svgRoot.createSVGPoint();
      point.x = x;
      point.y = y;
      return polyline;

      Then call addPoint(x,y) once for each point, style the polyline (set fill to "none", set stroke and stroke-width) and append it to the root element or to a group in the root element.

      > I saw these classes in batik javadoc... SVGEllipse, SVGPath .. can they be used so i dnt have to give coordinates myself???

      Well, read the corresponding javadoc files. These are extensions of the abstract class SVGGraphicObjectConverter. They convert java.awt.Shape objects to SVG elements. So if you know how to build your graph with the Shape drawing classes of the package java.awt, then you could probably convert it to SVG with the help of these converter classes.

      > Actually i am runnig out of time for this one and so javadoc doesnt give me idea.. can u pls give some input with example code so that i can achieve this??
      > i ll really appreciate ur help...
      > thanks in advance..
      > nitya
    Your message has been successfully submitted and would be delivered to recipients shortly.