1
0
Fork 0

chore(plugin-grainline): Changes for v3. See #2856

This commit is contained in:
Joost De Cock 2022-09-27 11:42:54 +02:00
parent b851e69ec8
commit 88e5339b37
2 changed files with 12 additions and 10 deletions

View file

@ -19,19 +19,18 @@ export const plugin = {
}, },
}, },
macros: { macros: {
grainline: function (so = {}) { grainline: function (so = {}, { points, paths, Path, complete, setGrain }) {
if (so === false) { if (so === false) {
delete this.points.grainlineFrom delete points.grainlineFrom
delete this.points.grainlineTo delete points.grainlineTo
delete this.paths.grainline delete paths.grainline
this.setGrain(90) // Restoring default setGrain(90) // Restoring default
return true return true
} }
so = { so = {
...dflts, ...dflts,
...so, ...so,
} }
const { points, complete, setGrain } = this.shorthand()
// setGrain relies on plugin-cutlist // setGrain relies on plugin-cutlist
if (typeof setGrain === 'function') { if (typeof setGrain === 'function') {
setGrain(so.from.angle(so.to)) setGrain(so.from.angle(so.to))
@ -39,7 +38,7 @@ export const plugin = {
if (complete) { if (complete) {
points.grainlineFrom = so.from.shiftFractionTowards(so.to, 0.05) points.grainlineFrom = so.from.shiftFractionTowards(so.to, 0.05)
points.grainlineTo = so.to.shiftFractionTowards(so.from, 0.05) points.grainlineTo = so.to.shiftFractionTowards(so.from, 0.05)
this.paths.grainline = new this.Path() paths.grainline = new Path()
.move(points.grainlineFrom) .move(points.grainlineFrom)
.line(points.grainlineTo) .line(points.grainlineTo)
.attr('class', 'note') .attr('class', 'note')

View file

@ -8,19 +8,22 @@ describe('Grainline Plugin Tests', () => {
it('Should run the default grainline macro', () => { it('Should run the default grainline macro', () => {
const part = { const part = {
name: 'test', name: 'test',
draft: ({ points, Point, macro }) => { draft: ({ points, Point, macro, part }) => {
points.from = new Point(10, 20) points.from = new Point(10, 20)
points.to = new Point(10, 230) points.to = new Point(10, 230)
macro('grainline', { macro('grainline', {
from: points.from, from: points.from,
to: points.to, to: points.to,
}) })
return part
}, },
plugins: [plugin],
} }
const Pattern = new Design({ plugins: [plugin], parts: [part] }) const Pattern = new Design({ parts: [part] })
const pattern = new Pattern() const pattern = new Pattern()
pattern.draft() pattern.draft()
const c = pattern.parts.test.paths.grainline const c = pattern.parts[0].test.paths.grainline
expect(c.attributes.get('class')).to.equal('note') expect(c.attributes.get('class')).to.equal('note')
expect(c.attributes.get('marker-start')).to.equal('url(#grainlineFrom)') expect(c.attributes.get('marker-start')).to.equal('url(#grainlineFrom)')
expect(c.attributes.get('marker-end')).to.equal('url(#grainlineTo)') expect(c.attributes.get('marker-end')).to.equal('url(#grainlineTo)')