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 🙏

© 2025 – Pkg Stats / Ryan Hefner

canvas-credit-score

v1.2.4

Published

Canvas实现类似支付宝的信用评分

Readme

Canvas-credit-score

面向现代主流浏览器实现的 Canvas 绘制的一个类似支付宝信用分的组件

  • 支持高清绘制(走像素比,然后缩放)
  • 文字等分的传入
  • 虚线等分的传入
  • 线条大小,颜色
  • 文字的色彩及大小

默认分数段是 450-850,角度 42 等分,文字 5 等分。。。

没那么严谨的各种判断,只是为了满足业务需求写的,有兴趣完善的可以提交 PR

安装

// yarn add canvas-credit-score
npm install --save canvas-credit-score

用法

// 引入
import CreditScore from 'canvas-credit-score';

// 初始化
let cs = new CreditScore(el: '',{/*options*/});

cs.drawBaseMap(); // 执行绘制

// 也可以调用init函数来设置配置,再执行绘制
let cs2 = new CreditScore(el);
cs2.init(configObject);
cs2.drawBaseMap(); // 执行绘制

选项

  • 参数(直接拿typescript的描述了哈)
interface defaultParams {
  x: number; // 圆心的x坐标
  y: number; // 圆心的y坐标
  startAngle: number; // 开始的角度
  endAngle: number; // 结束的角度
  currentAngle: number; // 当前的角度
  scoreStart: number; // 起步分
  scoreTarget: number; // 目标分
  scoreMin: number; // 最低分
  scoreMax: number; // 最高分
  scoreEvaDate: string; // 评估日期
  segAngle: number; // 总角度分成几等分
  outerTextSeg: number; // 外围文本分成几份
  style: styleParams; // 样式
}

interface styleParams {
  line?: {
    initColor?: string, // 初始化颜色
    activeColor?: string, // 高亮的颜色
    width?: number // 线条的粗细
  };
  dashLine?: {
    initColor?: string, // 初始化颜色
    activeColor?: string, // 高亮的颜色
    width?: number // 线条的粗细
  };
  outerText?: {
    // 外环文本
    fontSize?: number,
    color?: string
  };
  innerText?: {
    score?: {
      fontSize?: number,
      color?: string
    },
    level?: {
      fontSize?: number,
      color?: string
    },
    date?: {
      fontSize?: number,
      color?: string,
      fontWeight?: string
    }
  };
}
  • 方法
  • instance.drawBaseMap() - 读取配置后绘制图形
  • instance.init() - 配置参数,可选。也可以在构造函数传入
  • instance.refresh(delay,callback) - 延迟多少秒后再次渲染,支持回调函数的传入

License

The MIT License (MIT). Please see License File for more information.