npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svg-fan

v0.1.0

Published

This is a tool that can draw fans, arcs, or split circles.

Downloads

2

Readme

SVG-FAN

svg-fan 是一个用于画各类弧形、扇形的javascript工具,也可以易于画出一个n等份的圆。

使用typescript编写,简单易用。

安装

npm install svg-fan

使用

DEMO 01 画一个弧形

<!-- html -->
<div  id="svg-wrapper"></div>
// ESModule import
import { Arc } from 'svg-fan'
// 如果你使用的是commonJS, 请如w使用require引入
// const { Arc } = require('svg-fan')

const arc = new Arc({
  r: 30, // 内径
  R: 50, // 外径
  start: 20, // 圆弧起始角度
  end: 280, // 圆弧结速角度
  attr: {
    // 圆弧的svg属性设置
    fill: '#FF9988',
    stroke: '#cc2211',
    strokeWidth: 4
  }
})

arc.mount(document.getElementById('svg-wrapper')) // 挂载到指定容器显示

DEMO 02 画一个圆环

// ESModule import
import { Arc } from 'svg-fan'


const arc = new Arc({
  r: 30, // 内径
  R: 50, // 外径
  start: 0, // 当起始角与结束角度之差大于360度时,将变成一个圆
  end: 360, // 圆弧结速角度
  attr: {
    fill: '#443C85'
  }
})

arc.mount(document.getElementById('svg-wrapper')) // 挂载到指定容器显示

DEMO 03 画一个扇形

// ESModule import
import { Arc } from 'svg-fan'


const arc = new Arc({
  r: 0, // 内径为0时,即画扇形
  R: 50, // 外径
  start: 0, 
  end: 90,
  attr: {
    // 圆弧的svg属性设置
    fill: '#889C85'
  }
})

arc.mount(document.getElementById('svg-wrapper')) // 挂载到指定容器显示

DEMO 04 把圆弧拉直变成梯形

// ESModule import
import { Arc } from 'svg-fan'

const arc = new Arc({
  r: 20, // 内径
  R: 50, // 外径
  start: -30,
  end: 30,
  straighten: true, // 设置straighten为true时,把弧线拉直,但起点和终点的角度差必须少于180度
  attr: {
    // 圆弧的svg属性设置
    fill: '#5faf65'
  }
})

arc.mount(document.getElementById('svg-wrapper')) // 挂载到指定容器显示

DEMO 05 在圆弧内添加文字

// ESModule import
import { Arc } from 'svg-fan'

const arc = new Arc({
  r: 40, // 内径
  R: 80, // 外径
  start: -30,
  end: 30,
  attr: {
    fill: '#8870ee'
  },
  text: '离',
  textAttr: {
    fill: '#fff',
    fontSize: 18,
    fontWeight: 600
  }
})

arc.mount(document.getElementById('svg-wrapper')) // 挂载到指定容器显示

DEMO 06 把圆等分成6份

// ESModule import
import { Fan } from 'svg-fan'

const fan = new Fan({
  r: 0, // 内径
  R: 100, // 外径
  n: 6, // 分成6份
  attr: {
    fill: '#5faf65',
    strokeWidth: 4,
    stroke: '#2f4f33'
  }
})

fan.mount(document.getElementById('svg-wrapper')) // 挂载到指定容器显示

DEMO 07 把圆等分成6份, 并设置每份弧相隔10度

// ESModule import
import { Fan } from 'svg-fan'

const fan = new Fan({
  r: 20, // 内径
  R: 100, // 外径
  n: 6, // 分成6份
  gap: 10, // 每份相隔多少角度
  attr: {
    fill: '#5faf65',
    strokeWidth: 4,
    stroke: '#2f4f33'
  }
})

fan.mount(document.getElementById('svg-wrapper')) // 挂载到指定容器显示

DEMO 08 把圆等分成4份, 每份颜色单独设置

// ESModule import
import { Fan } from 'svg-fan'

const fan = new Fan({
  r: 60, // 内径
  R: 100, // 外径
  n: 4, // 分成4份,
  attr: {
    strokeWidth: 4,
    stroke: '#2f4f33'
  },
  arcSetting: [
    {
      attr: {
        fill: '#2f6f65'
      }
    },
    {
      attr: {
        fill: '#5f8f65'
      }
    },
    {
      attr: {
        fill: '#7faf65'
      }
    },
    {
      attr: {
        fill: '#afcf65'
      }
    }
  ]
})

fan.mount(document.getElementById('svg-wrapper')) // 挂载到指定容器显示

DEMO 09 设置start值,使第一份弧的起始角度为0

// ESModule import
import { Fan } from 'svg-fan'

const fan = new Fan({
  r: 60, // 内径
  R: 100, // 外径
  n: 4, // 分成4份,
  start: 0, // 通过设置start值,可设置第一份弧的起始角度,否则第一份弧形的中心会位默认于正上方。
  attr: {
    strokeWidth: 4,
    stroke: '#2f4f33'
  },
  arcSetting: [
    {
      attr: {
        fill: '#2f6f65'
      }
    },
    {
      attr: {
        fill: '#5f8f65'
      }
    },
    {
      attr: {
        fill: '#7faf65'
      }
    },
    {
      attr: {
        fill: '#afcf65'
      }
    }
  ]
})

fan.mount(document.getElementById('svg-wrapper')) // 挂载到指定容器显示

DEMO 10 画一个八卦

// ESModule import
import { Fan } from 'svg-fan'

const fan = new Fan({
  r: 50,
  R: 100,
  n: 8,
  straighten: true,
  attr: {
    strokeWidth: 1,
    stroke: '#999',
    fill: '#fff'
  },
  arcSetting: [
    {
      text: '離',
      textAttr: {
        fill: 'red'
      },
      attr: {
        fill: '#ffeeee'
      }
    },
    {
      text: '坤'
    },
    {
      text: '兌'
    },
    {
      text: '乾'
    },
    {
      text: '坎',
      textAttr: {
        fill: 'blue'
      },
      attr: {
        fill: '#eeeeff'
      }
    },
    {
      text: '艮'
    },
    {
      text: '震'
    },
    {
      text: '巽'
    }
  ]
})

fan.mount(document.getElementById('svg-wrapper')) // 挂载到指定容器显示