• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..21-May-2021-

build/H03-May-2022-

node_modules/d3-scale/H21-May-2021-916569

src/H03-May-2022-

LICENSEH A D21-May-20211.5 KiB2822

README.mdH A D21-May-20215.4 KiB136108

package.jsonH A D21-May-20211.3 KiB4544

README.md

1# vega-scale
2
3Scales and color schemes for visual encoding.
4
5This module provides [scale](#scale) and [scheme](#scheme) methods for
6managing scale mappings and color schemes. By default, the scale and
7scheme registries include all scale types and color schemes provided
8by the D3 4.0 [d3-scale](https://github.com/d3/d3-scale) and
9[d3-scale-chromatic](https://github.com/d3/d3-scale-chromatic) modules.
10
11This module also provides augmented implementations of `'band'`, `'point'`,
12and `'sequential'` scales in order to provide improved layout and
13inversion support for band/point scales, and multi-domain and color range
14array support for sequential scales.
15
16## API Reference
17
18<a name="scale" href="#scale">#</a>
19vega.<b>scale</b>(<i>type</i>[, <i>scale</i>])
20[<>](https://github.com/vega/vega-scale/blob/master/src/scales.js "Source")
21
22Registry function for adding and accessing scale constructor functions.
23The *type* argument is a String indicating the name of the scale type.
24If the *scale* argument is not specified, this method returns the matching
25scale constructor in the registry, or `null` if not found.
26If the *scale* argument is provided, it must be a scale constructor function
27to add to the registry under the given *type* name.
28
29By default, the scale registry includes entries for all scale types provided
30by D3 4.0's [d3-scale](https://github.com/d3/d3-scale) module. Scales created
31using the constructor returned by this method have an additional `type`
32property indicating the scale type. All scales supporting either an `invert`
33or `invertExtent` method are augmented with an additional `invertRange`
34function that returns an array of corresponding domain values for a given
35interval in the scale's output range.
36
37```js
38// linear scale
39var linear = vega.scale('linear');
40var scale = linear().domain([0, 10]).range([0, 100]);
41scale.type; // 'linear'
42scale.invertRange([0, 100]); // [0, 10]
43```
44
45```js
46var ordinal = vega.scale('ordinal');
47
48// ordinal scale
49var scale1 = ordinal().domain(['a', 'b', 'c']).range([0, 1, 2]);
50scale1.type; // 'ordinal'
51
52// ordinal scale with range set to the 'category20' color palette
53var scale2 = ordinal().range(vega.scheme('category20'));
54```
55
56```js
57var seq = vega.scale('sequential');
58
59// sequential scale, using the plasma color palette
60var scale1 = seq().interpolator(vega.scheme('plasma'));
61scale1.type; // 'sequential'
62```
63
64<a name="scheme" href="#scheme">#</a>
65vega.<b>scheme</b>(<i>name</i>[, <i>scheme</i>])
66[<>](https://github.com/vega/vega-scale/blob/master/src/schemes.js "Source")
67
68Registry function for adding and accessing color schemes.
69The *name* argument is a String indicating the name of the color scheme.
70If the *scheme* argument is not specified, this method returns the matching
71scheme value in the registry, or `null` if not found.
72If the *scheme* argument is provided, it must be a valid color array or
73[interpolator](https://github.com/d3/d3-scale#sequential_interpolator)
74to add to the registry under the given *name*.
75
76By default, the scheme registry includes entries for all scheme types
77provided by D3 4.0's [d3-scale](https://github.com/d3/d3-scale) and
78[d3-scale-chromatic](https://github.com/d3/d3-scale-chromatic) module.
79Valid schemes are either arrays of color values (e.g., applicable to
80`'ordinal'` scales) or
81[interpolator](https://github.com/d3/d3-scale#sequential_interpolator)
82functions (e.g., applicable to `'sequential'` scales.)
83
84<a name="interpolate" href="#interpolate">#</a>
85vega.<b>interpolate</b>(<i>name</i>[, <i>gamma</i>])
86[<>](https://github.com/vega/vega-scale/blob/master/src/interpolate.js "Source")
87
88Returns the D3 interpolator factory with the given *name* and optional
89*gamma*. All interpolator types provided by the
90[d3-interpolate](https://github.com/d3/d3-interpolate) module are supported.
91However, Vega uses hyphenated rather than camelCase names.
92
93```js
94var rgbBasis = vega.interpolate('rgb-basis'); // d3.interpolateRgbBasis
95var rgbGamma = vega.interpolate('rgb', 2.2);  // d3.interpolateRgb.gamma(2.2)
96```
97
98<a name="interpolateRange" href="#interpolateRange">#</a>
99vega.<b>interpolateRange</b>(<i>interpolator</i>, <i>range</i>])
100[<>](https://github.com/vega/vega-scale/blob/master/src/interpolate.js "Source")
101
102Given a D3 *interpolator* instance, return a new interpolator with a modified
103interpolation *range*. The *range* argument should be a two element array
104whose entries lie in the range [0, 1]. This method is convenient for
105transforming the range of values over which interpolation is performed.
106
107```js
108var number = d3.interpolateNumber(0, 10);
109number(0);   // 0
110number(0.5); // 5
111number(1);   // 1
112
113var range = vega.interpolateRange(number, [0.2, 0.8]);
114range(0);   // 2
115range(0.5); // 5
116range(1);   // 8
117```
118
119<a name="timeInterval" href="#timeInterval">#</a>
120vega.<b>timeInterval</b>(<i>unit</i>)
121[<>](https://github.com/vega/vega-scale/blob/master/src/timeInterval.js "Source")
122
123Given a string _unit_, return a corresponding
124[D3 time interval](https://github.com/d3/d3-time#_interval) function.
125Valid _unit_ strings are: `"millisecond"`, `"second"`, `"minute"`, `"hour"`,
126`"day"`, `"week"`, `"month"`, and `"year"`.
127
128<a name="utcInterval" href="#utcInterval">#</a>
129vega.<b>utcInterval</b>(<i>unit</i>)
130[<>](https://github.com/vega/vega-scale/blob/master/src/timeInterval.js "Source")
131
132Given a string _unit_, return a corresponding UTC-variant of a
133[D3 time interval](https://github.com/d3/d3-time#_interval) function.
134Valid _unit_ strings are: `"millisecond"`, `"second"`, `"minute"`, `"hour"`,
135`"day"`, `"week"`, `"month"`, and `"year"`.
136