0.1.6 • Published 3 years ago

mp-awesome-progress v0.1.6

Weekly downloads
22
License
MIT
Repository
github
Last release
3 years ago

mp-awesome-progress

基于微信小程序canvas的环形进度条组件,支持npm引入方式,支持和很多自定义的属性和动画效果,效果图如下

环形进度条效果图

其他效果案例

支持进度控制

安装和使用

npm引入

安装

npm install --save mp-awesome-progress

使用

npm构建后使用

import MpAwesomeProgress from "mp-awesome-progress"

const inst = new MpAwesomeProgress({
  canvasId: "myCanvas",
  cssSize: {
    width: 104,
    height: 104,
  },
  textNodes: [
    {
      color: "#999999",
      fontSize: 10,
      textContent: "本次考试得分",
      top: 61,
    },
  ],
  onReady: () => {
    // 自主控制绘制时机
    inst.draw();
    // 模拟获取到数据后再更新分数
    setTimeout(() => {
        inst.setTextNodes([
          {
            color: "#FF683F",
            fontWeight: "bold",
            fontSize: 18,
            format: (percentage) => {
              return percentage.toFixed(2);
            },
            top: 37,
          },
          {
            color: "#999999",
            fontSize: 10,
            textContent: "本次考试得分",
            top: 61,
          },
          {
            color: "#FF683F",
            fontSize: 14,
            textContent: "不合格",
            top: 81,
          },
      ]);
      inst.setPercentage({
        value: 90,
        duration: 0.6,
      });
    }, 3000);
  },
});

支持的组件属性

参数说明类型是否必传可选值默认值
percentage百分比Numberfalse0
start-deg开始角度Numberfalse270
circle-radius圆环的半径Numberfalse40
circle-width圆环的线宽Numberfalse2
circle-color圆环的颜色Stringfalse#e5e5e5
line-width进度弧线的宽度Numberfalse8
use-gradient是否使用渐变色绘制进度弧线Booleanfalsefalse
line-color-stops进度弧线渐变色断点Arrayfalse{"percent":0,"color":"#13CDE3"},{"percent":1,"color":"#3B77E3"}
line-color进度弧线颜色Stringfalse#3B77E3
show-text是否显示环内文字Booleanfalsetrue
font-size环内字体大小Numberfalse14
font-color环内字体颜色Stringfalse#444
format文字格式化方法Functionfalse
point-radius圆点半径,值<=0则不显示圆点Numberfalse6
point-color圆点填充色Stringfalse#3B77E3
animated是否使用动画效果Booleanfalsetrue
easing贝塞尔缓动函数,默认是ease-in效果Stringfalse0.42,0,1,1
duration初始动画周期,单位为秒Numberfalse1

支持的方法

  • draw
  • setTextNodes
  • setPercentage