I'm having problems with representing XML element inside a vertex. On the forum somebody said: "custom subclass of mxCell, some custom properties for the existing mxCell class, or a value as an Object or XML node with the same". But I'm not sure how to display XML node or element when a vertex is drawn. Just placing Element in insertVertex method doesn't work, so drawVertex needs to be changed. But how is the question. Or custom canvas can be used. Can anybody help me with this? Any code or examples is much appreciated. Many thanks in advance.

OK, let me say then what I need. I have a plain xml file, some dom elements are with attributes and some are not, I need to draw a graph, where inside a vertex there will be all data found in a xml element. When I use insertVertex method and as value I pass dom element, I get "Tag::null" inside the vertex. It says null, because for dom element value is null. Instead of this I would like that it said "Tag: attribute1=1 attribute2=2 ...". So the label needs to be changed, also I would like to style the label, I would like to insert a horizontal line splitting tag from attributes in a label. I hope that this makes it more clear. Please let know if I should add any additional information. Thanks again

asked 08 May '12, 09:49

vvllaaddaa's gravatar image

accept rate: 0%

edited 10 May '12, 05:32

Unclear question, please edit.

(09 May '12, 08:31) David

It sounds like all you need to do is override the mxGraph.getLabel and/or mxGraph.convertValueToString methods. Inside the override of these methods you can build your HTML from your custom user object that was set as an XML node in insertVertex. Make sure you set the mxGraph.htmlLabels property to true as well. For a good example of how to do this, as well as handling editing of custom XML node values, see the Userobject example in the JavaScript examples.


answered 11 May '12, 15:32

Dave's gravatar image

accept rate: 0%

Thanks Dave for quick response.

But I forgot to mention that I'm creating Java application with mxGraph, even though I should have started with JGraph, but mxGraph seemed to have more options.

So I'm not sure, how to use HTML with Java application. There is an example for mxGraph and convertValueToString in UserObject example. And it shows how to edit the label, but how to add some structure to the label. Something like horizontal line, and some formatting styles.

I really like that diagramly application http://www.diagram.ly/, especially the UML part, something similar to class, component or table options, is exactly what I need. Also is there a way to incorporate that popup window where you can format the vertex. It is shown on double click on vertex. Creating this for Java app would be great.

mxGraph graph = new mxGraph() {

        // Overrides method to disallow edge label editing

public boolean isCellEditable(Object cell)
            return !getModel().isEdge(cell);

// Overrides method to provide a cell label in the display
        public String convertValueToString(Object cell)
            if (cell instanceof mxCell)
                Object value = ((mxCell) cell).getValue();

if (value instanceof Element)
                    Element elt = (Element) value;

if (elt.getTagName().equalsIgnoreCase("person"))
                        String firstName = elt.getAttribute("firstName");
                        String lastName = elt.getAttribute("lastName");

if (lastName != null && lastName.length() > 0)
                            return lastName + ", " + firstName;

return firstName;
                    else if (elt.getTagName().equalsIgnoreCase("knows"))
                        return elt.getTagName() + " (Since "
                                + elt.getAttribute("since") + ")";


return super.convertValueToString(cell);

If you can share any more information, I'd really appreciate it. Thanks

(14 May '12, 07:37) vvllaaddaa

Great, it works. I didn't know if this would work in Java application, but it works.

All I needed to do, is set graph.setHtmlLabels(true) , and change convertValueToString method to handle XmlElement object.

Thanks for your help, I will let know if I encounter any more problems about this.


answered 15 May '12, 09:25

vvllaaddaa's gravatar image

accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 08 May '12, 09:49

Seen: 3,838 times

Last updated: 15 May '12, 09:25