2022-09-27 18:24:35 +02:00
|
|
|
---
|
|
|
|
title: Path.setText()
|
|
|
|
---
|
|
|
|
|
2022-12-07 21:03:29 -08:00
|
|
|
The `Path.setText()` method sets text on the path.
|
2022-09-27 18:24:35 +02:00
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
|
|
|
```js
|
2024-02-11 06:39:10 -08:00
|
|
|
Path path.setText(string text, string className = '')
|
2022-09-27 18:24:35 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
The second argument will optionally be used to set the CSS class for the text.
|
|
|
|
|
2024-09-28 13:13:48 +02:00
|
|
|
:::tipThis method is chainable as it returns the `Path` object:::
|
2022-09-27 18:24:35 +02:00
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
<Example caption="Example of the Path.setText() method">
|
|
|
|
```js
|
|
|
|
({ Point, points, Path, paths, part }) => {
|
|
|
|
points.from = new Point(5, 10)
|
|
|
|
points.to = new Point(95, 10)
|
|
|
|
|
|
|
|
paths.line = new Path()
|
|
|
|
.move(points.from)
|
|
|
|
.line(points.to)
|
2022-12-07 21:03:29 -08:00
|
|
|
.setText('FreeSewing rocks')
|
2022-09-27 18:24:35 +02:00
|
|
|
|
|
|
|
return part
|
|
|
|
}
|
|
|
|
```
|
|
|
|
</Example>
|
|
|
|
|
|
|
|
## Notes
|
|
|
|
|
|
|
|
The main purpose of this method is to save your some typing,
|
|
|
|
as the two following calls yield the same result:
|
|
|
|
|
|
|
|
```js
|
|
|
|
path.attr('data-text', 'Hello')
|
|
|
|
path.setText('Hello')
|
|
|
|
```
|
|
|
|
|
|
|
|
The difference with [Path.addText()](/reference/api/path/addtext) is that this
|
|
|
|
method will overwrite existing text on the path, whereas `Path.addText()` will
|
|
|
|
add to the existing text.
|