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

scale-color-perceptual

v1.1.2

Published

Javascript exports of matplotlib's new default color scales; inferno, magma, plasma and viridis. Works with browserify and D3.js

Downloads

4,804

Readme

scale-color-perceptual

Javascript exports of matplotlib's new default color scales; inferno, magma, plasma and viridis. Works with browserify and D3.js

Image showing inferno, magma, plasma and viridis respectively
Inferno, magma, plasma and viridis respectively Installation

npm install scale-color-perceptual

Usage

const scale = require('scale-color-perceptual')

[0, 0.25, 0.5, 0.75, 1].map(scale.viridis) // Spits out the colors at the given points

Exports scale.inferno(t), scale.magma(t), scale.plasma(t) and scale.viridis(t), all taking scale parameter t in the range [0, 1]. If a number is given outside this range is given an Error will be thrown.

Each of the scales has been put in the root of the module allowing you to import only the scale you need, yielding a smaller JS file:


const viridis = require('scale-color-perceptual/viridis')

[0, 0.25, 0.5, 0.75, 1].map(viridis) // Spits out the colors at the given

It can also be used with D3:

const d3 = require('d3')
const plasma = require('scale-color-perceptual/plasma')

const depthScale = d3.scale.linear().domain([-100, 100]) // default range is [0, 1]
    .clamp(true) // Make sure the output is constrained to [0, 1]

d3.selectAll('div', document.body)
    .data(d3.shuffle(d3.range(-100, 100, 0.1)).map(n => Math.random() * n))
  .enter().append('div')
    .style({
      background: d => viridis(depthScale(d)),
      width: '10px',
      height: '10px',
      float: 'left'
    })

You can also import the raw color maps, either as hex or rgb triplets ([r, g, b], where c is in [0, 1]):

const d3 = require('d3')
const plasmaMap = require('scale-color-perceptual/hex/plasma') // returns 256 hex colors from dark to bright

const colorScale = d3.scale.quantize().domain([-128, 127]).range(plasmaMap)

Development

rgb/ contains raw JSON exports of the pixel [r, g, b] triplets from bids/colormap, which are the default color scales in matplotlib 2.0. The pixel triplets were obtained from bids/colormap#84cb377. To build the corresponding hex/ files, run make.

License

All credits go to Stéfan van der Walt and Nathaniel Smith for their work devising these color scales. Remember to watch their talk on how it was derived and how it is better than other common scales

The code in this repository is licensed under ISC