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

word-cloud-js

v1.0.5

Published

<img src="./demo.gif" style="width: 500px">

Downloads

8

Readme

词云图

File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | ---------------|----------|----------|----------|----------|-------------------| All files | 62.69 | 60 | 52.63 | 61.02 | | src | 40.48 | 40 | 25 | 41.03 | | WordChart.ts | 40.48 | 40 | 25 | 41.03 |... 63,66,67,69,71 | src/helper | 100 | 100 | 100 | 100 | | constant.ts | 100 | 100 | 100 | 100 | | utils.ts | 100 | 100 | 100 | 100 | |

简介

优点:

相比目前大众开源的词图, 增加了更多的配置, 且支持自定义dom渲染和自定义tooltop和节点之间的间隔等,会按照真实渲染后的css属性去做碰撞检测, 支持颜色多种模式配置,按值的范围或数组索引配置, 不会遗漏数据,哪怕数据的占比很小或者相同占比却没有空间渲染的情况, 支持海量大数据的业务下渲染, 节点数超过一定数量会开启异步渲染,不会阻塞浏览器其他任务,仅在空闲的时间执行,目前其他词图库会默认选择遗漏,支持滚动假3d模式, 可配置斜率

缺点:

目前暂不支持在词内渲染,未基于目前流行库canvas碰撞检测的做法,相比带来的好处就是更小的内存消耗,优化后的空间的利用率可能会没有基于canvas高

纯ts开发,无任何第三方依赖

基于函数式编程

扩展性强,可自定义追加动画和其他数据

TS构建,丰富的测试用例

API

数据格式

默认配置:

import { MODE, ORIENTATION, init } from 'word-cloud-js'
const defaultOptions = {
  mode: MODE.SCROLL, // 模式 , 滚动 | 普通
  orientation: TEXT_ORIENTATION.RANDOM, // 方向
  animate: true, // 是否开启普通模式的动画
  colors: ["#ff9ecc", "#00b6ff", "#f3bd00", "#884dff", "#d3f0ff ", "#5cc4ee", "#eadf2b", "#e1583e", "#05e1b5", "#3e61e1", "#884dff", "#c59eff", "#06b8d1"],
  sizeRange: [12, 24], // 文字大小
  gridSize: 5, //字符间隔 (不包含padding)
  borderColor: "rgba(105,207,255)", // 单项的css配置
  borderWidth: 0,
  backgroundColor: "rgba(16,22,24,0)",
  padding: [1, 1], // 单项的padding属性
  events: { // 自定义事件
    click: (item: MappingDataItem, instance: WordChartBase) => {
      console.log(item, '----')
    }
  },
  tooltip: {
    show: true,
    // render(item: MappingDataItem, el: HTMLElement) { // tooltip 渲染函数, 返回DOMString | HTMLElement
    //   return `<span style="color: red">${item.name}</span>`
    // },
    padding: [15, 35],
    backgroundColor: 'rgba(50,50,50,0.7)',
    borderRadius: 0,
    textStyle: { // tooltip文字样式
      color: '#fff',
      fontFamily: 'Microsoft YaHei',
      fontSize: 14,
      lineHeight: 30
    },
    bgStyle: {
      width: 0,
      height: 0,
      url: "/static/vis_resource/background/bg-tooltip.png"
    },
  }
}

const config = {
  el: document.querySelector('#app') as HTMLElement || document.body,
  data: temp,
  config: defaultOptions,
  hooks: { // 函数扩展, 适用于自增加的其他业务, 如增加其他动画, 渲染每一项之前执行自己的钩子...
    // scan: (_: ScanParams) => { // 扫描钩子, 比系统级函数会先执行
    //   console.log(_)
    //   return _
    // },
    // effect: (_: MappingDataItem) => { // 异步函数, 每一项渲染完成后会调用一次
    //   console.log(_, '-effect')
    // },
    finally: (_: WordChartBase) => { // 所有任务执行完成后执行一次
      console.log(_, '---')
    }
  }
}

todos

  • 完善文档
  • 增加测试用例
  • 增加配置和api
  • 尝试使用canvas位运算和时间分片机制接入, 适配海量数据模式实现流畅渲染
  • 基于该库开发vue, react对应的组件