Details
-
Improvement
-
Status: Open
-
Resolution: Unresolved
-
1.5
-
None
-
None
-
Operating System: other
Platform: Other
Description
A component we want to output as SVG (a TouchGraph graph panel) needs to have
the offset set, as well as the drawing bounds, otherwise the SVG will draw
outside the bounds of the page (and some tools clip out the graphics which are
outside the page.)
As there is a setSVGCanvasSize method but no setSVGCanvasOffset method, we had
to improvise.
getTGPanel().drawForPrint(g);
if (g instanceof SVGGraphics2D)
{ TGPoint2D topLeft = getTGPanel().getTopLeftDraw(); TGPoint2D bottomRight = getTGPanel().getBottomRightDraw(); Element svgRoot = ((SVGGraphics2D) g).getRoot(); svgRoot.setAttribute("x", Double.toString(topLeft.x)); svgRoot.setAttribute("y", Double.toString(topLeft.y)); svgRoot.setAttribute("width", Double.toString(bottomRight.x - topLeft.x)); svgRoot.setAttribute("height", Double.toString(bottomRight.y - topLeft.y)); }The problem is that after doing this, there is nothing in the SVG file at all
(not the graphics, nor even the attributes I just tried to set!) If I remove
the whole block, the drawing works but has no x, y, width and height attributes
are there.
I would expect this to set the attributes on the SVG root element. I didn't ask
it to remove the element from the tree, so it shouldn't remove the element from
the tree. And setting attributes on an XML element should result in the
attributes being set.