source: Dev/branches/jQueryUI/client/d3/src/scale/quantize.js @ 249

Last change on this file since 249 was 249, checked in by hendrikvanantwerpen, 13 years ago

This one's for Subversion, because it's so close...

First widget (stripped down sequencer).
Seperated client and server code in two direcotry trees.

File size: 563 bytes
Line 
1d3.scale.quantize = function() {
2  var x0 = 0,
3      x1 = 1,
4      kx = 2,
5      i = 1,
6      range = [0, 1];
7
8  function scale(x) {
9    return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
10  }
11
12  scale.domain = function(x) {
13    if (!arguments.length) return [x0, x1];
14    x0 = x[0];
15    x1 = x[1];
16    kx = range.length / (x1 - x0);
17    return scale;
18  };
19
20  scale.range = function(x) {
21    if (!arguments.length) return range;
22    range = x;
23    kx = range.length / (x1 - x0);
24    i = range.length - 1;
25    return scale;
26  };
27
28  return scale;
29};
Note: See TracBrowser for help on using the repository browser.