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

js-colormaps-es

v0.0.5

Published

Downloads

31

Readme

js-colormaps

💡Idea: matplotlib colormaps for JavaScript

The idea of this project is simple: make the colormaps of Python's matplotlib library available in JavaScript. I came up with it because I needed a colormap in JavaScript for a side project of mine and Google did not spit out any good results, so I decided to do it myself and make it available to the public.

🎨 What is a colormap?

If you have found this repository I presume you already know what a colormap is, but just for completeness’ sake, a colormap formally is a function f: [0, 1] → [0, 255]³ that maps a number onto a color, represented by a triplet of 8-bit integers (= the red, green, blue values). Or at least that is the convention that I have adopted for this project. Of course, a lot of the time the values you want to colorcode are not between 0 and 1 — in this case, you will have to rescale them first.

🚀 How can I use the colormaps?

Most of the magic is contained in the js-colormaps.js file, which you need to include like:

<script src="js-colormaps.js"></script>

or install with yarn:

yarn add js-colormaps-es

or npm:

npm i js-colormaps-es

Once you have loaded that file, you have either use the function evaluate_cmap(x, name, reverse) to map a value x onto a color using the colormap specified by name and reverse:

>> evaluate_cmap(0.5, 'viridis', false)
Array(3) [ 33, 144, 140 ]

Alternatively, you can also directly access every colormap by its name (using the _r suffix to reverse it):

>> RdBu_r(0.25)
Array(3) [ 106, 172, 208 ]

🌈 Which colormaps are available?

All of matplotlib’s colormaps are available, under the same name that you would use in Python:

(Feel free to check out the overview.html file to see how this overview figure was created.)

Additionally, it should not be too hard to modify the code in create-colormaps.py to also export other Python-based colormaps to JavaScript, for example, the scientific colour maps by Fabio Crameri.

⚖️ Copyright

I did not invent any of the colormaps here, I do not own them, and I do not claim that I do. I just tried to make them available to others. If I happen to violate any of your copyrights with this project, please inform me before you drag me to court and we can sort this thing out :-)

Regarding my own copyrights: The project is released under the MIT license (see LICENSE file), which pretty much means “Do whatever you want, but don't hold me liable!”.