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

piechart-3d

v3.3.1

Published

3d饼状图图表

Downloads

14

Readme

piechart-3d

基于threejs开发的3D饼状图

安装

npm install piechart-3d
# OR
yarn add piechart-3d

使用

示例

import Pie from 'piechart-3d';

const options = {
  debug: false,
  data: [16406.8, 50256, 15752, 19467.6, 112249.6, 18601.6],
  innerRadius: 0,
  outerRadius: 100,
  cornerRadius: 0,
  padAngle: 0,
  height: 20,
  activeAnimation: {
    duration: 0.25,
    heightScale: 2,
  },
  label: {
    show: true,
    position: 0.75,
    render({ percent, color }) {
      const div = document.createElement('div');
      div.innerText = Number((percent * 100).toFixed(2)) + '%';
      div.style.background = color;
      return div;
    },
  },
  autoplay: false,
  on: {
    mouseenter(e) {
      console.log('mouseenter', e);
    },
    mouseleave(e) {
      console.log('mouseleave', e);
    },
    active(e) {
      console.log('active', e);
    },
  },
};

const pie = new Pie('.chart', options);

// 销毁实例
pie.dispose();

配置项

| 属性 | 类型 | 默认值 | 描述 | | --------------- | --------------- | -------- | ---------------- | | debug | Boolean | false | 是否开启调试模式 | | data | Array | [] | 数据源 | | innerRadius | Number | 0 | 饼图内径,0-100 | | outerRadius | Number | 100 | 饼图外径,0-100 | | cornerRadius | Number | 0 | 饼图圆角,0-50 | | padAngle | Number | 0 | 饼图间隔,0-0.1 | | height | Number | 20 | 饼图高度,0-50 | | scale | Number | 1 | 饼图缩放 | | viewport | Array | [0,2,3] | 摄像机位置 | | colors | Array | *见备注 | 饼图色板 | | emptyColor | String | #aaa | 饼图空状态颜色 | | lights | Array | *见备注 | 饼图灯光 | | label | Object | *见备注 | 饼图标签 | | activeAnimation | Object | *见备注 | 饼图动效 | | autoplay | Boolean|Number | false | 自动播放 | | on | Object | *见备注 | 监听事件 |

备注

colors默认值

[
  '#3b82f6', // blue
  '#f43f5e', // rose
  '#f97316', // orange
  '#22c55e', // green
  '#eab308', // yellow
  '#06b6d4', // cyan
  '#d946ef', // fuschia
  '#8b5cf6', // violet
  '#84cc16', // lime
  '#6366f1', // indigo
  '#ec4899', // pink
  '#a855f7', // purple
  '#0ea5e9', // lightBlue
  '#14b8a6', // teal
  '#10b981', // emerald
  '#f59e0b', // amber
  '#ef4444', // red
];

lights默认值

[
  {
    type: 'AmbientLight',
    color: '#fff',
    intensity: 0.3,
  },
  {
    type: 'SpotLight',
    color: '#fff',
    intensity: 1,
    position: [5, 5, 5],
  },
];

支持AmbientLightPointLightSpotLightDirectionalLight等灯光效果,每种灯光支持配置属性有colorintensityposition

label配置

饼图标签项配置,默认值如下:

{
  show: false, // 是否显示
  position: 0.7, // 标签显示位置占比。注意,如果值为`0`,则为中心展示,此时只显示激活项标签
  render: null, // 标签渲染函数,参数同事件参数,返回值为`dom`元素
}

activeAnimation配置

默认不开启动效,如果该项配置存在,则开启动效。

{
  duration: 0.75, // 动效时长
  heightScale: 2,  // 激活块高度缩放,如默认高度的2倍
}

autoplay配置

默认值为false,不开启自动播放。该项值接受布尔值和数值,如果需要开启自动播放,可设置为true或具体数值,单位秒。如果为true,则为3s,如果为数值,则取值在1-10之间。

on配置

默认值为null,如果需要监听事件,可进行相应配置,配置示例如下:

{
  mouseenter(e) {
    console.log('mouseenter', e);
  },
  mouseleave(e) {
    console.log('mouseleave', e);
  },
  active(e) {
    console.log('active', e);
  },
}

事件参数

事件参数非原生事件参数,封装值如下:

{
  index,  // 触发项序号
  value,  // 触发项值
  percent, // 触发项占比(0-1)
  color, // 触发项色值
}

实例方法

setLegendChecked

为了实现图例的自定义,图例需自行实现,该方法提供图例与饼图的控制交互。

该方法参数为回调函数,该回调函数的参数为数据等长的数组,示例如下:

[true, true, true];

每一项对应饼图的对应块,通过布尔值可以控制对应块的显示与隐藏。该回调函数的返回值应为等长的布尔值数组。使用示例如下:

pie.setLegendChecked((legends) => {
  legends[index] = checked;
  return legends;
});

activatedeactivate

这两个方法用于触发饼图的激活和取消激活。activate方法接受一个数值参数,该数值为对应激活块的序号。deactivate方法无参数。

dispose

该方法用于销毁实例,当组件卸载的时候需手动调用。