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

leaderlines

v0.0.1

Published

Find nice positions for leader lines with two right angles

Downloads

6

Readme

leaderlines

Find nice positions for leader lines with two right angles

Given the start and end y-coordinates of leader lines, this module calculates the positions of all the points on the lines, to give a result similar to the grey leader lines on Our World in Data's charts.

Install

$ npm install leaderlines

Usage

import leaderlines from 'leaderlines';

const data = [
    {y1: 10, y2: 3},
    {y1: 15, y2: 5},
    {y1: 20, y2: 20},
    {y1: 25, y2: 28},
    {y1: 26, y2: 35},
    {y1: 50, y2: 52}
];
const config = {xRange: [10, 30], middleX2: 24, targetGap: 3, maxSumOfGaps: 7};
leaderlines(data, config, d => d.y1, d => d.y2);

API

leaderlines(data, config, y1Fn, y2Fn)

data

Type: array

An array of objects, one per label.

config

Type: object

Members:

  • xRange: a two-element array with the min and max x values for leader lines
  • middleX2: the average x value for the vertical section of leader lines
  • targetGap: the target x-distance between vertical sections of successive leader lines
  • maxSumOfGaps: the maximum sum of these x-distances for a run of leader lines

y1Fn

Type: function

A function that takes an element of data and returns the first y value (the y position of rightmost point of a line on the line chart)

y2Fn

Type: function

A function that takes an element of data and returns the first y value (the y position of a label)

Return value

An array of objects, one for each leader line. Each object has members x1, x2, x3, y1, and y2.

Each leader line should be drawn with three line segments:

  • (x1, y1) to (x2, y1)
  • (x2, y1) to (x2, y2)
  • (x2, y2) to (x3, y2)