Welcome to yEd Q&A!
Here you can ask questions and receive answers from other members of the community and yEd developers. And you can tell us your most wanted feature requests.

Categories

Why does yEd use negative coordinates?

0 votes

In a new diagram, an object placed at coordinates (0,0) is located in the upper left corner:

Once "Show entire graph" is pressed, the first object is displayed centered and negative coordinates become available:

Why is that? Wouldn't it be simpler if (0, 0) is always the top left corner?

in Help by (170 points)

1 Answer

0 votes

Re:

Why is that?

Because "Show entire graph" does not change the coordinates of individual elements, but adjusts the viewport of yEd's editor area.

Re:

Wouldn't it be simpler if (0, 0) is always the top left corner?

No, it would not. Suppose you have a graph with lots of nodes. Suppose further, there is one node at (0,0) and that node is the left-most node in the graph.
If you need to move the aforementioned node to the left, assigning it negative coordinates is the sensible thing to do, because otherwise you would have to adjust the coordinates of all the other nodes even though those other nodes were not moved at all.

by [yWorks] (161k points)
Makes sense that I don't have to move the first thing at (0,0) if I want to put things to the left of it later.

But even if there are no new objects, pressing "Show entire graph" puts (0, 0) in the center, not the top left. That's what confused me.

Maybe I can clear up the confusion: "Show entire graph" does not necessarily put (0,0) in the center, but the center of the bounds of the whole graph. If there is only one node in your diagram, this node will end up in the center of the viewport. However, if there are several elements in the graph, the center of the viewport will be the center of the bounds of the entire graph. E.g. suppose there are two nodes, one with x=200, y=100, width=30, height=30 and one with x=400, y=500, width=80, height=60, then the bounds of the entire graph will be x=200, y=100, width=280, height=460. In this case, x=340, y=330 will end up being the center of the viewport after the "Show entire graph" operation.

If there are no elements, it is kind of debatable what constitutes the center of the whole graph. From a implementation point of view, it does make sense to assume width=0 and height=0 for the bounds of a graph with no elements. In this case, "Show entire graph" will center on the x and y coordinates of the graph bounds. Since there are no elements, there is not really a right or wrong choice for x and y. We did choose x=0 and y=0 because 0 is the default value for numbers in Java (the programming language that was used to create yEd). As a result, "Show entire graph" centers on (0,0) if there are no elements. Again, from an implementation point of view this make sense, because this means that there are no special cases for "Show entire graph".

By the way, negative coordinates do not become available only after "Show entire graph" - they are available right from the start.
E.g. start with an empty document. Create one node. Select said node. Now specify negative coordinates for the node's x and y properties in the properties view in yEd's lower right corner. If you specify small enough values, this will actually "move" the selected node out of  the current viewport. "Show entire graph" will again center the viewport on the node resulting in the viewport center having negative coordinates.

Legal Disclosure | Privacy Policy
...