How to use colormap - 9 common examples

To help you get started, we’ve selected a few colormap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openlayers / workshop / src / en / examples / vector / style.js View on Github external
import Snap from 'ol/interaction/Snap';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import View from 'ol/View';
import sync from 'ol-hashed';
import {Fill, Stroke, Style} from 'ol/style';
//! [imports]
import {getArea} from 'ol/sphere';
import colormap from 'colormap';
//! [imports]

//! [color]
const min = 1e8; // the smallest area
const max = 2e13; // the biggest area
const steps = 50;
const ramp = colormap({
  colormap: 'blackbody',
  nshades: steps
});

function clamp(value, low, high) {
  return Math.max(low, Math.min(value, high));
}

function getColor(feature) {
  const area = getArea(feature.getGeometry());
  const f = Math.pow(clamp((area - min) / (max - min), 0, 1), 1 / 2);
  const index = Math.round(f * (steps - 1));
  return ramp[index];
}
//! [color]
github allenai / allennlp-demo / demo / src / components / Saliency.js View on Github external
colorize(tokensWithWeights, topKIdx) {
    const {colormapProps} = this.props
    // colormap package takes minimum of 6 shades
    colormapProps.nshades =  Math.min(Math.max(colormapProps.nshades, 6), 72);
    const colors = colormap(colormapProps)

    let colorizedString = [];
    tokensWithWeights.forEach((obj, idx) => {
      colorizedString.push(
        // Again, 1 -, in this case because low extreme is blue and high extreme is red
        <label style="{{" data-tip="{(1">
            
                {obj.token}
            
        </label>
      )
    })
    return colorizedString
  }
github MikeHeaton / vambda / src / editor.js View on Github external
function getRandomColor() {
    // Generate a random color from a colormap (and convert it to hash).
    var ncolors = 72
    var index = Math.floor(Math.random() * ncolors)
    var col = colormap('nature', ncolors, 'hex')[index]
    return col
  }
github reichlab / flusight / src / choropleth.js View on Github external
let limits = []
    let barLimits = []

    if (data.type === 'sequential') {
      // Set a 0 to max ranged colorscheme
      this.cmap = colormap({
        colormap: 'YIOrRd',
        nshades: 50,
        format: 'rgbaString'
      })

      limits = [maxData, 0]
      barLimits = [0, maxData]
    } else if (data.type === 'diverging') {
      this.cmap = colormap({
        colormap: 'RdBu',
        nshades: 50,
        format: 'rgbaString'
      }).reverse()

      let extreme = Math.max(Math.abs(maxData), Math.abs(minData))

      limits = [extreme, -extreme]
      barLimits = [-extreme, extreme]
    }

    this.colorScale = d3.scaleLinear()
      .domain(limits)
      .range([0, this.cmap.length - 0.01])

    // Setup color bar
github reichlab / flusight / src / choropleth.js View on Github external
plot (data) {
    let svg = this.svg
    let regionHook = this.regionHook
    let tooltip = this.tooltip

    let minData = data.range[0]
    let maxData = data.range[1]

    let limits = []
    let barLimits = []

    if (data.type === 'sequential') {
      // Set a 0 to max ranged colorscheme
      this.cmap = colormap({
        colormap: 'YIOrRd',
        nshades: 50,
        format: 'rgbaString'
      })

      limits = [maxData, 0]
      barLimits = [0, maxData]
    } else if (data.type === 'diverging') {
      this.cmap = colormap({
        colormap: 'RdBu',
        nshades: 50,
        format: 'rgbaString'
      }).reverse()

      let extreme = Math.max(Math.abs(maxData), Math.abs(minData))
github reichlab / flusight / src / modules / map.js View on Github external
defaultFill: '#ccc'
      },
      geographyConfig: {
        highlightOnHover: false,
        popupTemplate: (geo, data) =&gt; {
          return ['<div class="hoverinfo">',
                  '<strong>State</strong><br>',
                  '<strong>Region</strong><br>',
                  'Weighted ILI (%)',
                  '</div>'].join('')
        }
      }
    })

    let nCmap = 50
    this.cmap = colormap({
      colormap: 'YIOrRd',
      nshades: nCmap,
      format: 'rgbaString'
    })

    let svg = this.d3.select('#' + this.elementId + ' svg')
    this.width = svg.node().getBoundingClientRect().width
    this.height = svg.node().getBoundingClientRect().height
    this.svg = svg
    this.nCmap = nCmap

    this.setupInfo()
    this.setupColorBar()
  }
github eranimo / terranova / src / interface / worldview / mapModes.ts View on Github external
constructor(
    options: {
      title: string,
      datapoint: string,
      colormap: string,
      showLegend?: boolean,
    },
    worldMap: WorldMap
  ) {
    this.title = options.title;
    this.worldMap = worldMap;
    this.datapoint = options.datapoint;
    this.colormap = options.colormap;
    this.showLegend = options.showLegend !== false;

    const colors: [number, number, number, number][] = colormap({
      nshades: 101,
      format: 'rba',
      colormap: this.colormap
    });
    let item;
    let min = Infinity;
    let max = -Infinity;
    const data = [];
    for (const cell of worldMap.world.cells) {
      item = cell[options.datapoint];
      data.push(item);
      if (item &lt; min) {
        min = item;
      } else if (item &gt; max) {
        max = item;
      }
github spikeekips / mitum / contrib / logviewer / src / App.js View on Github external
importTestData = () => {
      this.log = Log.load(raw)

      this.props.enqueueSnackbar(
        'test log data successfully imported: ' + this.log.records.length + ' records found',
        {variant: 'info'},
      )

      var colors = colormap({
        colormap: 'hsv',
        nshades: this.log.modules.length > 10 ? this.log.modules.length : 11,
        format: 'hex',
        alpha: 1,
      })

      this.setState({
        nodes: this.log.nodes,
        msgs: this.log.msgs,
        levels: this.log.levels,
        modules: this.log.modules,
        moduleColors: colors,
      })
github glslify / glsl-colormap / bin / build.js View on Github external
#!/usr/bin/env node
var data = require('colormap/colorScales.js')
var colors = Object.keys(data)
var gen = require('../index.js')
var fs = require('fs')
var path = require('path')

var file = path.join(__dirname, '..', 'colors.json')
fs.writeFile(file, JSON.stringify(colors))
colors.forEach(function (name) {
  var file = path.join(__dirname, '..', name + '.glsl')
  fs.writeFile(file, gen(name, data[name]))
})

colormap

Great looking color maps

MIT
Latest version published 4 years ago

Package Health Score

54 / 100
Full package analysis

Popular colormap functions