项目作者: omnibrain

项目描述 :
Create beautiful SVG guitar chord charts
高级语言: TypeScript
项目地址: git://github.com/omnibrain/svguitar.git
创建时间: 2019-09-15T12:08:39Z
项目社区:https://github.com/omnibrain/svguitar

开源协议:MIT License

下载


SVGuitar - JavaScript Guitar Chord Renderer

build
styled with prettier
Coveralls
semantic-release
Known Vulnerabilities
Code Style

JavaScript (TypeScript) library to create beautiful SVG guitar chord charts directly in the browser.

To see this library in action check out chordpic.com, a free online chord diagram creator.

Demo: https://omnibrain.github.io/svguitar/ [ source ]

TypeScript API Documentation: https://omnibrain.github.io/svguitar/docs/

Example chord charts:

Example Chord Chart 1
Example Chord Chart 2
Example Chord Chart 3
Example Chord Chart 4

Getting Started

  1. <!--container of the chart-->
  2. <div id="chart"></div>
  3. <!--load umd script -->
  4. <script src="https://omnibrain.github.io/svguitar/js/svguitar.umd.js"></script>
  5. <script>
  6. // initialize the chart
  7. var chart = new svguitar.SVGuitarChord('#chart')
  8. // draw the chart
  9. chart
  10. .configure({
  11. /* configuration */
  12. })
  13. .chord({
  14. /* chord */
  15. })
  16. .draw()
  17. </script>

Of course, you can also add SVGuitar as a dependency to your project:

  1. # Add the dependency to your project
  2. npm install --save svguitar
  3. # or
  4. yarn add svguitar
  5. # or
  6. pnpm add svguitar

And then import it in your project:

  1. import { SVGuitarChord } from 'svguitar'
  2. const chart = new SVGuitarChord('#chart')
  3. // draw the chart
  4. chart
  5. .configure({
  6. /* configuration */
  7. })
  8. .chord({
  9. /* chord */
  10. })
  11. .draw()

Usage

The SVG charts are highly customizable.
For a full API documentation have a look at the TypeScript documentation.

Chart configuration is completely optional, you don’t have to pass any configuration or you can
only override specific settings.

Here’s an example of a very customized chart:

  1. new SVGuitarChord('#some-selector')
  2. .chord({
  3. // array of [string, fret, text | options]
  4. fingers: [
  5. // finger at string 2, fret 2, with text '2'
  6. [2, 2, '2'],
  7. // finger at string 3, fret 3, with text '4', colored red and has class 'red'
  8. [3, 3, { text: '4', color: '#F00', className: 'red' }],
  9. // finger at string 4, fret 3, with text '3', triangle shaped
  10. [4, 3, { text: '3', shape: 'triangle' }],
  11. // an 'x' above string 6 denotes it isn't played
  12. [6, 'x'],
  13. ],
  14. // optional: barres for barre chords
  15. barres: [
  16. {
  17. fromString: 5,
  18. toString: 1,
  19. fret: 1,
  20. text: '1',
  21. color: '#0F0',
  22. textColor: '#F00',
  23. className: 'my-barre-chord',
  24. },
  25. ],
  26. // title of the chart (optional)
  27. title: 'F# minor',
  28. // position (defaults to 1)
  29. position: 9,
  30. })
  31. .configure({
  32. // Customizations (all optional, defaults shown)
  33. /**
  34. * Orientation of the chord diagram. Chose between 'vertical' or 'horizontal'
  35. */
  36. orientation: 'vertical',
  37. /**
  38. * Select between 'normal' and 'handdrawn'
  39. */
  40. style: 'normal',
  41. /**
  42. * The number of strings
  43. */
  44. strings: 6,
  45. /**
  46. * The number of frets
  47. */
  48. frets: 4,
  49. /**
  50. * Default position if no positon is provided (first fret is 1)
  51. */
  52. position: 1,
  53. /**
  54. * These are the labels under the strings. Can be any string.
  55. */
  56. tuning: ['E', 'A', 'D', 'G', 'B', 'E'],
  57. /**
  58. * The position of the fret label (eg. "3fr")
  59. */
  60. fretLabelPosition: 'right',
  61. /**
  62. * The font size of the fret label
  63. */
  64. fretLabelFontSize: 38,
  65. /**
  66. * The font size of the string labels
  67. */
  68. tuningsFontSize: 28,
  69. /**
  70. * Size of a finger or barre relative to the string spacing
  71. */
  72. fingerSize: 0.65,
  73. /**
  74. * Color of a finger or barre
  75. */
  76. fingerColor: '#000',
  77. /**
  78. * The color of text inside fingers and barres
  79. */
  80. fingerTextColor: '#FFF',
  81. /**
  82. * The size of text inside fingers and barres
  83. */
  84. fingerTextSize: 22,
  85. /**
  86. * stroke color of a finger or barre. Defaults to the finger color if not set
  87. */
  88. fingerStrokeColor: '#000000',
  89. /**
  90. * stroke width of a finger or barre
  91. */
  92. fingerStrokeWidth: 0,
  93. /**
  94. * stroke color of a barre chord. Defaults to the finger color if not set
  95. */
  96. barreChordStrokeColor: '#000000',
  97. /**
  98. * stroke width of a barre chord
  99. */
  100. barreChordStrokeWidth: 0,
  101. /**
  102. * Height of a fret, relative to the space between two strings
  103. */
  104. fretSize: 1.5,
  105. /**
  106. * The minimum side padding (from the guitar to the edge of the SVG) relative to the whole width.
  107. * This is only applied if it's larger than the letters inside of the padding (eg the starting fret)
  108. */
  109. sidePadding: 0.2,
  110. /**
  111. * The font family used for all letters and numbers
  112. */
  113. fontFamily: 'Arial, "Helvetica Neue", Helvetica, sans-serif',
  114. /**
  115. * Default title of the chart if no title is provided
  116. */
  117. title: 'F# minor',
  118. /**
  119. * Font size of the title. This is only the initial font size. If the title doesn't fit, the title
  120. * is automatically scaled so that it fits.
  121. */
  122. titleFontSize: 48,
  123. /**
  124. * Space between the title and the chart
  125. */
  126. titleBottomMargin: 0,
  127. /**
  128. * Global color of the whole chart. Can be overridden with more specifig color settings such as
  129. * @link titleColor or @link stringColor etc.
  130. */
  131. color: '#000000',
  132. /**
  133. * The background color of the chord diagram. By default the background is transparent. To set the background to transparent either set this to 'none' or undefined
  134. */
  135. backgroundColor: 'none',
  136. /**
  137. * Barre chord rectangle border radius relative to the fingerSize (eg. 1 means completely round endges, 0 means not rounded at all)
  138. */
  139. barreChordRadius: 0.25,
  140. /**
  141. * Size of the Xs and Os above empty strings relative to the space between two strings
  142. */
  143. emptyStringIndicatorSize: 0.6,
  144. /**
  145. * Global stroke width
  146. */
  147. strokeWidth: 2,
  148. /**
  149. * The width of the nut (only used if position is 1)
  150. */
  151. nutWidth: 10,
  152. /**
  153. * If this is set to `true`, the starting fret (eg. 3fr) will not be shown. If the position is 1 the
  154. * nut will have the same width as all other frets.
  155. */
  156. noPosition: false,
  157. /**
  158. * The color of the title (overrides color)
  159. */
  160. titleColor: '#000000',
  161. /**
  162. * The color of the strings (overrides color)
  163. */
  164. stringColor: '#000000',
  165. /**
  166. * The color of the fret position (overrides color)
  167. */
  168. fretLabelColor: '#000000',
  169. /**
  170. * The color of the tunings (overrides color)
  171. */
  172. tuningsColor: '#000000',
  173. /**
  174. * The color of the frets (overrides color)
  175. */
  176. fretColor: '#000000',
  177. /**
  178. * When set to true the distance between the chord diagram and the top of the SVG stayes the same,
  179. * no matter if a title is defined or not.
  180. */
  181. fixedDiagramPosition: false,
  182. /**
  183. * Text of the watermark (text on the bottom of the chart)
  184. */
  185. watermark: 'some watermark',
  186. /**
  187. * Font size of the watermark
  188. */
  189. watermarkFontSize: 12,
  190. /**
  191. * Color of the watermark (overrides color)
  192. */
  193. watermarkColor: '#000000',
  194. /**
  195. * Font-family of the watermark (overrides fontFamily)
  196. */
  197. watermarkFontFamily: 'Arial, "Helvetica Neue", Helvetica, sans-serif',
  198. /**
  199. * The title of the SVG. This is not visible in the SVG, but can be used for accessibility.
  200. */
  201. svgTitle: 'Guitar chord diagram of F# minor',
  202. /**
  203. * The fret markers. See type docs for more options.
  204. */
  205. fretMarkers: [
  206. 2, 4, 6, 8, {
  207. fret: 11,
  208. double: true,
  209. },
  210. ],
  211. /**
  212. * Flag to show or disable all fret markers globally. This is just for convenience.
  213. * The fret markers can also be removed by not setting the fretMarkers property.
  214. */
  215. showFretMarkers: true,
  216. /**
  217. * The shape of the fret markets. Applies to all fret markets unless overridden
  218. * on specific fret markers. Defaults to circles.
  219. */
  220. fretMarkerShape: 'circle',
  221. /**
  222. * The size of a fret marker. This is relative to the space between two strings, so
  223. * a value of 1 means a fret marker spans from one string to another.
  224. */
  225. fretMarkerSize: 0.4,
  226. /**
  227. * The color of the fret markers.
  228. */
  229. fretMarkerColor: 'rgba(0, 0, 0, 0.2)',
  230. /**
  231. * The stroke color of the fret markers. By default, the fret markets have no border.
  232. */
  233. fretMarkerStrokeColor: '#000000',
  234. /**
  235. * The stroke width of the fret markers. By default, the fret markets have no border.
  236. */
  237. fretMarkerStrokeWidth: 0,
  238. /**
  239. * The distance between the double fret markers, relative to the width
  240. * of the whole neck. E.g. 0.5 means the distance between the fret markers
  241. * is equivalent to 0.5 times the width of the whole neck.
  242. */
  243. doubleFretMarkerDistance: 0.4
  244. })
  245. .draw()

Contribute

Pull Requests are very welcome!

Projects using SVGuitar

Here are some projects that use svguitar:

Are you using SVGuitar? Create an issue to get your project listed here! Or simply create a pull request with your project added.