Skip to content

Commit

Permalink
feat(chord diagram): flag to hide all fret markers
Browse files Browse the repository at this point in the history
  • Loading branch information
omnibrain committed Oct 10, 2024
1 parent c4b5c0c commit 6267628
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ new SVGuitarChord('#some-selector')
},
],

/**
* Flag to show or disable all fret markers globally. This is just for convenience.
* The fret markers can also be removed by not setting the fretMarkers property.
*/
showFretMarkers: true,

/**
* The shape of the fret markets. Applies to all fret markets unless overridden
* on specific fret markers. Defaults to circles.
Expand Down Expand Up @@ -380,7 +386,7 @@ new SVGuitarChord('#some-selector')
* is equivalent to 0.5 times the width of the whole neck.
*/
doubleFretMarkerDistance: 0.4

})
.draw()
```
Expand Down
12 changes: 11 additions & 1 deletion src/svguitar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ export interface ChordSettings {
*/
fretMarkers?: FretMarker[]

/**
* Flag to show or disable all fret markers globally. This is just for convenience.
* The fret markers can also be removed by not setting the {@link fretMarkers} property.
*/
showFretMarkers?: boolean,

/**
* The {@link Shape} of the fret markets. Applies to all fret markets unless overridden
* on specific fret markers.
Expand Down Expand Up @@ -470,6 +476,7 @@ interface RequiredChordSettings {
orientation: Orientation
watermarkFontSize: number
noPosition: boolean
showFretMarkers: boolean,
fretMarkerSize: number,
fretMarkerShape: Shape,
fretMarkerColor: string,
Expand Down Expand Up @@ -508,6 +515,7 @@ const defaultSettings: RequiredChordSettings = {
fretMarkerSize: 0.4,
doubleFretMarkerDistance: 0.4,
fretMarkerShape: Shape.CIRCLE,
showFretMarkers: true,
}

export class SVGuitarChord {
Expand Down Expand Up @@ -1190,7 +1198,8 @@ export class SVGuitarChord {
)
})

this.settings.fretMarkers
if (this.settings.showFretMarkers ?? defaultSettings.showFretMarkers) {
this.settings.fretMarkers
?.forEach((fretMarker) => {
const fretMarkerOptions = (typeof fretMarker == 'number' ? {
fret: fretMarker,
Expand Down Expand Up @@ -1242,6 +1251,7 @@ export class SVGuitarChord {
)
}
});
}

return y + height
}
Expand Down
18 changes: 18 additions & 0 deletions test/svguitar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,24 @@ describe('SVGuitarChord', () => {

saveSvg('fret markers horizontal', container.outerHTML)
})
it('Should remove all fret markers', () => {
svguitar
.chord({
fingers: [
],
barres: [
],
})
.configure({
showFretMarkers: false,
fretMarkers: [
2, 4, 6,
],
})
.draw()

saveSvg('hide fret markers', container.outerHTML)
})

test.each`
setting | value | valid
Expand Down

0 comments on commit 6267628

Please sign in to comment.