Giter VIP home page Giter VIP logo

classybrew's Introduction

classybrew

classybrew lets you choose from several statistical algorithms (Jenks Natural Breaks, Quantile, Equal Interval) to generate class breaks based on your data. classybrew has colorbrewer color palettes built in to quickly generate choropleth maps, graphics, tables, etc. with ease.

View classybrew in action!

Created By: tannergeo

Using classybrew

Basics - Setup

var brew = new classyBrew();
brew.setSeries([30.01, 14.9, 22.71, 24.96, 7.17, ...]);
brew.setNumClasses(5);
brew.setColorCode("BuGn");

Basics - Classify

brew.classify('jenks'); // returns [7.17,14.9,19.3,22.71,26.9,31.26]

Basics - Retrieval

var breaks = brew.getBreaks(); // returns [7.17,14.9,19.3,22.71,26.9,31.26]
var colors = brew.getColors(); // returns [rgb(237,248,251),rgb(178,226,226),rgb(102,194,164),rgb(44,162,95),rgb(0,109,44)]
brew.getColorInRange(7.5); // returns rgb(237,248,251)

All classybrew Methods

//constructor
var brew = new classyBrew();

//_____setters______//
//__________________//

// classification
brew.setSeries(Array); // define array of data to classify
brew.setNumClasses(Number); // number of classes or breaks
//@Methods: equal_interval, quantile, jenks
brew.classify(Method:optional, Classes:optional); // returns classified data. Defaults to natural breaks methods

// color theory
brew.setColorCode(ColorCodeString); // color ramp code... see below

//_____getters______//
//__________________//

// classification
brew.getSeries(); // returns Array of original data
brew.getNumClasses(); // returns set number of classes
brew.getBreaks(); // will call classify but for performance returns pointer if classify has already been called
brew.getClassificationMethods(); // returns available classification methods to pass to classify()

//color theory
brew.getColorCodes(); // returns array of all available color codes
brew.getColorCodesByType(); // returns object of color codes by type (diverging, sequential, qualitative)
brew.getColorCode(); // returns set color code
brew.getColors(); // returns array of colors specific to your data
brew.getColorInRange(Num); // returns appropriate color for given number

Color Theory

The colors generated using classybrew are based on Cynthia Brewer's sequential color ramps. Below are the possible codes you can use when generating your color ramp with your data. BuGn -> Blue to Green

var brew = new classyBrew();
brew.getColorCodes();  // returns
/*
["OrRd", "PuBu", "BuPu", "Oranges", 
"BuGn", "YlOrBr", "YlGn", "Reds", 
"RdPu", "Greens", "YlGnBu", "Purples", 
"GnBu", "Greys", "YlOrRd", "PuRd", "Blues", 
"PuBuGn", "Spectral", "RdYlGn", "RdBu", 
"PiYG", "PRGn", "RdYlBu", "BrBG", 
"RdGy", "PuOr", "Set2", "Accent", 
"Set1", "Set3", "Dark2", "Paired", 
"Pastel2", "Pastel1"];
*/

You can also view the simple test file (./test/index.html) to better understand how to use the library and visualize the color palettes.

This tool was built with inspiration from two outstanding open source repositories.

classybrew's People

Contributors

tannerjt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

classybrew's Issues

Webpack can't find the module

Webpack can't find classybrew module in my project. Looks like the problem is missing definition of an entry point of your module in package.json:

...
"main": "build/classybrew.min.js",
...

By the way, repository attribute is incorrect, too.

Fewer actual ranges than specified number of classes

When the evaluation of the values array finds fewer ranges than the number of classes specified, the range array is filled at the lower end with zeroes. This causes the getColorInRange function to return erroneous results ("undefined" and "false") when the value of the num provided to it is zero. This is because the test for this.range[i + 1] (to see if it exists) produces false because the value in this.range[i + 1] is zero, which is the same as false. Correcting the test to this.range[i + 1] !== "undefined" fixes the problem, but still causes num of zero to select something other than the very first color.

Example:
numClasses = 6
brew.classify() = [0, 0, 0, 5859, 102141, 198942, 378736]
brew.getColors() = [color1, color2, color3, color4, color5, color6]
brew.getColorInRange(0) = color3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.