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

@nqminds/colours

v0.2.10

Published

Colour utilities and functions for NQM projects

Downloads

8

Readme

Colours

Version Badge Minzipped Size Badge

The colours module defines functions for creating consistent colour spaces across projects.

Colour cycles

Tools for creating uniform, or perceptually different colour for plot lines and charts. Functionality may need to be added to ensure colour contrast is preserved. i.e. a dark mode and light mode so that the mapping doesn't give a colour like light-yellow when the colours will be plotted on a white background.

Palette map

A class for keeping a consistent and distinct colour mappings between keys.

import { PaletteMap } from "@nqminds/colours";
const paletteMap = new PaletteMap(keys, options);

Parameters

  • keys: array of strings

  • options: object

    • format: string. One of hex, rgb, cmyk, hsl.
      • default = hex
    • exclusions: array of colours to exclude. e.g. ["red", "green"].
      • default = []

getColour()

const paletteMap = new PaletteMap(dataKeys, { format: "rgb" });
const colour = paletteMap.getColour("key");

get-palette

A function which returns an array of n distinct colour values in a specified format

import { getPalette } from "@nqminds/colours";
const palette = getPalette(paletteSize, options);

Parameters

  • paletteSize: number of colors to use

  • options: object

    • format: string. One of hex, rgb, cmyk, hsl.
      • default = hex
    • exclusions: array of colours to exclude. e.g. ["red", "green"].
      • default = []

Returns

Array of colour values of length paletteSize.

map-to-palette

A function which can be used to map data automatically to a color map.

It supports the following data types:

  • Boolean - maps true/false to 2 bins
  • Strings - maps each unique string to a bin (to be used on categorical variables with only a few values)
  • Numbers - bins values into the specified number of intervals inferred from the values in the data, NaN, undefined and null values are ignored and linear or logarithmic intervals are supported. Interval bounds are rounded to the specified precision and if values of <= 0 are provided for a logarithmic scale colormap an extra interval from 0 to the minumum positive non-zero value is added to the generated intervals.
import { mapToPalette } from "@nqminds/colours";
const palette = getPalette(paletteSize, options);
const { paletteMap, getColour } = mapToPalette(
  data,
  "property.subProperty",
  "number",
  options
);

Parameters

  • data: array of data objects
  • field: path to the field in the data to map to a colormap
  • type: string specifying data type
  • options: object
    • format: string. One of hex, rgb, cmyk, hsl.
      • default = hex
    • exclusions: array of colours to exclude. e.g. ["red", "green"].
      • default = []
    • paletteSize number of intervals to use for numeric values
      • default = 10
    • precision precision (significant figures) to use for interval boundries
      • default = 2
    • logarithmic whether to use a logarithmic color map (Linear is used by default)
      • default = false
    • colourMap an external colour map object (keys/values being keys/colours), entries from this colour map are only added to the palette map if data is present with the corresponding key. Can be used to ensure that particular keys always map to a particular colours

Returns

  • Result
  • Result.paletteMap - paletteMap object generated for supplied data
  • Result.getColour - method which when passed a data object will return the mapped color value