diff --git a/.gitignore b/.gitignore index bd9a3e6..2970d80 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ compiled .rpt2_cache docs +# IDE +*.iml diff --git a/code-of-conduct.md b/code-of-conduct.md deleted file mode 100644 index 4a9568b..0000000 --- a/code-of-conduct.md +++ /dev/null @@ -1,74 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -nationality, personal appearance, race, religion, or sexual identity and -orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment -include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or -advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at alexjovermorales@gmail.com. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [http://contributor-covenant.org/version/1/4][version] - -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ diff --git a/src/svguitar.ts b/src/svguitar.ts index 6fb0cef..5a0d4b6 100644 --- a/src/svguitar.ts +++ b/src/svguitar.ts @@ -77,6 +77,11 @@ export interface ChordSettings { tuningsColor?: string fretColor?: string + /** + * Barre chord rectangle border radius relative to the nutSize (eg. 1 means completely round endges, 0 means not rounded at all) + */ + barreChordRadius: number + /** * Size of the Xs and Os above empty strings relative to the space between two strings */ @@ -106,7 +111,8 @@ const defaultChordSettings: ChordSettings = { emptyStringIndicatorSize: 0.6, strokeWidth: 2, topFretWidth: 10, - fretSize: 1.5 + fretSize: 1.5, + barreChordRadius: 0.25 } interface ChartConstants { @@ -168,7 +174,7 @@ export class SVGuitarChord { return this } - draw() { + draw(): { width: number; height: number } { this.clear() this.drawTopEdges() @@ -185,6 +191,11 @@ export class SVGuitarChord { y = y + this.fretSpacing() / 10 this.svg.viewbox(0, 0, constants.width, y) + + return { + width: constants.width, + height: y + } } private drawTunings(y: number) { @@ -373,6 +384,9 @@ export class SVGuitarChord { const startX = stringXPositions[0] const endX = stringXPositions[stringXPositions.length - 1] + const nutSize = this.settings.nutSize * stringSpacing + const nutColor = this.settings.nutColor || this.settings.color + // draw frets fretYPositions.forEach(fretY => { this.svg.line(startX, fretY, endX, fretY).stroke({ @@ -390,8 +404,6 @@ export class SVGuitarChord { }) // draw fingers - const nutSize = this.settings.nutSize * stringSpacing - const nutColor = this.settings.nutColor || this.settings.color this._chord.fingers .filter(([_, value]) => value !== SILENT && value !== OPEN) .map(([stringIndex, fretIndex]) => [this.toArrayIndex(stringIndex), fretIndex as number]) @@ -405,6 +417,18 @@ export class SVGuitarChord { .fill(nutColor) }) + // draw barre chords + this._chord.barres.forEach(({ fret, fromString, toString }) => { + this.svg + .rect(Math.abs(toString - fromString) * stringSpacing + stringSpacing / 2, nutSize) + .move( + stringXPositions[this.toArrayIndex(fromString)] - stringSpacing / 4, + fretYPositions[fret - 1] - fretSpacing + nutSize / 2 + ) + .fill(nutColor) + .radius(nutSize * this.settings.barreChordRadius) + }) + return y + height } diff --git a/svguitar.iml b/svguitar.iml index 8021953..51f25e0 100644 --- a/svguitar.iml +++ b/svguitar.iml @@ -1,5 +1,5 @@ - + diff --git a/test/svguitar.test.ts b/test/svguitar.test.ts index f2340d2..a22f70b 100644 --- a/test/svguitar.test.ts +++ b/test/svguitar.test.ts @@ -128,6 +128,32 @@ describe('SVGuitarChord', () => { saveSvg('too many tunings', container.outerHTML) }) + it('Should render barre chords', () => { + svguitar + .configure({ + strings: 5, + frets: 5 + }) + .chord({ + fingers: [], + barres: [ + { + fret: 1, + fromString: 4, + toString: 1 + }, + { + fret: 3, + fromString: 5, + toString: 2 + } + ] + }) + .draw() + + saveSvg('barre chords', container.outerHTML) + }) + it('Should render everything in red', () => { svguitar .configure({