1
0
Fork 0

chore(docs): Add Stack documentation

This commit is contained in:
Benjamin F 2023-05-07 08:37:03 -07:00 committed by Benjamin Fan
parent 09d1a17cf1
commit 96ced472e4
10 changed files with 182 additions and 0 deletions

View file

@ -76,6 +76,7 @@ It just so happens that in most cases, there will be only one settings object in
- `Pattern.parts`: Holds the parts used in the pattern - `Pattern.parts`: Holds the parts used in the pattern
- `Pattern.plugins`: Holds the plugins used in the pattern - `Pattern.plugins`: Holds the plugins used in the pattern
- `Pattern.settings`: Holds the settings used for the pattern - `Pattern.settings`: Holds the settings used for the pattern
- `Pattern.stacks`: Holds the stacks used in the pattern
- `Pattern.store`: Holds the pattern-wide Store - `Pattern.store`: Holds the pattern-wide Store
- `Pattern.setStores`: Holds an array of stores, one for each set of settings. - `Pattern.setStores`: Holds an array of stores, one for each set of settings.

View file

@ -0,0 +1,14 @@
---
title: Stack.addPart()
---
The `Stack.addPart()` method adds a part to the stack and returns the
original stack.
## Stack.addPart() signature
```js
Stack stack.addPart(Part part)
```
<Note>This method is chainable as it returns the Stack object</Note>

View file

@ -0,0 +1,12 @@
---
title: Stack.asProps()
---
The `Stack.asProps()` method returns a stack object suitable for renderprops.
## Stack.asProps() signature
```js
Object stack.asProps()
```

View file

@ -0,0 +1,23 @@
---
title: Stack.attr()
---
The `Stack.attr()` method adds an attribute to the stack
and returns the original stack.
Setting the third parameter to `true` will replace the value of the
attribute instead of adding it.
## Stack.attr() signature
```js
Stack stack.attr(
string name,
mixed value,
bool overwrite = false
```
If the third parameter is set to `true` it will call
`this.attributes.set()` instead,
thereby overwriting the value of the attribute.
<Note>This method is chainable as it returns the Stack object</Note>

View file

@ -0,0 +1,52 @@
---
title: Stack
---
A Stack object represents a layer within a pattern, holding one or
more parts..
<Related>
See [Stacks](/guides/patterns/stacks)
for information about how stacks are used in a pattern
</Related>
## Signature
```js
Stack new Stack(String name)
```
The stack constructor takes a single argument, a String containing the name
of the stack.
## Properties
Stack objects come with the following properties:
- `attributes` : An [Attributes](/reference/api/attributes) instance holding the point's attributes
- `parts` : A set of parts in the stack
- `name` : The name of the stack
- `topleft` : A [Point](/reference/api/point) that is the top left of the stack's bounding box
- `bottomRight` : A [Point](/reference/api/point) that is the bottom right of the stack's bounding box
- `width` : The width of the stack in mm
- `height` : The height of the stack in mm
- `anchor` : A [Point](/reference/api/point) that is used as the anchor to align parts in the stack
## Example
<Example caption="Example of the Stack constructor">
```js
import { Stack } from '@freesewing/core'
const myStack = new Stack('mystack')
```
</Example>
## Methods
A Stack object exposes the following methods:
<ReadMore list />

View file

@ -0,0 +1,26 @@
---
title: Stack.generateTransform()
---
The `Stack.generateTransform()` method generates transforms for the stack,
sets them as attributes, and returns the original stack.
## Stack.generateTransform() signature
```js
Stack stack.generateTransforms(Object transforms)
```
The `Stack.generateTransforms()` method takes a single argument,
an object with the following properties containing the transforms
to apply:
| Property | Type |Description |
|----------|------|------------|
| `move` | Object | `move.x` and `move.y` are coordinates to which the stack should be translated
| `rotate` | Number | The number of degrees to rate the stack around its center |
| `flipX` | Boolean | Whether to flip the stack along the X axis |
| `flipY` | Boolean | Whether to flip the stack along the Y axis |
<Note>This method is chainable as it returns the Stack object</Note>

View file

@ -0,0 +1,13 @@
---
title: Stack.getAnchor()
---
The `Stack.getAnchor()` method returns the Point which is the anchor
to align parts in the stack.
## Stack.getAnchor() signature
```js
Point stack.getAnchor()
```

View file

@ -0,0 +1,12 @@
---
title: Stack.getPartList()
---
The `Stack.getPartList()` method returns an Array containing the parts
in this stack.
## Stack.getPartList() signature
```js
Part[] stack.getPartList()
```

View file

@ -0,0 +1,12 @@
---
title: Stack.getPartNames()
---
The `Stack.getPartNames()` method returns an Array containing the names
of the parts in the stack.
## Stack.getPartNames() signature
```js
String[] stack.getPartNames()
```

View file

@ -0,0 +1,17 @@
---
title: Stack.home()
---
The `Stack.home()` method calculates the stack's bounding box, sets it,
and returns the original stack.
## Stack.home() signature
```js
Stack stack.home()
```
<Note>This method is chainable as it returns the Stack object</Note>
## Notes
The bounding box is calculated taking into consideration the `margin` setting.