Coordinates

The canvas uses a world coordinate system with coordinates specified as floating point numbers. World coordinates mean that units can represent whatever is most convenient to you: meters, pixels, parsecs, etc.

Coordinates are calculated from the origin of the canvas, which has coordinates (0.0, 0.0). Positive X coordinates go to the right of the origin, and positive Y coordinates go down, like in the rest of the X Window System.

Coordinates of items are calculated with respect to their parent group. When a group is moved, its children's logical coordinates do not change, although their physical position does. A group stores a single pair of coordinates which define its origin relative to its parent group. The canvas' root group starts with its origin in world position (0.0, 0.0).

For example, let us say you have a toplevel group at (5.0, 3.0). If you insert an item in it with coordinates (2.0, 1.0), the item will appear to be at coordinates (7.0, 4.0). Coordinates of items are always relative to their parent group.

You will normally only need use this floating point, world coordinate system. The canvas also has a different coordinate system which works in terms of pixel offsets. This coordinate system is used internally to control scrolling of the canvas. You won't need to know about it unless you want to do scrolling by hand (as opposed to letting scrollbars handle this for you), or when you create your own canvas item types. We will discuss this pixel coordinate system later.

Zooming and scale

You can change the zoom factor of the canvas so that all the objects in it will appear larger or smaller. To control the zoom factor, you specify the number of pixels per unit that the canvas will use when converting world coordinates to display coordinates. The default is to use 1.0 pixels per unit, so an object that is 10 units wide will be displayed as 10 pixels wide. If you set the canvas to use 5 pixels per unit, then that object will be displayed as 50 pixels wide.

Sometimes you may want some features of your drawing to have the same displayed size regardless of the zoom factor of the canvas. For example, in a display of a graph composed of vertices and edges, you may want the edges to keep the same displayed width even if you zoom in closer to the graph, as well as having arrowheads keep the same size regardless of the zoom factor of the canvas.

Canvas items like lines and rectangles which support an outline width parameter let you select whether the outline width is specified in absolute pixels (which will keep the same displayed size regardless of the zoom factor of the canvas), or normal units (which will get scaled when the zoom factor is changed).