2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
title: Drawing circles
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-02-19 08:04:25 +01:00
|
|
|
Real circles are rarely used in pattern design, and they are not part of the SVG path specification,
|
2021-08-25 16:09:31 +02:00
|
|
|
but rather a different SVG element.
|
|
|
|
|
2022-02-19 08:04:25 +01:00
|
|
|
Still, if you want a circle, you can draw one by setting a Point's `data-circle` attribute
|
2021-08-25 16:09:31 +02:00
|
|
|
to the radius of the circle you want to draw.
|
|
|
|
|
|
|
|
In addition, all attributes that have a `data-circle-` prefix will apply to the circle, rather than the point.
|
|
|
|
|
2022-09-21 17:41:39 +02:00
|
|
|
Practically, you will probably want to use
|
|
|
|
the [Point.addCircle()](/reference/api/point/adcircle) which does all of this for you behind the scenes:
|
|
|
|
|
|
|
|
<Example part="point_addcircle">
|
|
|
|
Examples of circles drawn on a pattern
|
2022-01-19 11:31:39 +01:00
|
|
|
</Example>
|
2022-09-21 17:41:39 +02:00
|
|
|
|
|
|
|
<Comment by="joost">
|
|
|
|
##### How multiple circles are implemented
|
|
|
|
|
|
|
|
When you add the same attribute multiple times, they are typically joined together
|
|
|
|
when rendering. For example multiple calls to add a `class` attribute will end up being
|
|
|
|
rendered as `class="class1 class2 class3` which makes a lot of sense.
|
|
|
|
|
|
|
|
But when we're placing multiple circles on the same point, that raises a bit of a problem.
|
|
|
|
For example in this code:
|
|
|
|
|
|
|
|
```js
|
|
|
|
point.a = new Point(0,0)
|
|
|
|
.addCircle(10, 'lining')
|
|
|
|
.addCircle(20, 'fabric')
|
|
|
|
```
|
|
|
|
|
|
|
|
Based on the rules of attributes, this would render a single circle with `r="10 20"
|
|
|
|
class="lining fabric"`. Which does not make a lot of sense and is invalid SVG
|
|
|
|
as `r` only takes one value.
|
|
|
|
|
|
|
|
So the render engine will do some extra work here to check that there are multiple
|
|
|
|
circles added, and will render a circle element for each, with the `r` and `class`
|
|
|
|
values of their respective calls.
|
|
|
|
|
|
|
|
While this is probably what you'd intuitively expect, it is somewhat inconsistent with how
|
|
|
|
other attributes are rendered, so I felt it was best to point it out explicitly.
|
|
|
|
|
|
|
|
</Comment>
|