1 /** 2 * Returns a linear scale for the specified domain. The arguments to this 3 * constructor are optional, and equivalent to calling {@link #domain}. 4 * The default domain and range are [0,1]. 5 * 6 * @class Represents a linear scale; a function that performs a linear 7 * transformation. <style type="text/css">sub{line-height:0}</style> Most 8 * commonly, a linear scale represents a 1-dimensional linear transformation 9 * from a numeric domain of input data [<i>d<sub>0</sub></i>, 10 * <i>d<sub>1</sub></i>] to a numeric range of pixels [<i>r<sub>0</sub></i>, 11 * <i>r<sub>1</sub></i>]. The equation for such a scale is: 12 * 13 * <blockquote><i>f(x) = (x - d<sub>0</sub>) / (d<sub>1</sub> - d<sub>0</sub>) * 14 * (r<sub>1</sub> - r<sub>0</sub>) + r<sub>0</sub></i></blockquote> 15 * 16 * For example, a linear scale from the domain [0, 100] to range [0, 640]: 17 * 18 * <blockquote><i>f(x) = (x - 0) / (100 - 0) * (640 - 0) + 0</i><br> 19 * <i>f(x) = x / 100 * 640</i><br> 20 * <i>f(x) = x * 6.4</i><br> 21 * </blockquote> 22 * 23 * Thus, saying 24 * 25 * <pre> .height(function(d) d * 6.4)</pre> 26 * 27 * is identical to 28 * 29 * <pre> .height(pv.Scale.linear(0, 100).range(0, 640))</pre> 30 * 31 * Note that the scale is itself a function, and thus can be used as a property 32 * directly, assuming that the data associated with a mark is a number. While 33 * this is convenient for single-use scales, frequently it is desirable to 34 * define scales globally: 35 * 36 * <pre>var y = pv.Scale.linear(0, 100).range(0, 640);</pre> 37 * 38 * The <tt>y</tt> scale can now be equivalently referenced within a property: 39 * 40 * <pre> .height(function(d) y(d))</pre> 41 * 42 * Alternatively, if the data are not simple numbers, the appropriate value can 43 * be passed to the <tt>y</tt> scale (e.g., <tt>d.foo</tt>). The {@link #by} 44 * method similarly allows the data to be mapped to a numeric value before 45 * performing the linear transformation. 46 * 47 * @param {number...} domain... optional domain values. 48 * @extends pv.Scale.quantitative 49 */ 50 pv.Scale.linear = function() { 51 var scale = pv.Scale.quantitative(); 52 scale.domain.apply(scale, arguments); 53 return scale; 54 }; 55