Skip to content
gka edited this page Jun 7, 2012 · 2 revisions

Scales are utility functions for mapping data values of arbitrary domains to the [0..1] range. The concept is heavily influenced by d3.

You can construct a scale by calling one of the following generator methods:

  • kartograph.scale.linear()
  • kartograph.scale.quantiles()
  • kartograph.scale.log()

The scale types share the same constructor and can be used almost in the same way.

Here's how to construct a scale in the most simple way:

domain = [83736.34, 237474.94, 4353.53, ..] // array of values
scale = kartograph.scale.linear(domain);

If the values are not given in plain lists but in a list of dictionaries, you can pass the value key as second parameter to the scale constructor.

domain = [{ label: "New York City", amount: 23453 }, ..] // array of dictionaries
scale = kartograph.scale.linear(domain, 'amount');

Sometimes you need to compute the actual values based on multiple measures in your data. Therefore scale constructor allows you to pass a function for computing values for each item within the domain.

domain = [{ label: "New York City", murder: 227, population: 8175133 }, ..] // array of dictionaries
scale = kartograph.scale.linear(domain, function(item) {
  return item.murder / item.population;
});
Clone this wiki locally