Skip to content

Commit

Permalink
Fix #83 - add quantize.thresholds.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jan 27, 2019
1 parent 058882b commit 0c30bf3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,10 @@ Equivalent to [*continuous*.tickFormat](#continuous_tickFormat).

Equivalent to [*continuous*.nice](#continuous_nice).

<a name="quantize_thresholds" href="#quantize_thresholds">#</a> <i>quantize</i>.<b>thresholds</b>() [<>](https://github.com/d3/d3-scale/blob/master/src/quantize.js "Source")

Returns the array of computed thresholds within the [domain](#quantize_domain).

<a name="quantize_copy" href="#quantize_copy">#</a> <i>quantize</i>.<b>copy</b>() [<>](https://github.com/d3/d3-scale/blob/master/src/quantize.js "Source")

Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa.
Expand Down
4 changes: 4 additions & 0 deletions src/quantize.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export default function quantize() {
return arguments.length ? (unknown = _, scale) : scale;
};

scale.thresholds = function() {
return domain.slice();
};

scale.copy = function() {
return quantize()
.domain([x0, x1])
Expand Down
2 changes: 2 additions & 0 deletions test/quantize-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ tape("scaleQuantize() has the expected defaults", function(test) {
var s = scale.scaleQuantize();
test.deepEqual(s.domain(), [0, 1]);
test.deepEqual(s.range(), [0, 1]);
test.deepEqual(s.thresholds(), [0.5]);
test.equal(s(0.25), 0);
test.equal(s(0.75), 1);
test.end();
});

tape("quantize(value) maps a number to a discrete value in the range", function(test) {
var s = scale.scaleQuantize().range([0, 1, 2]);
test.deepEqual(s.thresholds(), [1 / 3, 2 / 3]);
test.equal(s(0.0), 0);
test.equal(s(0.2), 0);
test.equal(s(0.4), 1);
Expand Down

0 comments on commit 0c30bf3

Please sign in to comment.