Skip to content

cmap

cmap(data, robust?, cmapSeq?, cmapBool?, cmapDiv?): any

Defined in: packages/pleco-xa/src/scripts/xa-display.js:107

Get a default colormap from the given data

Determines an appropriate colormap based on data characteristics:

  • Sequential colormaps for non-negative data
  • Boolean colormaps for binary data
  • Diverging colormaps for centered data

any[] | Float32Array<ArrayBufferLike> | number[][]

Input data (1D or 2D array)

boolean = true

If true, use 2nd/98th percentiles for range detection

string = 'magma'

Sequential colormap name (default: ‘magma’)

string = 'gray_r'

Boolean colormap name (default: ‘gray_r’)

string = 'coolwarm'

Diverging colormap name (default: ‘coolwarm’)

any

Colormap configuration with {type, name, colors, map function}

// Sequential data (spectrogram)
const spec = new Float32Array([0.1, 0.5, 0.9, 1.2]);
const cmap = cmap(spec); // Returns 'magma' sequential colormap
// Centered data (chromagram difference)
const diff = new Float32Array([-1.0, -0.5, 0.0, 0.5, 1.0]);
const cmap = cmap(diff, true, 'magma', 'gray_r', 'coolwarm'); // Returns 'coolwarm' diverging