项目作者: svgcamp

项目描述 :
Use SVG's to generate circle,annulus,circular sector or annular sector, and return the d attribute value.
高级语言: JavaScript
项目地址: git://github.com/svgcamp/svg-arc.git
创建时间: 2020-09-12T08:44:58Z
项目社区:https://github.com/svgcamp/svg-arc

开源协议:

下载


svg-arc


Version
License


Use SVG’s <path> to generate circle, annulus, circular sector or annular sector, and return the d attribute value.

Install

  1. npm i --save svg-arc
  1. import arc from 'svg-arc';
  2. arc({x, y, R, r, start, end})

Arguments

arguments type default description
x Number 0 The x-coordinate of the center of the circle
y Number 0 The y-coordinate of the center of the circle
R Number 0 Outside Radius
r Number 0 Inside Radius
start Number - The starting angle, 0360
end Number - The ending angle, 0360

Usage

  1. import arc from 'svg-arc';
  2. // create SVG
  3. const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
  4. svg.setAttribute('viewBox', '0 0 300 300');
  5. // create path
  6. const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
  7. path.setAttribute('fill', '#ddd');
  8. svg.appendChild(path);
  9. // set path
  10. const d = arc({
  11. x: 150,
  12. y: 150,
  13. R: 100,
  14. r: 80,
  15. start: 100,
  16. end: 200,
  17. });
  18. path.setAttribute('d', d);
  19. // When drawing a annulus, the attribute value of 'fill-rule' must be set to 'evenodd', otherwise the color cannot be filled correctly.
  20. path.setAttribute('fill-rule', 'evenodd');

Circle

  1. arc({
  2. x: 150,
  3. y: 150,
  4. r: 100,
  5. })

Annulus

  1. arc({
  2. x: 150,
  3. y: 150,
  4. R: 100,
  5. r: 80,
  6. })
  7. path.setAttribute('fill-rule', 'evenodd');

When drawing a annulus, the attribute value of fill-rule must be set to evenodd, otherwise the color cannot be filled correctly.

Circular Sector

  1. arc({
  2. x: 150,
  3. y: 150,
  4. r: 100,
  5. start: 100,
  6. end: 360,
  7. })

Annular Sector

  1. arc({
  2. x: 150,
  3. y: 150,
  4. R: 100,
  5. r: 80,
  6. start: 300,
  7. end: 150,
  8. })

License

MIT

Copyright (c) 2020-present, Z8264