Setting properties of SubGraph has no effect


#1

Hi,

I would like to group some nodes of my graph by the help of a JGoSubGraph. Grouping works fine but setting some properties of the JGoSubGraph like e.g. BackgroundColor or BorderPen has no effect.
// create seperate network for SubGraph
JGoNetwork oJGoSubGraphNetwork = new JGoNetwork();
// create SubGraph and set properties
JGoSubGraph oJGoSubGraph = new JGoSubGraph();
oJGoSubGraph.setBackgroundColor(Color.green);
oJGoSubGraph.setBorderPen(new JGoPen(JGoPen.SOLID, 2, Color.black));
oJGoSubGraph.setDraggable(false);
// add a label
JGoText oJGoText = new JGoText();
oJGoText.setText("Reports");
oJGoText.setBold(true);
oJGoText.setMultiline(false);
oJGoText.setFontSize(12);
oJGoSubGraphNetwork.addNode(oJGoText);
oJGoSubGraph.addObjectAtTail(oJGoText);
// add some other nodes to SubGraph and network
...
// add SubGraph to the document's network and document oJGoNetwork.addNode(oJGoSubGraph);
oJGoDocument.add(oJGoSubGraph);
performLayout(oJGoSubGraphNetwork, 10);
The problem might be that I generate a svg document at the end and transfer it to a C# client to be displayed:
DefaultDocument svgDomDoc = new DefaultDocument();
svgDomDoc.setGenerateJGoXML(false);
svgDomDoc.setGenerateSVG(true);
svgDomDoc.setSVGTooltips(false);
// create SVG
ByteArrayOutputStream oSVGBuffer = new ByteArrayOutputStream();
svgDomDoc.SVGWriteDoc(oSVGBuffer, oJGoDocument);
When I open the generated svg document by firefox the SubGraph has no border and no background color either. So how can I add information about the SubGraph to the svg document?
Thanks in advance!

#2

Yes, the problem is in the SVG generation. As it says in the JGo User Guide, the JGo SVG package doesn’t always produce a fully accurate rendition of the JGoDocument. In this case, the svg group element doesn’t allow you specify a background color. You can specify a fill style, but this style changes the color of all the objects within the group rather than applying the color to the background.

You may be able to accomplish what you want by generating an additional rect element for the background of the JGoSubGroup. You could do this by adding code similar to the following to the JGoSubGraph SVGWriteObject method (or your your override of that method):
if (svgDoc.SVGOutputEnabled()) {
DomElement element = (DomElement)svgDoc.createElement("rect");
element.setAttribute("x", Integer.toString(this.getTopLeft().x));
element.setAttribute("y", Integer.toString(this.getTopLeft().y));
element.setAttribute("width", Integer.toString(this.getWidth()));
element.setAttribute("height", Integer.toString(this.getHeight()));
Color color = getBackgroundColor();
int nRed = color.getRed();
int nGreen = color.getGreen();
int nBlue = color.getBlue();
String sFill = "fill:rgb(" + Integer.toString(nRed) +
"," + Integer.toString(nGreen) +
"," + Integer.toString(nBlue) +
");";
element.setAttribute("style", sFill);
jGoElementGroup.appendChild(element);
}

#3

It works properly. Thank you!