Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ chroma.scale(['yellow', 'red', 'black']);
### scale.domain
#### (domain)

You can change the input domain to match your specific use case.
You can change the input domain to match your specific use case. If called with no arguments, `scale.domain` returns the original array of positions along the scale where the color ramp was sampled.

```js
// default domain is [0,1]
Expand Down
2 changes: 1 addition & 1 deletion src/generator/scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default function (colors) {

f.domain = function (domain) {
if (!arguments.length) {
return _domain;
return _pos.map(p => _min + p * (_max - _min));;
}
_min = domain[0];
_max = domain[domain.length - 1];
Expand Down
21 changes: 21 additions & 0 deletions test/scales.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,25 @@ describe('Some tests for scale()', () => {
expect(f(0.625).hex()).toBe(f1(0.75).hex());
});
});

describe('multi-stop domain with matching ramp stops', () => {
const f = scale(['yellow', 'red', 'black']).domain([0, 25, 100]);

it('returns the original domain positions', () => {
expect(f.domain()).toEqual([0, 25, 100]);
});

it('maps first stop', () => {
expect(f(0).hex()).toBe('#ffff00');
});

it('maps mid stop', () => {
expect(f(25).hex()).toBe('#ff8080');
});

it('maps last stop', () => {
expect(f(100).hex()).toBe('#000000');
});
});

});