@chordproject/diagrammer 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # Chord Diagrammer
2
+
3
+ A TypeScript library to generate SVG chord diagrams.
4
+
5
+ Inspired by: https://github.com/tombatossals/react-chords.
6
+
7
+ Part of [ChordProject](https://chordproject.com/)
8
+
9
+ ## Requirements
10
+
11
+ - Node.js 20.19.0 or newer.
12
+ ## Overview
13
+
14
+ Generates SVG chord diagrams according to received specifications.
15
+
16
+ ![Diagrams](./diagrammer.png)
17
+
18
+ ## Usage
19
+
20
+ `Chord Diagrammer` is on npm. To install run:
21
+
22
+ ```sh
23
+ $ npm i @chordproject/diagrammer
24
+ ```
25
+
26
+ It's really easy to draw an SVG chord diagram:
27
+
28
+ ```ts
29
+ import { ChordDiagram, Instrument, SvgBuilder } from '@chordproject/diagrammer';
30
+
31
+ // chord diagram definitions
32
+ const chordDiagram = new ChordDiagram({
33
+ frets: [-1, 0, 2, 2, 1, 0],
34
+ fingers: [0, 0, 2, 3, 1, 0],
35
+ baseFret: 1,
36
+ });
37
+
38
+ // instrument definitions
39
+ const instrument = new Instrument('Guitar', 6, 4, ['E', 'A', 'D', 'G', 'B', 'E']);
40
+
41
+ const generator = new SvgBuilder();
42
+ const svg = generator.build(chordDiagram, instrument);
43
+ document.body.appendChild(svg); // add the svg in the html content (here the body)
44
+ ```
45
+
46
+ ## Diagram collections
47
+
48
+ `ChordDiagramCollection` resolves chord definitions supplied by the host application. The
49
+ diagrammer does not fetch or own a database; pass a static dataset or another local source:
50
+
51
+ ```ts
52
+ import { Chord, ChordDiagramCollection } from '@chordproject/diagrammer';
53
+
54
+ const collection = new ChordDiagramCollection([
55
+ {
56
+ key: 'C',
57
+ type: 'major',
58
+ bass: '',
59
+ frets: [-1, 3, 2, 0, 1, 0],
60
+ fingers: [0, 3, 2, 0, 1, 0],
61
+ variation: 1,
62
+ },
63
+ ]);
64
+
65
+ const diagrams = collection.get(new Chord('C', 'M', ''));
66
+ ```
67
+
68
+ The collection normalizes common enharmonic and quality aliases, returns variations ordered by
69
+ their `variation` number, and converts definitions into the library's `ChordDiagram` model.
70
+
71
+ The repository includes a compact guitar dataset with the most accessible position first and
72
+ additional playable variations after it. It is generated from
73
+ [`tombatossals/chords-db`](https://github.com/tombatossals/chords-db), licensed under MIT; its
74
+ license is included at `data/CHORDS_DB_LICENSE`. Project-specific voicings live in
75
+ `data/supplemental-guitar.json`, so they survive upstream updates.
76
+
77
+ To download the current upstream guitar database, regenerate the dataset, and validate collection
78
+ and song coverage, run:
79
+
80
+ ```sh
81
+ npm run update:guitar-data
82
+ ```
83
+
84
+ The generated `data/guitar.json` is the only guitar data published with this package. The source
85
+ database is never bundled into the client application.
86
+
87
+ The collection returns no diagram when the source dataset has no explicit voicing for a chord
88
+ variant. The consumer can then choose whether to hide the diagram or fall back to the base chord;
89
+ the library does not invent a voicing for an uncovered slash chord.
90
+
91
+ ## Song coverage analysis
92
+
93
+ Coverage of application song backups belongs to the consuming client, not this library. In
94
+ `chordproject-client`, run `npm run analyze:song-coverage` to compare a local Firestore backup
95
+ against this package's published `data/guitar.json`.
96
+
97
+ A ChordDiagram is defined by:
98
+
99
+ - **frets** (array of numbers). Use 0 for open strings and -1 for muted strings. Frets must be relative to the base-fret.
100
+ - **fingers** (array of numbers). Use 0 for no finger. The fingers array length must match the frets array length. The fingers are optional
101
+ - **base-fret** (number)
102
+
103
+ ## Customization
104
+ You can customize the diagram by changing the default settings.
105
+
106
+ For example:
107
+ ```ts
108
+ builder.settings.dot.radius = 5; // change the dot radius
109
+ builder.settings.neck.lineWidth = 0.8; //change the line width of the neck
110
+ ```
111
+ Here is all the available settings:
112
+ - stringSpace
113
+ - fretSpace
114
+ - fontFamily
115
+ - fingering:
116
+ - color
117
+ - margin
118
+ - size
119
+ - visible
120
+ - dot:
121
+ - radius
122
+ - borderWith
123
+ - fillColor
124
+ - strokeColor
125
+ - openStringRadius
126
+ - neck
127
+ - useRoman
128
+ - color
129
+ - nut:
130
+ - color
131
+ - visible
132
+ - width
133
+ - stringName:
134
+ - color
135
+ - size
136
+ - margin
137
+ - visible
138
+ - grid:
139
+ - color
140
+ - width
141
+ - visible
142
+ - baseFret:
143
+ - color
144
+ - size
145
+ - margin
146
+ - visible
147
+ - stringInfo:
148
+ - color
149
+ - size
150
+ - margin
151
+ - visible
152
+ ## Demo
153
+
154
+ 1. Clone
155
+ 2. Install dependencies:
156
+
157
+ ```sh
158
+ $ npm i
159
+ ```
160
+
161
+ 1. Run in dev mode:
162
+
163
+ ```sh
164
+ $ npm run dev
165
+ ```
166
+
167
+ Open a browser and navigate to http://localhost:8082/ to load the demo.
168
+
169
+ ## Contributing
170
+
171
+ This project welcomes contributions of all types. If you find any bug or want some new features, please feel free to create an issue or submit a pull request.
172
+
173
+ Join the community and chat with us on **[Discord](https://discord.gg/ZQAgwBC9c8)**
174
+
175
+ ## License
176
+ [GNU Affero General Public License v3.0](LICENSE)
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 David Rubert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.