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

hue-map

v1.0.0

Published

Interpolate gradients based on common palettes

Downloads

141

Readme

🎨 Hue Map

npm version minzip size

Interpolate gradients based on common palettes. See a demo.

Inspired by D3 colour scales, with maps from colormap.

Some example palettes

Installation

yarn add hue-map

Usage

import { createPalette } from 'hue-map'

const myPalette = createPalette({
  map: 'viridis',
  steps: 3,
})

console.log(myPalette.format('cssHex'))
// --> ['#440154FF', '#21908DFF', '#FDE725FF']

API

hue-map exports a createPalette function which takes an options object and returns a palette object.

Palette Creation Options

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | map | string | 'viridis' | The colour map to use, see below for a list of built-in colour maps. You can also provide a custom colour map. | | steps | number | 10 | The number of colour shades to return. |

Palette Formatting

Call .format() on a palette object to get an array of colours. Pass a format argument to control the format that the colors are returned as.

| Format | Returned Type | Example | Description | | -------- | ------------- | ----------- | ------------------------------------------- | | cssHex | string | '#F79E00FF' | A valid css colour in the form of #RRGGBBAA | | cssRGBA | string | 'rgba(247, 158, 0, 1)' | A valid css colour in the form of rgba(R, G, B, A) | | number | number | 0xF79E00FF | A hex number representing the colour in the form of 0xRRGGBBAA | | float | [number, number, number, number] | [0.3, 0.2, 0.5, 1.0] | A four-tuple of numbers between 0 and 1 representing R, G, B, and A respectively | | rgba | [number, number, number, number] | [128, 40, 200, 255] | A four-tuple of numbers between 0 and 255 representing R, G, B, and A respectively |

Built-in maps

There are several built-in colour maps available to use:

jet, hsv, hot, spring, summer, autumn, winter, bone, copper, greys, yignbu, greens, yiorrd, bluered, rdbu, picnic, rainbow, portland, blackbody, earth, electric, alpha, viridis, inferno, magma, plasma, warm, cool, rainbow-soft, bathymetry, cdom, chlorophyll, density, freesurface-blue, freesurface-red, oxygen, par, phase, salinity, temperature, turbidity, velocity-blue, velocity-green, cubehelix

Visit the demo page to see a list with examples.

Custom colour maps

You can also provide a custom colour map to the map option, with a type of [number, number | RGBA][]. This is an array of tuples, where each tuple has an index of where that colour appears in the gradient (from 0 to 1), and the colour at that point, as a HEX number or an RGBA tuple. Note that all HEX numbers need to include alpha.

import { createPalette } from 'hue-map'

// 3 colour points, using HEX values
const myHexPalette = createPalette({
  map: [
    [0, 0xFEAC5EFF],
    [0.5, 0xC779D0FF],
    [1, 0x4BC0C8FF],
  ]
})

// 5 colour points, using RGBA values
const myHexPalette = createPalette({
  map: [
    [0, [38, 83, 43, 255]],
    [0.25, [57, 158, 90, 255]],
    [0.5, [90, 188, 185, 255]],
    [0.75, [99, 226, 198, 255]],
    [1, [110, 249, 245, 255]],
  ]
})

Development

  1. Clone the repo onto your machine
  2. Run yarn to install dependencies
  3. Run yarn dev to test palettes with a demo page

Build the library to dist using yarn build.

Contributing

Issue contributions and PRs are greatly welcomed and appreciated!

This library uses changesets, if the changes you've made would constitute a version bump, run yarn changeset and follow the prompts to document the changes you've made. Changesets are consumed on releases, and used to generate a changelog and bump version number.

License

hue-map is licensed under MIT