1# Transformation
2
3Transformation attributes allow you to rotate, translate, scale, or transform a component.
4
5> **NOTE**
6>
7> The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8
9## rotate
10
11rotate(value: RotateOptions)
12
13Rotates the component.
14
15**Widget capability**: This API can be used in ArkTS widgets since API version 9.
16
17**Atomic service API**: This API can be used in atomic services since API version 11.
18
19**System capability**: SystemCapability.ArkUI.ArkUI.Full
20
21**Parameters**
22
23| Name| Type                                   | Mandatory| Description                                                        |
24| ------ | --------------------------------------- | ---- | ------------------------------------------------------------ |
25| value  | [RotateOptions](#rotateoptions) | Yes  | How the component rotates in the coordinate system (as shown below) with the upper left corner of the component as the coordinate origin. (x, y, z) specifies a vector as the axis of rotation.<br>The axis and center of rotation are set based on the coordinate system, which remains where it is when the component is moved.<br>Default value: When **x**, **y**, and **z** are not specified, their default values are **0**, **0**, and **1**, respectively. If any of **x**, **y**, and **z** is specified, the default value for the unspecified one is **0**.<br>{<br>centerX: '50%',<br>centerY: '50%'<br>centerZ: 0,<br>perspective: 0<br>}<br>Unit: vp<br>![coordinates](figures/coordinates.png)<br>Since API version 10, **CenterZ** and **perspective** are supported in ArkTS widgets.|
26
27## translate
28
29translate(value: TranslateOptions)
30
31Translates the component.
32
33**Widget capability**: This API can be used in ArkTS widgets since API version 9.
34
35**Atomic service API**: This API can be used in atomic services since API version 11.
36
37**System capability**: SystemCapability.ArkUI.ArkUI.Full
38
39**Parameters**
40
41| Name| Type                                         | Mandatory| Description                                                        |
42| ------ | --------------------------------------------- | ---- | ------------------------------------------------------------ |
43| value  | [TranslateOptions](#translateoptions) | Yes  | How the component is translated in the coordinate system (as shown below) with the upper left corner of the component as the coordinate origin. Values of **x**, **y**, and **z** indicate the translation distance along the respective axis. A positive value indicates a forward movement towards the respective axis, and a negative value indicates a backward movement towards the respective axis. The translation distance can be a number or a string (for example, **'10px'** or **'10%'**).<br>Default value:<br>{<br>x: 0,<br>y: 0,<br>z: 0<br>}<br>Unit: vp<br>![coordinates](figures/coordinates.png)<br>**NOTE**<br>When the component is translated along the z-axis, the position of the observation point remains unchanged. As such, the component appears larger when the value of **z** places it closer to the observation point and smaller when the value of **z** places it further away from the observation point.<br>![coordinateNode](figures/coordinateNote.png) |
44
45## scale
46
47scale(value: ScaleOptions)
48
49Scales the component.
50
51**Widget capability**: This API can be used in ArkTS widgets since API version 9.
52
53**Atomic service API**: This API can be used in atomic services since API version 11.
54
55**System capability**: SystemCapability.ArkUI.ArkUI.Full
56
57**Parameters**
58
59| Name| Type                                 | Mandatory| Description                                                        |
60| ------ | ------------------------------------- | ---- | ------------------------------------------------------------ |
61| value  | [ScaleOptions](#scaleoptions) | Yes  | Scale ratio along the x-, y-, and z-axis. The default value is **1**. **centerX** and **centerY** are used to set the scale center point.<br>Default value:<br>{<br>x: 1,<br>y: 1,<br>z: 1,<br>centerX:'50%',<br>centerY:'50%'<br>} |
62
63## transform
64
65transform(value: object)
66
67Sets the transformation matrix of the component.
68
69**Atomic service API**: This API can be used in atomic services since API version 11.
70
71**System capability**: SystemCapability.ArkUI.ArkUI.Full
72
73**Parameters**
74
75| Name| Type                                   | Mandatory| Description                    |
76| ------ | --------------------------------------- | ---- | ------------------------ |
77| value  | object | Yes  | Transformation matrix of the component. Only the [Matrix4Transit](../js-apis-matrix4.md) object type is supported.|
78
79## RotateOptions
80
81**Widget capability**: This API can be used in ArkTS widgets since API version 9.
82
83**Atomic service API**: This API can be used in atomic services since API version 11.
84
85| Name                     | Type                      | Mandatory| Description                                                        |
86| ------------------------- | -------------------------- | ---- | ------------------------------------------------------------ |
87| x                         | number                     | No  | X coordinate of the rotation axis vector.                                           |
88| y                         | number                     | No  | Y coordinate of the rotation axis vector.                                           |
89| z                         | number                     | No  | Z coordinate of the rotation axis vector.                                           |
90| angle                     | number \| string | Yes  | Angle to rotate. A positive angle indicates a clockwise rotation, and a negative angle indicates a counterclockwise rotation. The value can be of the string type, for example, **'90deg'**.|
91| centerX                   | number \| string | No  | X coordinate of the center point.                                         |
92| centerY                   | number \| string | No  | Y coordinate of the center point.                                         |
93| centerZ<sup>10+</sup>     | number                     | No  | Z-axis anchor, that is, the z-component of the 3D rotation center point.                          |
94| perspective<sup>10+</sup> | number                     | No  | Distance from the user to the z=0 plane.<br>The axis and center of rotation are set based on the coordinate system, which remains where it is when the component is moved.|
95
96## TranslateOptions
97
98**Widget capability**: This API can be used in ArkTS widgets since API version 9.
99
100**Atomic service API**: This API can be used in atomic services since API version 11.
101
102| Name| Type                      | Mandatory| Description           |
103| ---- | -------------------------- | ---- | --------------- |
104| x    | number \| string | No  | Translation distance along the x-axis.|
105| y    | number \| string | No  | Translation distance along the y-axis.|
106| z    | number \| string | No  | Translation distance along the z-axis.|
107
108## ScaleOptions
109
110**Widget capability**: This API can be used in ArkTS widgets since API version 9.
111
112**Atomic service API**: This API can be used in atomic services since API version 11.
113
114| Name   | Type                      | Mandatory| Description                                                        |
115| ------- | -------------------------- | ---- | ------------------------------------------------------------ |
116| x       | number                     | No  | Scale ratio along the x-axis. x > 1: The component is scaled up along the x-axis.<br>0 < x < 1: The component is scaled down along the x-axis.<br>x < 0: The component is scaled in the reverse direction of the x-axis.|
117| y       | number                     | No  | Scale ratio along the y-axis. y > 1: The component is scaled up along the y-axis.<br>0 < y < 1: The component is scaled down along the y-axis.<br>y < 0: The component is scaled in the reverse direction of the y-axis.|
118| z       | number                     | No  | Scale ratio along the z-axis. z > 1: The component is scaled up along the z-axis.<br>0 < z < 1: The component is scaled down along the z-axis.<br>z < 0: The component is scaled in the reverse direction of the z-axis.|
119| centerX | number \| string | No  | X coordinate of the center point.                                         |
120| centerY | number \| string | No  | Y coordinate of the center point.                                         |
121
122> **NOTE**
123>
124> If the **rotate** and **scale** attributes are both set for a component, the values of **centerX** and **centerY** conflict. In this case, the one that is set later in time prevails.
125
126## Example
127
128```ts
129// xxx.ets
130import { matrix4 } from '@kit.ArkUI';
131
132@Entry
133@Component
134struct TransformExample {
135  build() {
136    Column() {
137      Text('rotate').width('90%').fontColor(0xCCCCCC).padding(15).fontSize(14)
138      Row()
139        .rotate({
140          x: 0,
141          y: 0,
142          z: 1,
143          centerX: '50%',
144          centerY: '50%',
145          angle: 300
146        }) // The component rotates around the center point of the rotation axis (0,0,1) clockwise by 300 degrees.
147        .width(100).height(100).backgroundColor(0xAFEEEE)
148
149      Text('translate').width('90%').fontColor(0xCCCCCC).padding(10).fontSize(14)
150      Row()
151        .translate({ x: 100, y: 10 }) // The component translates by 100 along the x-axis and by 10 along the y-axis.
152        .width(100).height(100).backgroundColor(0xAFEEEE).margin({ bottom: 10 })
153
154      Text('scale').width('90%').fontColor(0xCCCCCC).padding(15).fontSize(14)
155      Row()
156        .scale({ x: 2, y: 0.5}) // The height and width are doubled. The z-axis has no effect in 2D mode.
157        .width(100).height(100).backgroundColor(0xAFEEEE)
158
159      Text('Matrix4').width('90%').fontColor(0xCCCCCC).padding(15).fontSize(14)
160      Row()
161        .width(100).height(100).backgroundColor(0xAFEEEE)
162        .transform(matrix4.identity().translate({ x: 50, y: 50 }).scale({ x: 1.5, y: 1 }).rotate({
163          x: 0,
164          y: 0,
165          z: 1,
166          angle: 60
167        }))
168    }.width('100%').margin({ top: 5 })
169  }
170}
171```
172
173![transform](figures/transform.PNG)
174