Hi all,

I'm having a particular problem with a jgraph serialization. The problem
involves the sizes attributes of the SVG element not being set correctly.
The following code produces a nice SVG image, but is cropped by firefox due
to the missing attributes:

    public Document serialize(JGraph graph){
        Object[] cells = graph.getDescendants(graph.getRoots());
        Rectangle2D bounds = graph.getCellBounds(cells);
        graph.toScreen(bounds);

        graph.setGridVisible(false);
        graph.setDoubleBuffered(false);
        graph.clearSelection();

        // Get a DOMImplementation
        DOMImplementation domImpl =
            GenericDOMImplementation.getDOMImplementation();
        // Create an instance of org.w3c.dom.Document
        Document document = domImpl.createDocument (null, "svg", null);
        // Create an instance of the SVG Generator
        SVGGraphics2D g2 = new SVGGraphics2D(document);
        // Render into the SVG Graphics2D implementation
        String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
        // get the root element (the svg element)
        Element svgRoot = g2.getRoot();

        graph.paint(g2);

        g2.getRoot(document.getDocumentElement());
        return document;
    }
It all works, but for the attributes (and some minor fiddling with namespace
declarations being at the second level instead of the root element, but
that's another story).
Any idea on how to add the height and width elements?

Regards,
Chris
--
Christian Decker
Software Architect
http://blog.snyke.net

Reply via email to