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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ryancui-/ranking-bar

v0.0.2

Published

Ranking Bar Visualization based on d3.js

Readme

Ranking Bar

简体中文

Use it the same as ECharts.

This project is based on https://github.com/Jannchie/Historical-ranking-data-visualization-based-on-d3.js, thanks for your ideas.

Though, this project has many different configuration than the original due to my requirement, perhaps not suitable for your case, please refer to Options chapter for more information.

Install

npm install -S @ryancui-/ranking-bar

ATTENTION, you need to ensure the global variable d3 is avaliable(v5).

Usage

First, You need a <svg> element with specific height and width. Besides, viewBox is not required.

<svg id="chart" width="600" height="350"></svg>

Then, initialize like ECharts:

import { RankingBar } from '@ryancui-/ranking-bar'

const dom = document.getElementById('chart')
const options = { /*...*/ }

const instance = new RankingBar(dom)

instance.render(options)

instance.play()

Options

const options = {
  // Render data, see dataset chapter
  data: [],
  // Image data above the bar, see dataset chapter  
  imgMapping: [],
  // Color palette,support single color, linear gradient(0%-100%)
  color: ['#00bcbe', ['#00bcbe', 'rgba(0, 188, 190, 0.2)']],
  // Animation duration(ms) for each time tick
  duration: 1000,
  // Default time tick, start means at the beginning of the time, end means at the end
  init: 'start',
  // Max bar number(same as TopN)
  rankingCount: 20,
  // Grid distances to four directions
  grid: {
    top: 0,
    left: 0,
    right: 0,
    bottom: 0
  },
  // Tooltip
  tooltip: {
    show: true,
    formatter: (d3, dataItem) => `${dataItem.name} - ${dataItem.value}`
  },
  // X axis
  xAxis: {
    show: true,
    fontSize: 12,
    fontColor: '#999',
    fontWeight: 'normal',
    tickColor: '#F0F0F0',   // Tick line color
    tickType: 'solid',      // Tick line type: solid / dashed
    tickFormatter: (d3, value) => d3.format('~s')(value).toUpperCase()
  },
  // Time(event) tick label in right-bottom corner
  eventLabel: {
    show: false,
    fontSize: 28,
    fontColor: '#2b2b2b',
    fontWeight: 'normal',
    formatter: (d3, datum) => datum.date
  },
  // Bar options  
  bar: {
    height: 'auto',   // Bar height, auto means self-adjusted, or provide a fixed pixel number
    round: 0          // Bar border radius
  },
  // Bar label(same as y axis)
  barLabel: {
    show: true,
    fontSize: 12,
    fontColor: '=',   // = means follow the bar serie color, or provide specific one
    fontWeight: 'normal',
    formatter: (d3, datum) => datum.name
  },
  // Bar info text(above the bar)
  barInfo: {
    show: true,
    fontSize: 12,
    fontColor: '#fff',
    fontWeight: 'normal',
    formatter: (d3, datum) => `${datum.name} - ${datum.type}`
  },
  // Bar value(after the bar)
  barValue: {
    show: true,
    fontSize: 12,
    fontColor: '=',   // = means follow the bar serie color, or provide specific one
    fontWeight: 'normal',
    prefix: '',       // prefix the value
    postfix: ''       // postfix the value
  },
  // Bar image(above the bar)
  barImage: {
    show: false,
    borderColor: 'transparent',
    borderWidth: 0,
    shadowOffsetX: 0,
    shadowOffsetY: 0,
    shadowBlur: 0,
    shadowColor: 'transparent'
  }
}

Dataset

options.data:

interface Serie {
  date: string;
  name: string;
  type: string;
  value: string | number;
}

const data: Serie[] = [{
  date: '2019-01-01',    // Time tick, string
  name: 'China',         // Serie, for different bar
  type: 'Asia',          // Type, for different color
  value: 19384           // Value
}, {
  date: '2019-01-01',
  name: 'Korea',
  type: 'Asia',
  value: 8475
}, /*...*/]

options.imgMapping:

interface ImgMapping {
  name: string;
  img: string;
}

const imgMapping: ImgMapping[] = [{
  name: 'China',                    // Serie
  img: 'http://path/to/your/image'  // Image url
}, /*...*/]

Methods

// Render the chart
instance.render(options)

// Start the animation from the beginning
instance.play()

Events

Use on/off to add/remove event listeners.

instance.on('click', (params) => {})

instance.off('click')

click

Fired when click the bar.

instance.on('click', ({ datum: Serie }) => {
  console.log(datum)  // datum is the object in options.data  
})

eventTick

Fired when a new time(event) tick starts, you can use this to synchronize the outside status.

instance.on('eventTick', ({ date: string }) => {
  console.log(date)  // Current time tick  
})

stop

Fired when animation finishs.

instance.on('stop', () => {
    
})