1
1

I want to add what looks like "floating text" to my graph and have the vertex containing the text autosize to that label.

asked 14 Mar '11, 09:54

JacobShafer's gravatar image

JacobShafer
1112
accept rate: 0%

edited 24 Jun '14, 11:47

David's gravatar image

David
4.9k21831


This can be implemented as follows for a given graph and parent:

var graph = new mxGraph(container);
var parent = graph.getDefaultParent();

First mxGraph.isAutoSizeCell needs to be overridden if you want the cell size to change after each change of its value:

graph.isAutoSizeCell = function(cell)
{
  var state = this.view.getState(cell);
  var style = (state != null) ? state.style : this.getCellStyle(cell);

  return this.isAutoSizeCells() || style['autosize'] == 1;
};

This implementation uses a new style (autosize) which can be set to 1 to enable automatic sizing of a cell as follows:

graph.getModel().beginUpdate();
try
{
  var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30,
    'strokeColor=none;fillColor=none;resizable=0;autosize=1;');
  graph.updateCellSize(v1);
}
finally
{
  graph.getModel().endUpdate();
}

The call to updateCellSize explicitly updates the size of the cell to its preferred size after being inserted. The resizable=0 style is optional and disables manual sizing of the cell.

link

answered 22 Mar '11, 01:29

Gaudenz's gravatar image

Gaudenz
80.1k1310
accept rate: 39%

edited 24 Jun '14, 11:49

David's gravatar image

David
4.9k21831

Your answer
toggle preview

Follow this question

By Email:

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

By RSS:

Answers

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

Tags:

×228
×29
×9
×5

Asked: 14 Mar '11, 09:54

Seen: 4,155 times

Last updated: 24 Jun '14, 11:49