How do i add a vertex at the center of the diagram, taking into account the scrollbars, if they exist? And also taking into account the zoom?
\nI mean, no matter where the user has scrolled the graph, i need to be able to add a vertex the center of the viewable area, not the center of the whole graph.
\n

\n

How do I achive that please?

asked 24 Aug '11, 06:14

Avi%20Shilon's gravatar image

Avi Shilon
1041528
accept rate: 14%


Try this:

\n
var s = graph.view.scale;\nvar c = graph.container;\nvar w = 80;\nvar h = 40;\nvar x = (c.scrollLeft + c.clientWidth / 2) / s - w / 2;\nvar y = (c.scrollTop + c.clientHeight / 2) / s - h / 2;\n\nvar parent = graph.getDefaultParent();\ngraph.insertVertex(parent, null, 'Test', x, y, w, h);\n
link

answered 25 Aug '11, 06:53

Gaudenz's gravatar image

Gaudenz
80.1k1310
accept rate: 39%

Helpful as always Gaudenz. Thanks a lot!

(25 Aug '11, 07:43) Avi Shilon

Can I tell if there is already a vertex at the exact location in the center,
\nso that i can add a little offset to the x, y coordiantes of the vertex to be
\nadded (so it doesn't hide the one with the same coordinates)?

(28 Aug '11, 03:49) Avi Shilon

Not without a loop where you check the bounds of each vertex against the x and y values (w, h) in the above code.

(28 Aug '11, 08:11) Gaudenz
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:

×5

Asked: 24 Aug '11, 06:14

Seen: 1,139 times

Last updated: 28 Aug '11, 08:11