MCPcopy Create free account
hub / github.com/jipegit/OSXAuditor / d3_scale_quantize

Function d3_scale_quantize

d3-3.2.8/d3.js:7083–7113  ·  view source on GitHub ↗
(x0, x1, range)

Source from the content-addressed store, hash-verified

7081 return d3_scale_quantize(0, 1, [ 0, 1 ]);
7082 };
7083 function d3_scale_quantize(x0, x1, range) {
7084 var kx, i;
7085 function scale(x) {
7086 return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
7087 }
7088 function rescale() {
7089 kx = range.length / (x1 - x0);
7090 i = range.length - 1;
7091 return scale;
7092 }
7093 scale.domain = function(x) {
7094 if (!arguments.length) return [ x0, x1 ];
7095 x0 = +x[0];
7096 x1 = +x[x.length - 1];
7097 return rescale();
7098 };
7099 scale.range = function(x) {
7100 if (!arguments.length) return range;
7101 range = x;
7102 return rescale();
7103 };
7104 scale.invertExtent = function(y) {
7105 y = range.indexOf(y);
7106 y = y < 0 ? NaN : y / kx + x0;
7107 return [ y, y + 1 / kx ];
7108 };
7109 scale.copy = function() {
7110 return d3_scale_quantize(x0, x1, range);
7111 };
7112 return rescale();
7113 }
7114 d3.scale.threshold = function() {
7115 return d3_scale_threshold([ .5 ], [ 0, 1 ]);
7116 };

Callers 1

d3.jsFile · 0.85

Calls 1

rescaleFunction · 0.85

Tested by

no test coverage detected