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 23 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
71 changes: 71 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,71 @@
---
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 the specified unit type.

This function will:

- Set the {{domxref("SVGAngle.unitType", "unitType")}} property to the given unit type
- Update the {{domxref("SVGAngle.valueInSpecifiedUnits", "valueInSpecifiedUnits")}} and {{domxref("SVGAngle.valueAsString", "valueAsString")}} properties so the angle value is represented in the given unit type

## Syntax

```js-nolint
svgAngle.convertToSpecifiedUnits(unitType)
```

### Parameters

- `unitType`
- : A constant representing the unit type to which the angle's value should be converted. This must be one of the constant values defined for the {{domxref("SVGAngle.unitType", "unitType")}} property, with the exception of `SVG_ANGLETYPE_UNKNOWN`.
- `SVGAngle.SVG_ANGLETYPE_DEG`: convert to degrees
- `SVGAngle.SVG_ANGLETYPE_RAD`: convert to radians
- `SVGAngle.SVG_ANGLETYPE_GRAD`: convert to gradians
- `SVGAngle.SVG_ANGLETYPE_UNSPECIFIED`: convert to a unitless number, interpreted as degrees

### Return value

None ({{jsxref('undefined')}}).

## Examples

### Converting an angle to degrees

```js
// Get an SVGAngle object
const svg = document.querySelector("svg");
const angle = svg.createSVGAngle();

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

// Retrieve the angle's value as a string
console.log(angle.valueAsString); // Output: 1.5708rad
console.log(angle.unitType); // Output: 3 (SVG_ANGLETYPE_RAD)

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

// Retrieve the angle's value as a string
console.log(angle.valueAsString); // Output: 90deg
console.log(angle.unitType); // Output: 2 (SVG_ANGLETYPE_DEG)
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("SVGAnimatedAngle")}}
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
104 changes: 104 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,104 @@
---
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 resets the value as a number with an associated {{domxref("SVGAngle.unitType", "unitType")}}, thereby replacing the values for all of the attributes on the object.
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved

## Syntax

```js-nolint
svgAngle.newValueSpecifiedUnits(unitType, valueInSpecifiedUnits)
```

### Parameters

- `unitType`

- : A constant representing the unit type to which the angle's value should be converted. This must be one of the constant values defined for the {{domxref("SVGAngle.unitType", "unitType")}} property, with the exception of `SVG_ANGLETYPE_UNKNOWN`.
- `SVGAngle.SVG_ANGLETYPE_DEG`: convert to degrees
- `SVGAngle.SVG_ANGLETYPE_RAD`: convert to radians
- `SVGAngle.SVG_ANGLETYPE_GRAD`: convert to gradians
- `SVGAngle.SVG_ANGLETYPE_UNSPECIFIED`: convert to a unitless number, interpreted as degrees

- `valueInSpecifiedUnits`
- : The numeric factor for the angle value, expressed in the specified unit type.

### Return value

None ({{jsxref('undefined')}}).

### Exceptions

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

- `NotSupportedError` {{domxref("DOMException")}}

- : Thrown if `unitType` is `SVG_ANGLETYPE_UNKNOWN` or not a valid unit type constant.

- `NoModificationAllowedError` {{domxref("DOMException")}}
- : Thrown if {{domxref("SVGAngle")}} corresponds to a read-only attribute or when the object itself is read-only.

## Examples

### Setting an angle in degrees

```js
// Get an SVGAngle object
const svg = document.querySelector("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
// Get an SVGAngle object
const svg = document.querySelector("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
// Get an SVGAngle object
const svg = document.querySelector("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)
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("SVGAnimatedAngle")}}
45 changes: 45 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,45 @@
---
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 is one of the [unit type contants](/en-US/docs/Web/API/SVGAngle#constants) and represents the units in which this angle's value is expressed.
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved

## Value

An `integer`; the angle type as an unsigned short.
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved

## Examples

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

```js
// Get an SVGAngle object
const svg = document.querySelector("svg");

// Assume `angle` is an instance of SVGAngle
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved
const angle = 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("SVGAnimatedAngle")}}
45 changes: 45 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,45 @@
---
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 floating point value of the [`<angle>`](/en-US/docs/Web/SVG/Content_type#angle) in degrees.

Setting this attribute will cause {{domxref("SVGAngle.valueInSpecifiedUnits", "valueInSpecifiedUnits")}} and {{domxref("SVGAngle.valueAsString", "valueAsString")}} to be updated automatically to reflect this setting.

## Value

An `integer`; the angle value in degrees as a float.
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved

## Examples

```js
// Get an SVGAngle object
const svg = document.querySelector("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
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

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

{{APIRef("SVG")}}

The `valueAsString` property of the {{domxref("SVGAngle")}} interface represents the angle's value as a **string**, in the units expressed by {{domxref("SVGAngle.unitType", "unitType")}}.
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved

Setting this attribute will cause {{domxref("SVGAngle.value", "value")}}, {{domxref("SVGAngle.valueInSpecifiedUnits", "valueInSpecifiedUnits")}}, and {{domxref("SVGAngle.unitType", "unitType")}} to be updated automatically to reflect this setting.

## Value

A `string`; the value of the angle.
yashrajbharti marked this conversation as resolved.
Show resolved Hide resolved

## Examples

### Setting and retrieving `valueAsString`

```js
// Get an SVGAngle object
const svg = document.querySelector("svg");
const angle = svg.createSVGAngle();

// Set the value using valueAsString in degrees
angle.valueAsString = "45deg";
console.log(angle.valueAsString); // Output: "45deg"
console.log(angle.value); // Output: 45 (in degrees)

// Set the value using valueAsString in radians
angle.valueAsString = "1.57rad";
console.log(angle.valueAsString); // Output: "1.57rad"
console.log(Math.round(angle.value)); // Output: 90 (since 1.57 radians is approximately 90 degrees)
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [`<angle>`](/en-US/docs/Web/SVG/Content_type#angle)
- {{domxref("SVGAnimatedAngle")}}
Loading
Loading