SVG with grouped links and nodes


I already hava a solution to generate a SVG.
But now I need a solution to group the SVG elements which represents a
node or link (using the SVG element ). This groups should also
have a id, for example the name of the node or link.

How can I realize this functionality?

Thanks for help.

Here is my code to generate the SVG:

//create workflow
JGoDocument oJGoDocument = …;

// convert JGoDocument to svg string
SVGGoView svgView = new SVGGoView();

//create SVG
ByteArrayOutputStream oSVGBuffer = new ByteArrayOutputStream();

//get the SVG as String
String svg = oSVGBuffer.toString();

To add a group element with additional attributes around any node or link class, just create a subclass of that node or link and override SVGWriteObject as follows:

public void SVGWriteObject(DomDoc svgDoc, DomElement jGoElementGroup)
DomElement sampleGroup = svgDoc.createElement("g");
sampleGroup.setAttribute("id", this.getLabel().getText());
super.SVGWriteObject(svgDoc, sampleGroup);

Thanks for the hint.

It works with the normal SVG creation over the DefaultDocument, but not with the SVGGoView.
The SVGWriteObject method would not be called.

Is there a possibility reach the goal with the SVGGoView?

No, SVGGoView doesn’t give you that kind of control over the SVG generation.

But if you use DefaultDocument and call setGenerateJGoXML(false) you'll end up just generating SVG elements without all the additional JGo stuff and you'll have much more control over the SVG generation.

Ok, I’ll use the DefaultDocument.

I had another problem with the group element of Links.

When I use JGoLabeledLinks with a MidLabel of type JGoLinkLabel, I can only catch the svg elements of the link, but not the elements of the label.

Is there a chance to combine the link and the corresponding labe with one group element?

No, the element is grouping all the children of the JGoLabeledLink. But the MidLabel of a JGoLabeledLink isn’t a child of the JGoLabeledLink. Instead it’s a totally separate JGoObject that gets repositioned as the JGoLabeledlink changes position.