vega/vega-scale

Name: vega-scale

Owner: Vega

Description: Scales and color schemes for visual encoding.

Created: 2016-08-10 03:47:23.0

Updated: 2016-09-23 23:23:17.0

Pushed: 2017-08-11 04:44:05.0

Homepage: null

Size: 31

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

vega-scale

Scales and color schemes for visual encoding.

This module provides scale and scheme methods for managing scale mappings and color schemes. By default, the scale and scheme registries include all scale types and color schemes provided by the D3 4.0 d3-scale and d3-scale-chromatic modules.

This module also provides augmented implementations of 'band', 'point', and 'sequential' scales in order to provide improved layout and inversion support for band/point scales, and multi-domain and color range array support for sequential scales.

API Reference

# vega.scale(type[, scale]) <>

Registry function for adding and accessing scale constructor functions. The type argument is a String indicating the name of the scale type. If the scale argument is not specified, this method returns the matching scale constructor in the registry, or null if not found. If the scale argument is provided, it must be a scale constructor function to add to the registry under the given type name.

By default, the scale registry includes entries for all scale types provided by D3 4.0's d3-scale module. Scales created using the constructor returned by this method have an additional type property indicating the scale type. All scales supporting either an invert or invertExtent method are augmented with an additional invertRange function that returns an array of corresponding domain values for a given interval in the scale's output range.

inear scale
linear = vega.scale('linear');
scale = linear().domain([0, 10]).range([0, 100]);
e.type; // 'linear'
e.invertRange([0, 100]); // [0, 10]
s
ordinal = vega.scale('ordinal');

rdinal scale
scale1 = ordinal().domain(['a', 'b', 'c']).range([0, 1, 2]);
e1.type; // 'ordinal'

rdinal scale with range set to the 'category20' color palette
scale2 = ordinal().range(vega.scheme('category20'));
s
seq = vega.scale('sequential');

equential scale, using the plasma color palette
scale1 = seq().interpolator(vega.scheme('plasma'));
e1.type; // 'sequential'

# vega.scheme(name[, scheme]) <>

Registry function for adding and accessing color schemes. The name argument is a String indicating the name of the color scheme. If the scheme argument is not specified, this method returns the matching scheme value in the registry, or null if not found. If the scheme argument is provided, it must be a valid color array or interpolator to add to the registry under the given name.

By default, the scheme registry includes entries for all scheme types provided by D3 4.0's d3-scale and d3-scale-chromatic module. Valid schemes are either arrays of color values (e.g., applicable to 'ordinal' scales) or interpolator functions (e.g., applicable to 'sequential' scales.)

# vega.interpolate(name[, gamma]) <>

Returns the D3 interpolator factory with the given name and optional gamma. All interpolator types provided by the d3-interpolate module are supported. However, Vega uses hyphenated rather than camelCase names.

rgbBasis = vega.interpolate('rgb-basis'); // d3.interpolateRgbBasis
rgbGamma = vega.interpolate('rgb', 2.2);  // d3.interpolateRgb.gamma(2.2)

# vega.interpolateRange(interpolator, range]) <>

Given a D3 interpolator instance, return a new interpolator with a modified interpolation range. The range argument should be a two element array whose entries lie in the range [0, 1]. This method is convenient for transforming the range of values over which interpolation is performed.

number = d3.interpolateNumber(0, 10);
er(0);   // 0
er(0.5); // 5
er(1);   // 1

range = vega.interpolateRange(number, [0.2, 0.8]);
e(0);   // 2
e(0.5); // 5
e(1);   // 8

# vega.timeInterval(unit) <>

Given a string unit, return a corresponding D3 time interval function. Valid unit strings are: "millisecond", "second", "minute", "hour", "day", "week", "month", and "year".

# vega.utcInterval(unit) <>

Given a string unit, return a corresponding UTC-variant of a D3 time interval function. Valid unit strings are: "millisecond", "second", "minute", "hour", "day", "week", "month", and "year".


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.