Using JavaScript I'm trying to get the position of a cell relative to the container holding the graph not the graph itself. Or at the very least the x and y values of the graph at the top left corner of the container so I can do the math. The graph has no defined dimensions and can pan forever. So when the graph pans the position values I'm looking for should change.

I've tried:

cell.geometry.realtive = true;
cell.geometry.x;
cell.geometry.y;
mxUtils.getScrollOrigin(cell);
mxUtils.getOffset(graph.container);
mxUtils.convertPoint(container,x,y);

None of these have yeilded any results.

asked 23 Aug '11, 13:10

rrogers's gravatar image

rrogers
111
accept rate: 0%

edited 10 May '12, 06:44

David's gravatar image

David
4.9k21831


All children are relative by default, here is an example:

var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 100, 50);
var v2 = graph.insertVertex(v1, null, 'World!', 10, 10, 80, 30);
link

answered 23 Aug '11, 23:49

Gaudenz's gravatar image

Gaudenz
80.1k1310
accept rate: 39%

edited 10 May '12, 06:45

David's gravatar image

David
4.9k21831

The problem is I'm getting points relative to the origin of the graph not the top left corner of the container. The graph is infinite so there is no guarantee cells will be in the bottom right quadrant. How can I get a cells position relative to the graphs container?

(24 Aug '11, 05:13) rrogers

I finally figured it out:

var cell = graph.getSelectionCell();
var cellX = graph.view.getState(cell).shape.node.offsetLeft;
var cellY = graph.view.getState(cell).shape.node.offsetTop;
link

answered 24 Aug '11, 12:18

rrogers's gravatar image

rrogers
111
accept rate: 0%

edited 10 May '12, 06:47

David's gravatar image

David
4.9k21831

Hi, I tried the same above code for offsetLeft and offsetTop, its not working. Is there any other changes to be done for the same code.

Even i also tried

var cell  = graph.getSelectionCell(rootnode);
var cellX = graph.view.getState(cell).shape.node.offsetLeft;
var cellY = graph.view.getState(cell).shape.node.offsetTop;
(10 May '12, 06:37) hansie

I'm not sure what exactly it is you need, but you can get the following numbers:

var state = graph.view.getState(graph.getSelectionCell()); state.x/y => Absolute coordinates of the shape (scaled and translated)

var origin = mxUtils.getOffset(graph.container); origin.x/y => Absolute coordinates of the graph container (top, left corner)

graph.container.scrollLeft/-Top: Position of the scrollbars in the graph container

BTW: The above solution using offsetLeft/-Top on the shape's node will only work in VML/HTML, but not in SVG.

link

answered 14 May '12, 05:44

Gaudenz's gravatar image

Gaudenz
80.1k1310
accept rate: 39%

Thanks Gaudenz for the reply, actually i found some other solution by using bounds width, and interestingly i was successful what i was expecting...Now from this i am getting the full scrollbar to the entire graph also. But the problem i am facing now is from outline container graph, when i move the picture to the desired one in outline graph, scrollbar is not affecting as that is relative to container, but what i have done is for body now and not the container... Can u suggest any ideas for this...

Thanks in advance

link

answered 14 May '12, 06:22

hansie's gravatar image

hansie
51428
accept rate: 0%

edited 14 May '12, 06:29

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
×66
×9
×2

Asked: 23 Aug '11, 13:10

Seen: 4,019 times

Last updated: 14 May '12, 06:29