I am adding a background image and vertices are placed on it.

The user can drag a vertex out of image border. I would like to limit the graph area to the size of the image and disable dragging of vertex out of image bounds.

Here's the code snippet :

  mxRectangleShape.prototype.crisp = true;

  // Creates the graph inside the given container
  var graph = new mxGraph(container);

  // Enables rubberband selection
  new mxRubberband(graph);
  var img = new mxImage('editors/images/floorplan.png', 805, 516);
  graph.setBackgroundImage(img);
  graph.view.validate();

  var parent = graph.getDefaultParent();                                
  // Adds cells to the model in a single step
  graph.getModel().beginUpdate();
  try
  {
    var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30);
  }
  finally
  {
    graph.getModel().endUpdate();
  }

Thanks In Advance.

This question is marked "community wiki".

asked 14 Feb '12, 19:33

punithsn's gravatar image

punithsn
1248
accept rate: 41%

edited 18 Jan '13, 06:26

David's gravatar image

David
4.9k21831

http://forum.jgraph.com/questions/1449/graph-bounds

related question, but not answered yet...

(14 Feb '12, 19:34) punithsn

Answering my own question:

graph.maximumGraphBounds = new mxRectangle(0, 0, requiredWidth, requiredHeight);
link

answered 14 Feb '12, 20:02

punithsn's gravatar image

punithsn
1248
accept rate: 41%

edited 18 Jan '13, 06:24

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
×18
×9
×5

Asked: 14 Feb '12, 19:33

Seen: 1,968 times

Last updated: 18 Jan '13, 06:26