node package manager

geocolor

Geocolor

Build Status

Geocolor is both a javascript module and a web app. The web app makes it easy to demo the functionality or use to create quick visualizations without having to code. It can be found at geocolor.io.

Geocolor classifies data contained in geojson properties, and assigns color values based on the simplestyle-spec. This means that when your geojson is rendered in github, gists, mapbox, or other simplestyle-spec compliant renderers, you will get nice styles that help to visualize your data.

sc-counties

Install

npm install geocolor

Colors

The color gradient is defined by simply passing an array of colors with as many stops as you want.

Classification

Curently supported classifications:

  • equal intervals
  • quantiles
  • jenks
  • custom
  • random
  • all

Example

gradient

var geocolor = require('geocolor')
 
var cities = {
  // [point data](https://github.com/morganherlocker/geocolor/blob/master/test/in/cities.geojson) 
}
 
var z = 'Population',
    numberOfBreaks = 5,
    colors = ['green', 'yellow', 'red']
 
// jenks 
geoJenks = geocolor.jenks(cities, z, numberOfBreaks, colors)
console.log(geoJenks)
 
// quantiles 
geoQuantiles = geocolor.quantiles(cities, z, numberOfBreaks, colors)
console.log(geoQuantiles)
 
// equal intervals 
geoEqualIntervals = geocolor.equalIntervals(cities, z, numberOfBreaks, colors)
console.log(geoEqualIntervals)
 
// custom breaks 
geoCustom = geocolor.custom(cities, z, [0,200000,300000,400000,500000,800000,1000000,1000000000], colors)
console.log(geoCustom)
 
// random colors 
geoRandom = geocolor.random(geo, ['green', 'yellow', 'red', 'blue', 'purple', 'orange', 'pink'])
console.log(geoRandom)
 
// all (assigns the same style to all features) 
var style = {
  'stroke': 'blue',
  'fill-opacity': .7,
  'fill': 'green'
}
geoAll = geocolor.all(geo, style)
console.log(geoRandom)

You can also pass in a custom style object to any of the functions that will applied to all features as an optional parameter. The following will perform a quantile white to red ramp, will set the stroke to blue, and will set the fill opacity to .4.

var geocolor = require('geocolor')
 
var cities = {
  // [point data](https://github.com/morganherlocker/geocolor/blob/master/test/in/cities.geojson) 
}
 
var z = 'Population',
    numberOfBreaks = 15,
    colors = ['white', 'red']
 
var style = {
  'stroke': 'blue',
  'fill-opacity': .4
}
 
// quantiles 
geoQuantiles = geocolor.quantiles(cities, z, numberOfBreaks, colors, style)
console.log(geoQuantiles)

Dev

Running tests:

npm test

More Examples

rivers

choloropleth

gradient

gradient