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

google-palette

v1.1.1

Published

Script for generating colour palettes for use with graphs, charts and cartography.

Downloads

30,492

Readme

Colour Palette Generator

The palette.js script allows to generate palette colours and was intended for use with graphs, charts and cartography. In default setup, it contains Paul Tol's and ColorBrewer palettes specifically designed for that purpose. The library includes several qualitative, sequential and diverging colour schemes

Some of the included palettes have a limited number of colours, but others use a colour generation functions and can potentially create a whole spectrum of colours.

There is an interactive demo of the library if you wish to see what it can do.

Naming

The basic two concepts in palette.js library are schemes and palettes. It is important to understand what they are so as to understand the API of the library.

A palette is a sequence of colours and it is represented by an array of colours encoded as “RRGGBB” strings. Palette has a fixed size or number of colours in it. For example, the following code defines a 8-colour palette which is a sequence of base colours of the Solarized palette:

var sol_base = ['002b36', '073642', '586e75', '657b83',
                '839496', '93a1a1', 'eee8d5', 'fdf6e3'];

A scheme is a set of colour palettes and it is represented by a function with some additional properties and methods (i.e. it can be used as an object). In simplest cases, scheme will be used to generate a palette of desired size. For example, if hsv_rainbow is an HSV rainbow scheme, the following code generates a 6-colour palette based on the scheme:

var hsv6 = hsv_rainbow(6);

Library quick start

The simplest way to access the library is by calling palette function. It takes two required arguments: A name of a colour scheme and size of the palette. For example to generate a 10-colour palette one would invoke:

var seq = palette('tol-sq', 10);

tol-sq is a name for Paul Tol's sequential scheme. In addition to names of schemes the function can also take group names or a list of palette names. For example:

var seq = palette('sequential', 10);
var cbf = palette('sequential-cbf', 10);

will take the first available sequential colour scheme and generate 10-colour palette storing it in seq. The second line does the same except it limits the palettes to only those that are colour blind friendly.

The argument can also be a list of colour schemes as in:

var div = palette(['tol', 'qualitative'], 10);

Here, div will be assigned an array of colours from Paul Tol's qualitative scheme unless it is not available in which case the first available qualitative colour scheme will be used.

Another use of a list of schemes or group names is a third optional argument to the palette function -- the index for the scheme to use. When specified, not the first one, but the given scheme will be used (indexed from zero). This can be used to generate distinct colour palettes for various types of data.

var pal_for_queries = palette(['sequential'], 10, 0);
var pal_for_errors = palette(['sequential'], 10, 1);
var pal_for_latency = palette(['sequential'], 10, 2);

With the above code, three separate 10-colour palettes will be generated each for different kind of data.

If no schemes matched specified name(s), palette function will return null.

For a full reference please see the source code.

Note on colour blindness

A palette can be colour blind friendly, or CBF, meaning that colours in it are distinguishable by a colour blind person. Scheme can also be colour blind friendly (for example all Paul Tol's schemes are), but more often only some of the palettes in given scheme are (for example a 4-colour palette based on ColorBrewer Paired scheme is CBF, but bigger palettes aren't).

The demo page contains code for colour blindness simulation mode.