This may be a left field situation, but I'm trying to convert a Vertex dropped on a graph to end up as an Edge. My scenario is, I have a "Named Communication Object" in a tree and I want to drag it - to be a Vertex on one graph and an Edge on another - so I'm currently setting it up as a Vertex within an mxGraphTransferable from the drag point.

Is there a function for doing the conversion from a Vertex to an Edge once dropped?

The following works (up to a point) - (i.e. in overridden graphModel.add()).


But the cell label gets displaced outside the edge bounds - almost as if the label geometry is changed to relative from absolute. Potentially I assume there may be a difference in how the geometry for a label and a cell work.

I've tried adjusting this using setLabelBounds() via cell state and setRelative(true/false) via cell geometry with no luck.

Thanks Dazed

asked 08 Jan '13, 05:04

dazed's gravatar image

accept rate: 0%

SetRelative(true) on the geometry should work, try doing a graph.refresh(cell) after it to update the label bounds and force a repaint.


answered 08 Jan '13, 05:34

Gaudenz's gravatar image

accept rate: 39%

Gaudenz, thanks - found there was a bit more to think about (when the edge isn't connected on initial drop)

(08 Jan '13, 08:33) dazed

After digging into the library code a bit, I found the following works.

 mxGeometry geometry = cell.getGeometry();


 mxPoint spt = new mxPoint(geometry.getX(), geometry.getY()+geometry.getHeight());
 geometry.setTerminalPoint(spt, true);
 mxPoint tpt = new mxPoint(geometry.getX()+geometry.getWidth(), geometry.getY());
 geometry.setTerminalPoint(tpt, false);


As the edge isn't initially connected to Vertexes the geometry needs source and target terminal points added. And the label seemed to be affected by the X and Y which were initially set by mouse drop position - with relative and X=0 and Y=0 it works.

Cheers Dazed


answered 08 Jan '13, 08:37

dazed's gravatar image

accept rate: 0%

Yeah, now that you say it, it makes sense... :-) Thanks for sharing this!

(08 Jan '13, 08:38) Gaudenz
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 Jan '13, 05:04

Seen: 1,204 times

Last updated: 08 Jan '13, 08:38