0.2.10 • Published 2 years ago

@nqminds/colours v0.2.10

Weekly downloads
70
License
UNLICENSED
Repository
github
Last release
2 years ago

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
0.2.10-alpha.0

2 years ago

0.2.10

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.6-alpha.7

3 years ago

0.2.6-alpha.5

3 years ago

0.2.6-alpha.6

3 years ago

0.2.6-alpha.3

3 years ago

0.2.6-alpha.4

3 years ago

0.2.6-alpha.1

3 years ago

0.2.6-alpha.2

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5-alpha.0

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3-alpha.0

3 years ago

0.2.3

3 years ago

0.2.2-alpha.0

3 years ago

0.2.2-alpha.1

3 years ago

0.2.2

3 years ago

0.2.2-alpha.2

3 years ago

0.2.2-alpha.3

3 years ago

0.2.2-alpha.4

3 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago