Skip to content

Commit

Permalink
Document SVGClipPathElement.(clipPathUnits|transform) (#25340)
Browse files Browse the repository at this point in the history
Co-authored-by: dawei-wang <dawei-wang@users.noreply.github.com>
  • Loading branch information
teoli2003 and dawei-wang authored Mar 17, 2023
1 parent 150692a commit cce0046
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 93 deletions.
73 changes: 73 additions & 0 deletions files/en-us/web/api/svganimatedenumeration/animval/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
title: SVGAnimatedEnumeration.animVal
slug: Web/API/SVGAnimatedEnumeration/animVal
page-type: web-api-instance-property
browser-compat: api.SVGAnimatedEnumeration.animVal
---

{{APIRef("SVG")}}

The **`animVal`** property of the {{domxref("SVGAnimatedEnumeration")}} interface contains the current value of an SVG enumeration. If there is no animation, it is the same value as the {{domxref("SVGAnimatedEnumeration.baseVal", "baseVal")}}.

## Value

An integer containing the current value of the enumeration

## Examples

```css hidden
html,
body,
svg {
height: 100%;
}
```

```html
<div>
<svg viewbox="0 0 100 100" width="200" height="200">
<clipPath id="clip1" clipPathUnits="userSpaceOnUse">
<animate
attributeName="clipPathUnits"
values="userSpaceOnUse;objectBoundingBox;userSpaceOnUse"
dur="2s"
repeatCount="indefinite" />
<circle cx="50" cy="50" r="25" />
</clipPath>

<rect id="r1" x="0" y="0" width="50" height="100" />

<use clip-path="url(#clip1)" xlink:href="#r1" fill="lightblue" />
</svg>
</div>
<pre id="log"></pre>
```

```js
const clipPath1 = document.getElementById("clip1");
const log = document.getElementById("log");

function displayLog() {
const animValue = clipPath1.clipPathUnits.animVal;
const baseValue = clipPath1.clipPathUnits.baseVal;
log.textContent = `The 'clipPathUnits.animVal' is ${animValue}.\n`;
log.textContent += `The 'clipPathUnits.baseVal' is ${baseValue}.`;
requestAnimationFrame(displayLog);
}

displayLog();
```

{{EmbedLiveSample("Examples", "280", "260")}}

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("SVGAnimatedEnumeration.baseVal")}}
48 changes: 48 additions & 0 deletions files/en-us/web/api/svganimatedenumeration/baseval/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: SVGAnimatedEnumeration.baseVal
slug: Web/API/SVGAnimatedEnumeration/baseVal
page-type: web-api-instance-property
browser-compat: api.SVGAnimatedEnumeration.baseVal
---

{{APIRef("SVG")}}

The **`baseVal`** property of the {{domxref("SVGAnimatedEnumeration")}} interface contains the initial value of an SVG enumeration.

## Value

An integer containing the initial value of the enumeration

## Examples

Considering this snippet with a {{SVGElement("clipPath")}} element: Its {{SVGAttr("clipPathUnits")}} is associated with a {{domxref("SVGAnimatedEnumeration")}} object.

```html
<svg viewbox="0 0 100 100" width="200" height="200">
<clipPath id="clip1" clipPathUnits="userSpaceOnUse">
<circle cx="50" cy="50" r="35" />
</clipPath>

<!-- Some reference rect to materialized to clip path -->
<rect id="r1" x="0" y="0" width="45" height="45" />
</svg>
```

This snippet gets the element, and logs the `baseVal`of the {{domxref("SVGClipPathElement.clipPathUnits")}} property.

```js
const clipPathElt = document.getElementById("clip1");
console.log(clipPathElt.clipPathUnits.baseVal); // Logs 1 that correspond to userSpaceOnUse
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("SVGAnimatedEnumeration.animVal")}}
96 changes: 32 additions & 64 deletions files/en-us/web/api/svganimatedenumeration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,78 +7,46 @@ browser-compat: api.SVGAnimatedEnumeration

{{APIRef("SVG")}}

## SVG animated enumeration interface

The `SVGAnimatedEnumeration` interface is used for attributes whose value must be a constant from a particular enumeration and which can be animated.

### Interface overview

<table class="no-markdown">
<tbody>
<tr>
<th scope="row">Also implement</th>
<td><em>None</em></td>
</tr>
<tr>
<th scope="row">Methods</th>
<td><em>None</em></td>
</tr>
<tr>
<th scope="row">Properties</th>
<td>
<ul>
<li>unsigned short <code>baseVal</code></li>
<li>readonly unsigned short <code>animVal</code></li>
</ul>
</td>
</tr>
<tr>
<th scope="row">Normative document</th>
<td>
<a
href="https://www.w3.org/TR/SVG11/types.html#InterfaceSVGAnimatedEnumeration"
>SVG 1.1 (2nd Edition)</a
>
</td>
</tr>
</tbody>
</table>
The **`SVGAnimatedEnumeration`** interface describes attribute values which are constants from a particular enumeration and which can be animated.

## Instance properties

<table class="no-markdown">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>baseVal</code></td>
<td>unsigned short</td>
<td>
The base value of the given attribute before applying any animations.
</td>
</tr>
<tr>
<td><code>animVal</code></td>
<td>unsigned short</td>
<td>
If the given attribute or property is being animated, contains the
current animated value of the attribute or property. If the given
attribute or property is not currently being animated, contains the same
value as <code>baseVal</code>.
</td>
</tr>
</tbody>
</table>
- {{domxref("SVGAnimatedEnumeration.baseVal", "baseVal")}}
- : An integer that is the base value of the given attribute before applying any animations.
- {{domxref("SVGAnimatedEnumeration.animVal", "animVal")}}
- : If the given attribute or property is being animated, it contains the current animated value of the attribute or property. If the given attribute or property is not currently being animated, it contains the same value as `baseVal`.

## Instance methods

The `SVGAnimatedEnumeration` interface do not provide any specific methods.

## Examples

Considering this snippet with a {{SVGElement("clipPath")}} element: Its {{SVGAttr("clipPathUnits")}} is associated with a `SVGAnimatedEnumeration` object.

```html
<svg viewbox="0 0 100 100" width="200" height="200">
<clipPath id="clip1" clipPathUnits="userSpaceOnUse">
<circle cx="50" cy="50" r="35" />
</clipPath>

<!-- Some reference rect to materialized to clip path -->
<rect id="r1" x="0" y="0" width="45" height="45" />
</svg>
```

This snippet gets the element, and logs the `baseVal` and `animVal`of the {{domxref("SVGClipPathElement.clipPathUnits")}} property. As no animation is happening, they have the same value.

```js
const clipPathElt = document.getElementById("clip1");
console.log(clipPathElt.clipPathUnits.baseVal); // Logs 1 that correspond to userSpaceOnUse
console.log(clipPathElt.clipPathUnits.animVal); // Logs 1 that correspond to userSpaceOnUse
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}
87 changes: 87 additions & 0 deletions files/en-us/web/api/svgclippathelement/clippathunits/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
title: SVGClipPathElement.clipPathUnits
slug: Web/API/SVGClipPathElement/clipPathUnits
page-type: web-api-instance-property
browser-compat: api.SVGClipPathElement.clipPathUnits
---

{{APIRef("SVG")}}

The read-only **`clipPathUnits`** property of the {{domxref("SVGClipPathElement")}} interface reflects the {{SVGAttr("clipPathUnits")}} attribute of a {{SVGElement("clipPath")}} element which defines the coordinate system to use for the content of the element.

> **Note:** Although this property is read-only, it is merely a container for two values you can modify, {{domxref("SVGAnimatedEnumeration.baseVal", "baseVal")}} and {{domxref("SVGAnimatedEnumeration.animVal", "animVal")}}.
## Value

An {{domxref("SVGAnimatedEnumeration")}} representing the coordinate system. The possible values are defined in the {{domxref("SVGUnitTypes")}} interface:

- `0` (`SVG_UNIT_TYPE_UNKWOWN`)
- : The type is not one of the predefined type.
- `1` (`SVG_UNIT_TYPE_USERSPACEONUSE`)
- : Corresponds to a value of `userSpaceOnUse` for the {{SVGAttr("clipPathUnits")}} attribute and means that all coordinates inside the element refer to the user coordinate system as defined when the clipping path was created. It is the default value.
- `2` (`SVG_UNIT_TYPE_OBJECTBOUNDINGBOX`)
- : Corresponds to a value of `objectBoundingBox` for the attribute and means that all coordinates inside the element are relative to the bounding box of the element the clipping path is applied to. It means that the origin of the coordinate system is the top left corner of the object bounding box and the width and height of the object bounding box are considered to have a length of 1 unit value.

## Examples

```css hidden
html,
body,
svg {
height: 100%;
}
```

```html
<div>
<svg viewbox="0 0 100 100" width="200" height="200">
<clipPath id="clip1" clipPathUnits="userSpaceOnUse">
<circle cx="50" cy="50" r="35" />
</clipPath>

<clipPath id="clip2" clipPathUnits="objectBoundingBox">
<circle cx=".5" cy=".5" r=".35" />
</clipPath>

<!-- Some reference rect to materialized to clip path -->
<rect id="r1" x="0" y="0" width="45" height="45" />
<rect id="r2" x="0" y="55" width="45" height="45" />
<rect id="r3" x="55" y="55" width="45" height="45" />
<rect id="r4" x="55" y="0" width="45" height="45" />

<!-- The first 3 rect are clipped with userSpaceOnUse units -->
<use clip-path="url(#clip1)" xlink:href="#r1" fill="red" />
<use clip-path="url(#clip1)" xlink:href="#r2" fill="blue" />
<use clip-path="url(#clip1)" xlink:href="#r3" fill="yellow" />

<!-- The last rect is clipped with objectBoundingBox units -->
<use clip-path="url(#clip2)" xlink:href="#r4" fill="green" />
</svg>
</div>
<pre id="log"></pre>
```

```js
const clipPath1 = document.getElementById("clip1");
const clipPath2 = document.getElementById("clip2");

const log = document.getElementById("log");

log.textContent = `The clipPath used three times has a 'clipPathUnits' value of ${clipPath1.clipPathUnits.baseVal}
The clipPath used three times has a 'clipPathUnits' value of ${clipPath2.clipPathUnits.baseVal}`;
```

{{EmbedLiveSample("Examples", "280", "260")}}

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{SVGAttr("clipPathUnits")}}
- {{SVGElement("clipPath")}}
4 changes: 3 additions & 1 deletion files/en-us/web/api/svgclippathelement/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ The **`SVGClipPathElement`** interface provides access to the properties of {{SV
_This interface also inherits properties from its parent, {{domxref("SVGElement")}}._

- {{domxref("SVGClipPathElement.clipPathUnits")}} {{ReadOnlyInline}}
- : An {{domxref("SVGAnimatedEnumeration")}} corresponding to the {{SVGAttr("clipPathUnits")}} attribute of the given {{SVGElement("clipPath")}} element. Takes one of the constants defined in {{domxref("SVGUnitTypes")}}.
- : Returns an {{domxref("SVGAnimatedEnumeration")}} corresponding to the {{SVGAttr("clipPathUnits")}} attribute of the associated {{SVGElement("clipPath")}} element. Takes one of the constants defined in {{domxref("SVGUnitTypes")}}.
- {{domxref("SVGClipPathElement.transform")}} {{ReadOnlyInline}}
- : Returns an {{domxref("SVGAnimatedTransformList")}} corresponding to the {{SVGAttr("transform")}} attribute of the associated {{SVGElement("clipPath")}} element.

## Instance methods

Expand Down
Loading

0 comments on commit cce0046

Please sign in to comment.