Geometry Properties — SVG 2 (original) (raw)

Chapter 7: Geometry Properties

Contents

    1. 7.1. Horizontal center coordinate: The ‘cx’ property
    2. 7.2. Vertical center coordinate: The ‘cy’ property
    3. 7.3. Radius: The ‘r’ property
    4. 7.4. Horizontal radius: The ‘rx’ property
    5. 7.5. Vertical radius: The ‘ry’ property
    6. 7.6. Horizontal coordinate: The ‘x’ property
    7. 7.7. Vertical coordinate: The ‘y’ property
    8. 7.8. Sizing properties: the effect of the ‘width’ and ‘height’ properties

Beside SVG's styling properties, SVG also definesgeometry properties. Geometry properties describe the position and dimension of the graphics elements ‘circle’,‘ellipse’, ‘rect’, ‘image’, ‘foreignObject’ and the‘svg’ element.

7.1. Horizontal center coordinate: The ‘cx’ property

Name: cx
Value:
Initial: 0
Applies to: circle’ and ‘ellipse’ elements
Inherited: no
Percentages: refer to the width of the current SVG viewport (seeUnits)
Media: visual
Computed value: an absolute length or percentage
Animation type: by computed value

The cx property describes the horizontal center coordinate of the position of the element.

7.2. Vertical center coordinate: The ‘cy’ property

Name: cy
Value:
Initial: 0
Applies to: circle’ and ‘ellipse’ elements
Inherited: no
Percentages: refer to the height of the current SVG viewport (seeUnits)
Media: visual
Computed value: an absolute length or percentage
Animation type: by computed value

The cy property describes the vertical center coordinate of the position of the element.

7.3. Radius: The ‘r’ property

Name: r
Value:
Initial: 0
Applies to: circle’ element
Inherited: no
Percentages: refer to the normalized diagonal of the current SVG viewport (seeUnits)
Media: visual
Computed value: an absolute length or percentage
Animation type: by computed value

The r property describes the radius of the ‘circle’element.

A negative value for r is invalid and must be ignored.

7.4. Horizontal radius: The ‘rx’ property

Name: rx
Value: | auto
Initial: auto
Applies to: ellipse’, ‘rect’ elements
Inherited: no
Percentages: refer to the width of the current SVG viewport (seeUnits)
Media: visual
Computed value: an absolute length or percentage
Animation type: by computed value

The rx property describes the horizontal radius of the‘ellipse’ element and the curve radius of the ‘rect’element. When the computed value of ‘rx’ is auto, the used radius is equal to the absolute length used for ry, creating a circular arc. If both ‘rx’ and ‘ry’ have a computed value of auto, the used value is 0.

Regardless of how the value is calculated, the used value of ‘rx’ for a ‘rect’ is never more than 50% of the used value of width for the same shape.

The auto behavior is new in SVG 2 for ‘ellipse’, matching the behavior for ‘rect’ elements when rx was not specified.

A negative value for rx is invalid and must be ignored.

7.5. Vertical radius: The ‘ry’ property

Name: ry
Value: | auto
Initial: auto
Applies to: ellipse’, ‘rect
Inherited: no
Percentages: refer to the height of the current SVG viewport (seeUnits)
Media: visual
Computed value: an absolute length or percentage
Animatable type: by computed value

The ry property describes the vertical radius of the‘ellipse’ element and the vertical curve radius of the ‘rect’ element. When the computed value of ‘ry’ is auto, the used radius is equal to the absolute length used for rx, creating a circular arc. If both ‘rx’ and ‘ry’ have a computed value of auto, the used value is 0.

Regardless of how the value is calculated, the used value of ‘ry’ for a ‘rect’ is never more than 50% of the used value of height for the same shape.

The auto behavior is new in SVG 2 for ‘ellipse’, matching the behavior for ‘rect’ elements when ry was not specified.

A negative value for ry is invalid and must be ignored.

7.6. Horizontal coordinate: The ‘x’ property

Name: x
Value:
Initial: 0
Applies to: svg’, ‘rect’,‘image’, ‘foreignObject’ elements
Inherited: no
Percentages: refer to the width of the current SVG viewport (seeUnits)
Media: visual
Computed value: an absolute length or percentage
Animation type: by computed value

The x property describes the horizontal coordinate of the position of the element.

7.7. Vertical coordinate: The ‘y’ property

Name: y
Value:
Initial: 0
Applies to: svg’, ‘rect’,‘image’, ‘foreignObject’ elements
Inherited: no
Percentages: refer to the height of the current SVG viewport (seeUnits)
Media: visual
Computed value: an absolute length or percentage
Animation type: by computed value

The y property describes the vertical coordinate of the position of the element.

7.8. Sizing properties: the effect of the ‘width’ and ‘height’ properties

See the CSS 2.1 specification for the definitions ofwidth andheight.

The CSS width and height properties are used for sizing some SVG elements. Specifically, they are used to size‘rect’, ‘svg’, ‘image’ and‘foreignObject’. All of these elements have ‘width’and ‘height’ presentation attributes. The properties are also used for laying out embedded elements from the HTML namespace.

The used value of widthmay be constrained by the value of themax-width andmin-width properties. The used value of heightmay be constrained by the value of themax-height andmin-height properties.

The value auto for widthand height on the ‘svg’ element is treated as 100%.

The value auto for widthand height on the ‘image’ element is calculated from the referenced image's intrinsic dimensions and aspect ratio, according to the CSS Default Sizing Algorithm.

New in SVG 2. Images embedded in SVG can now be auto-sized to the intrinsic size, or scaled to a fixed height or width according to the intrinsic aspect ratio. This matches the behavior of embedded images in HTML.

The value auto for widthand height on other elements is treated as 0.

This means that, for example, a ‘foreignObject’object element will not shrink-wrap to its contents ifauto is used.