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

54 lines
1.8 KiB
Markdown
Raw Normal View History

---
title: Pattern.sample()
---
2022-09-20 18:09:28 +02:00
The `Pattern.sample()` method will _sample_ the pattern which means
to draft multiple variants of the same pattern, and stack them on
top of each other.
<Note>This method is chainable as it returns the Pattern object</Note>
2022-02-19 08:04:25 +01:00
Under the hood, this method will call one of
[Pattern.sampleOption()](/reference/api/pattern/sampleoption),
[Pattern.sampleMeasurement()](/reference/api/pattern/samplemeasurement), or
[Pattern.sampleModels()](/reference/api/pattern/samplemodels) to sample
2022-09-20 18:09:28 +02:00
an option, a measurement, or different models respectively.
2022-02-19 08:04:25 +01:00
Unlike those three methods where you pass the relevant info to to the method,
2022-09-20 18:09:28 +02:00
this `Pattern.sample()` method will instead read the `settings.sample`
object to determine what needs to be done.
2022-09-20 18:09:28 +02:00
The `settings.sample` object can hold the following properties:
- **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).
2022-09-20 18:09:28 +02:00
- **models**: A plain object of different models where the key is the model name and the value an object with the required measurements.
2021-09-25 17:05:18 +02:00
See the specific sample methods below for more details:
- [Pattern.sampleOption()](/reference/api/pattern/sampleoption)
- [Pattern.sampleMeasurement()](/reference/api/pattern/samplemeasurement)
- [Pattern.sampleModels()](/reference/api/pattern/samplemodels)
2021-09-25 17:05:18 +02:00
## 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
2022-09-20 18:09:28 +02:00
import { Aaron } from "@freesewing/aaron"
import { cisFemaleAdult } from "@freesewing/models"
2021-09-25 17:05:18 +02:00
const pattern = new Aaron({
2022-09-20 18:09:28 +02:00
sample: {
models: cisFemaleAdult
}
2021-09-25 17:05:18 +02:00
})
const svg = pattern.sample().render()
2022-02-19 08:04:25 +01:00
```