Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: SVG Angle MDN Feature Pages #37013

Merged
merged 33 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
80f5450
add: SVG Angle MDN Feature Pages
yashrajbharti Nov 28, 2024
14ecd52
fixes the format
yashrajbharti Dec 5, 2024
be260f1
fix: the general format of instance property
yashrajbharti Dec 5, 2024
9c1a0c7
Update files/en-us/web/api/svgangle/converttospecifiedunits/index.md
yashrajbharti Dec 6, 2024
56e0cf0
major content fixes
yashrajbharti Dec 6, 2024
98c95a6
fix: content
yashrajbharti Dec 6, 2024
f909f48
changed format for values in unitType
yashrajbharti Dec 6, 2024
40fce22
Update files/en-us/web/api/svgangle/converttospecifiedunits/index.md
yashrajbharti Dec 17, 2024
cad9283
Update files/en-us/web/api/svgangle/converttospecifiedunits/index.md
yashrajbharti Dec 17, 2024
e8aa82f
Update files/en-us/web/api/svgangle/converttospecifiedunits/index.md
yashrajbharti Dec 17, 2024
7448d51
Update files/en-us/web/api/svgangle/converttospecifiedunits/index.md
yashrajbharti Dec 17, 2024
85c8eed
fix: syntax
yashrajbharti Dec 17, 2024
c8f070d
fix: syntax
yashrajbharti Dec 17, 2024
7b870aa
fix: return type
yashrajbharti Dec 17, 2024
c1ac8d6
fix: parameters for new value in specified units
yashrajbharti Dec 17, 2024
d3c0b88
fix: unittype
yashrajbharti Dec 17, 2024
64212f3
fix unittype format
yashrajbharti Dec 17, 2024
3b6e4a5
fix: value
yashrajbharti Dec 25, 2024
427ca5d
Update index.md
yashrajbharti Dec 25, 2024
52e1686
Update index.md
yashrajbharti Dec 26, 2024
d18d2e5
fix for consistency
yashrajbharti Dec 29, 2024
9f79ac0
Merge branch 'main' into feat/SVGAngle
wbamberg Jan 6, 2025
55471ed
Update files/en-us/web/api/svgangle/unittype/index.md
yashrajbharti Jan 7, 2025
ac0a1ef
Update files/en-us/web/api/svgangle/newvaluespecifiedunits/index.md
yashrajbharti Jan 7, 2025
197e649
Update files/en-us/web/api/svgangle/valueinspecifiedunits/index.md
yashrajbharti Jan 7, 2025
231599b
Update files/en-us/web/api/svgangle/value/index.md
yashrajbharti Jan 7, 2025
d1479a0
Update files/en-us/web/api/svgangle/valueinspecifiedunits/index.md
yashrajbharti Jan 7, 2025
64d0821
Update files/en-us/web/api/svgangle/unittype/index.md
yashrajbharti Jan 7, 2025
0acf266
Update files/en-us/web/api/svgangle/unittype/index.md
yashrajbharti Jan 7, 2025
2f27dc0
Update files/en-us/web/api/svgangle/valueasstring/index.md
yashrajbharti Jan 7, 2025
1c276ee
fix: bold string removed
yashrajbharti Jan 7, 2025
8c2ede8
fix: remove angle comment
yashrajbharti Jan 7, 2025
6bb38f5
Merge branch 'main' into feat/SVGAngle
yashrajbharti Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions files/en-us/web/api/svgangle/converttospecifiedunits/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: "SVGAngle: convertToSpecifiedUnits() method"
short-title: convertToSpecifiedUnits()
slug: Web/API/SVGAngle/convertToSpecifiedUnits
page-type: web-api-instance-method
browser-compat: api.SVGAngle.convertToSpecifiedUnits
---

{{APIRef("SVG")}}

The `convertToSpecifiedUnits()` method of the {{domxref("SVGAngle")}} interface allows you to convert the angle's value to a specified unit type. This method is used when you want to convert an angle from its current unit type to another specified unit.
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved

## Syntax

```js
svgAngle.convertToSpecifiedUnits(unitType);
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved
```

### Parameters

- **{{domxref("SVGAngle.unitType")}}**
A constant representing the unit type to which the angle's value should be converted. This can be one of the following:
- `SVG_ANGLETYPE_DEG` — Degrees
- `SVG_ANGLETYPE_RAD` — Radians
- `SVG_ANGLETYPE_GRAD` — Gradians
- `SVG_ANGLETYPE_UNSPECIFIED` — Unitless (a number only)
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved

### Return Value
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved

A reference to the updated {{domxref("SVGAngle")}} object.
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved

When the `convertToSpecifiedUnits()` method is successfully called, the `SVGAngle` object's `valueInSpecifiedUnits` is converted to match the specified `unitType`, and its value is updated accordingly. If the `SVGAngle` reflects the base value of an attribute, the corresponding attribute is re-serialized to reflect the updated angle.
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved

### Exceptions

This method may raise a {{domxref("DOMException")}} of one of the following types:

- `NO_MODIFICATION_ALLOWED_ERR` {{domxref("DOMException")}}
- : Thrown if the `SVGAngle` object is read-only and modification is attempted.
- `NOT_SUPPORTED_ERR` {{domxref("DOMException")}}
- : Thrown if the `unitType` is not a valid value or is `SVG_ANGLETYPE_UNKNOWN`.
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved

## Examples

Converting an angle to degrees
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved

```js
// Create an SVGAngle object
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
const angle = svg.createSVGAngle();

// Set the angle's value in radians (Math.PI / 2)
angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_RAD, Math.PI / 2);

// Convert the angle's value to degrees
angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG);

// Retrieve the angle's value in degrees
console.log(angle.value); // Output: 90
console.log(angle.unitType); // Output: 2 (SVG_ANGLETYPE_DEG)
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved
```

Attempting to convert to an unsupported unit type
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved

```js
try {
// Create an SVGAngle object
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
const angle = svg.createSVGAngle();

// Attempt to convert to an invalid unit type
angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_UNKNOWN);
} catch (e) {
console.error(e.name); // Output: NotSupportedError
}
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("SVGAngle.unitType")}}
- {{domxref("SVGAngle.valueInSpecifiedUnits")}}
- {{domxref("SVGAngle.newValueSpecifiedUnits")}}
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 9 additions & 6 deletions files/en-us/web/api/svgangle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,23 @@ Every `SVGAngle` object operates in one of two modes:

## Instance properties

- `unitType`
- {{domxref("SVGAngle.unitType")}}

- : The type of the value as specified by one of the `SVG_ANGLETYPE_*` constants defined on this interface.
- `value`

- {{domxref("SVGAngle.value")}}

- : The value as a floating point value, in user units. Setting this attribute will cause `valueInSpecifiedUnits` and `valueAsString` to be updated automatically to reflect this setting.

**Exceptions on setting:** A {{domxref("DOMException")}} with code `NO_MODIFICATION_ALLOWED_ERR` is raised when the length corresponds to a read-only attribute, or when the object itself is read-only.

- `valueInSpecifiedUnits`
- {{domxref("SVGAngle.valueInSpecifiedUnits")}}

- : The value as a floating point value, in the units expressed by `unitType`. Setting this attribute will cause `value` and `valueAsString` to be updated automatically to reflect this setting.

**Exceptions on setting:** A {{domxref("DOMException")}} with code `NO_MODIFICATION_ALLOWED_ERR` is raised when the length corresponds to a read-only attribute, or when the object itself is read-only.

- `valueAsString`
- {{domxref("SVGAngle.valueAsString")}}

- : The value as a string value, in the units expressed by `unitType`. Setting this attribute will cause `value`, `valueInSpecifiedUnits`, and `unitType` to be updated automatically to reflect this setting.

Expand All @@ -59,7 +61,7 @@ Every `SVGAngle` object operates in one of two modes:

## Instance methods

- `newValueSpecifiedUnits`
- {{domxref("SVGAngle.newValueSpecifiedUnits")}}

- : Reset the value as a number with an associated unitType, thereby replacing the values for all of the attributes on the object.

Expand All @@ -68,7 +70,8 @@ Every `SVGAngle` object operates in one of two modes:
- A {{domxref("DOMException")}} with code `NOT_SUPPORTED_ERR` is raised if `unitType` is `SVG_ANGLETYPE_UNKNOWN` or not a valid unit type constant (one of the other `SVG_ANGLETYPE_*` constants defined on this interface).
- A {{domxref("DOMException")}} with code `NO_MODIFICATION_ALLOWED_ERR` is raised when the length corresponds to a read only attribute or when the object itself is read only.

- `convertToSpecifiedUnits`
- {{domxref("SVGAngle.convertToSpecifiedUnits")}}

- : Preserve the same underlying stored value, but reset the stored unit identifier to the given `unitType`. Object attributes `unitType`, `valueInSpecifiedUnits`, and `valueAsString` might be modified as a result of this method.

## Specifications
Expand Down
121 changes: 121 additions & 0 deletions files/en-us/web/api/svgangle/newvaluespecifiedunits/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
title: "SVGAngle: newValueSpecifiedUnits() method"
short-title: newValueSpecifiedUnits()
slug: Web/API/SVGAngle/newValueSpecifiedUnits
page-type: web-api-instance-method
browser-compat: api.SVGAngle.newValueSpecifiedUnits
---

{{APIRef("SVG")}}

The `newValueSpecifiedUnits()` method of the {{domxref("SVGAngle")}} interface allows you to set the angle's value in a specified unit type. This method is used when you want to provide a unit alongside the numeric value of the angle.

## Syntax

```js
svgAngle.newValueSpecifiedUnits(unitType, valueInSpecifiedUnits);
```

### Parameters

- **{{domxref("SVGAngle.unitType")}}**
A constant representing the unit type for the angle. This can be one of the following:

- `SVG_ANGLETYPE_DEG` — Degrees
- `SVG_ANGLETYPE_RAD` — Radians
- `SVG_ANGLETYPE_GRAD` — Gradians
- `SVG_ANGLETYPE_UNSPECIFIED` — Unitless (a number only)

- **{{domxref("SVGAngle.valueInSpecifiedUnits")}}**
The numeric factor for the angle value, expressed in the specified unit type (e.g., a number for degrees, radians, or gradians).

### Return Value

A reference to the updated {{domxref("SVGAngle")}} object.

If the `newValueSpecifiedUnits()` method is successfully called, the `SVGAngle` object's `valueInSpecifiedUnits` is updated to the specified numeric factor, and the `unitType` is set to the provided unit type. For `SVG_ANGLETYPE_UNSPECIFIED`, the angle is treated as a unitless number. When the `SVGAngle` reflects a base value of an attribute, the corresponding attribute is re-serialized to reflect the updated angle.

### Exceptions

This method may raise a {{domxref("DOMException")}} of one of the following types:

- `NO_MODIFICATION_ALLOWED_ERR` {{domxref("DOMException")}}
- : Thrown if the `SVGAngle` object is read-only and modification is attempted.
- `NOT_SUPPORTED_ERR` {{domxref("DOMException")}}
- : Thrown if the `unitType` is not a valid value or is `SVG_ANGLETYPE_UNKNOWN`.

## Examples

Setting an angle in degrees

```js
// Create an SVGAngle object
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
const angle = svg.createSVGAngle();

// Set the angle's value in degrees using newValueSpecifiedUnits()
angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, 45);

// Retrieve the angle's value in degrees
console.log(angle.value); // Output: 45
console.log(angle.unitType); // Output: 2 (SVG_ANGLETYPE_DEG)
```

Setting an angle in radians

```js
// Create an SVGAngle object
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
const angle = svg.createSVGAngle();

// Set the angle's value in radians using newValueSpecifiedUnits()
angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_RAD, Math.PI / 2);

// Retrieve the angle's value
console.log(angle.value); // Output: 90
console.log(angle.unitType); // Output: 3 (SVG_ANGLETYPE_RAD)
```

Setting an angle in gradians

```js
// Create an SVGAngle object
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
const angle = svg.createSVGAngle();

// Set the angle's value in gradians using newValueSpecifiedUnits()
angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_GRAD, 100);

// Retrieve the angle's value in gradians
console.log(angle.value); // Output: 90
console.log(angle.unitType); // Output: 4 (SVG_ANGLETYPE_GRAD)
```

Attempting to set an unsupported unit type

```js
try {
// Create an SVGAngle object
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
const angle = svg.createSVGAngle();

// Attempt to set an invalid unit type
angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_UNKNOWN, 45);
} catch (e) {
console.error(e.name); // Output: NotSupportedError
}
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("SVGAngle.unitType")}}
- {{domxref("SVGAngle.valueInSpecifiedUnits")}}
- {{domxref("SVGAngle.convertToSpecifiedUnits")}}
52 changes: 52 additions & 0 deletions files/en-us/web/api/svgangle/unittype/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: "SVGAngle: unitType property"
short-title: unitType
slug: Web/API/SVGAngle/unitType
page-type: web-api-instance-property
browser-compat: api.SVGAngle.unitType
---

{{APIRef("SVG")}}

The **`unitType`** property of the {{domxref("SVGAngle")}} interface that represents the type of value the `SVGAngle` holds. This is determined by one of the predefined constants of the `SVGAngle` interface.

## Value

An **unsigned short** indicating the angle type, represented by one of the following constants:

- `SVG_ANGLETYPE_UNKNOWN` (0): The angle type is unknown or not specified.
- `SVG_ANGLETYPE_UNSPECIFIED` (1): A unitless number, interpreted as degrees.
- `SVG_ANGLETYPE_DEG` (2): The angle is specified in degrees (`deg`).
- `SVG_ANGLETYPE_RAD` (3): The angle is specified in radians (`rad`).
- `SVG_ANGLETYPE_GRAD` (4): The angle is specified in gradians (`grad`).

## Examples

Here's an example of how to access the `unitType` property:

```js
// Assume `angle` is an instance of SVGAngle
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved
const angle = document
.createElementNS("http://www.w3.org/2000/svg", "svg")
.createSVGAngle();

// Set the angle value
angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, 45);

// Check the unit type
console.log(angle.unitType); // Output: 2 (SVG_ANGLETYPE_DEG)
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("SVGAngle.value")}}
- {{domxref("SVGAngle.valueInSpecifiedUnits")}}
- {{domxref("SVGAngle.valueAsString")}}
65 changes: 65 additions & 0 deletions files/en-us/web/api/svgangle/value/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: "SVGAngle: value property"
short-title: value
slug: Web/API/SVGAngle/value
page-type: web-api-instance-property
browser-compat: api.SVGAngle.value
---

{{APIRef("SVG")}}

The `value` property of the {{domxref("SVGAngle")}} interface represents the numeric value of the angle in **degrees**. Setting this property automatically updates the {{domxref("SVGAngle.valueInSpecifiedUnits")}} and {{domxref("SVGAngle.valueAsString")}} attributes of the `SVGAngle` object.

A {{domxref("DOMException")}} with code `NO_MODIFICATION_ALLOWED_ERR` is thrown if the `SVGAngle` object is read-only.

## Value

A floating-point number indicating the angle value in degrees.

## Examples

```js
// Create an SVGAngle object
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
const angle = svg.createSVGAngle();

// Set the value
angle.value = 45;
console.log(angle.value); // Output: 45

// Reflecting the value
angle.value = 90;
console.log(angle.value); // Output: 90
```

Attempting to modify a read-only `SVGAngle` object will result in an error:

```js
try {
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");

rect.setAttribute("transform", "rotate(45)");
svg.appendChild(rect);

// Access the animVal (read-only)
const angle = rect.transform.baseVal.getItem(0).angle;
angle.value = 90; // Throws an error
} catch (e) {
console.error(e.name); // Output: NoModificationAllowedError
}
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("SVGAngle.unitType")}}
- {{domxref("SVGAngle.valueInSpecifiedUnits")}}
- {{domxref("SVGAngle.valueAsString")}}
Loading
Loading