1
0
Fork 0
freesewing/markdown/dev/reference/api/pattern/sample/en.md

80 lines
2.4 KiB
Markdown
Raw Normal View History

---
title: Pattern.sample()
---
2022-02-20 14:35:50 +01:00
A pattern's `sample()` method will _sample_ the pattern which means
2021-09-25 17:05:18 +02:00
to draft it in different iterations while adjusting the input settings.
2022-02-19 08:04:25 +01:00
Under the hood, this method will call one of
2021-09-25 17:05:18 +02:00
[Pattern.sampleOption()](/reference/apu/pattern/sampleoption),
[Pattern.sampleMeasurement()](/reference/apu/pattern/sampleoption), or
[Pattern.sampleModels()](/reference/apu/pattern/sampleoption) to sample
an option, a measurement, or a set of measurements respectively.
2022-02-19 08:04:25 +01:00
Unlike those three methods where you pass the relevant info to to the method,
this `Pattern.sample()` will instead read the `pattern.settings.sample`
object to determine what to do.
The possiblities are:
- **type**: One of `option`, `measurement`, or `models`
- **option**: An option name as defined in the pattern config file (only used when `type` is option).
- **measurement**: A measurement name as defined in the pattern config file (only used when `type` is measurement).
- **models**: An array of models with the required measurements for this pattern (only used when `type` is models).
2021-09-25 17:05:18 +02:00
See the specific sample methods below for more details:
- [Pattern.sampleOption()](/reference/apu/pattern/sampleoption)
- [Pattern.sampleMeasurement()](/reference/apu/pattern/sampleoption)
- [Pattern.sampleModels()](/reference/apu/pattern/sampleoption)
2021-09-25 17:05:18 +02:00
From a lifecycle point of view, the `Pattern.sample()` method is a substitute for
`Pattern.draft()`. So you call it after instantiating the pattern, prior to
calling `Pattern.render()`.
<Tip>
###### Anchor your samples
If you add a point named `anchor` to your pattern part, the different samples
will be anchored on this point.
In other words, for each sample, the anchor point will be kept in the same location.
</Tip>
2021-09-25 17:05:18 +02:00
<Note>This method is chainable as it returns the Pattern object</Note>
<Warning>
##### FreeSewing v3 breaking changes
This method does some juggling under the hood, essentially cramming
different versions of a pattern into a single Pattern object.
This behavior is likely to change in FreeSewing v3. Refer to [the
roadmap](https://github.com/freesewing/freesewing/discussions/1278) for details.
</Warning>
## Pattern.sample() signature
```js
Pattern pattern.sample()
2022-02-19 08:04:25 +01:00
```
2021-09-25 17:05:18 +02:00
## Pattern.sample() example
```js
import Aaron from "@freesewing/aaron"
import models from "@freesewing/models"
const pattern = new Aaron({
settings: {
embed: true,
},
measurements: models.manSize38
})
const svg = pattern.sample().render()
2022-02-19 08:04:25 +01:00
```