Code Monkey home page Code Monkey logo

svg-arc's Introduction

svg-arc

Version License

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

Install

npm i --save svg-arc
import arc from 'svg-arc';

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

import arc from 'svg-arc';

// create SVG
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('viewBox', '0 0 300 300');

// create path
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
path.setAttribute('fill', '#ddd');
svg.appendChild(path);

// set path
const d = arc({
  x: 150,
  y: 150,
  R: 100,
  r: 80,
  start: 100,
  end: 200,
});
path.setAttribute('d', d);

// When drawing a annulus, the attribute value of 'fill-rule' must be set to 'evenodd', otherwise the color cannot be filled correctly.
path.setAttribute('fill-rule', 'evenodd');

Circle

arc({
  x: 150,
  y: 150,
  r: 100,
})

Annulus

arc({
  x: 150,
  y: 150,
  R: 100,
  r: 80,
})

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

arc({
  x: 150,
  y: 150,
  r: 100,
  start: 100,
  end: 360,
})

Annular Sector

arc({
  x: 150,
  y: 150,
  R: 100,
  r: 80,
  start: 300,
  end: 150,
})

License

MIT

Copyright (c) 2020-present, Z8264

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.