Skip to content

Instantly share code, notes, and snippets.

@classiemilio
Created July 25, 2016 19:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save classiemilio/9a422290b9f29c7beccd3d9cd591e5b4 to your computer and use it in GitHub Desktop.
/* Implementation */
function getXScale(dimensions, data) {
var range = [0, dimensions.width];
var domain = [0, data.length - 1];
return d3.scale.linear().domain(domain).range(range);
}
/* Test */
describe('#getXScale', function() {
it('returns the correct domain and range', function() {
var data = [0, 5, 10, 30, 50];
var dimensions = {
width: 100,
height: 300
};
var scale = getXScale(dimensions, data);
assert.deepEqual(scale.range(), [0, 100]);
assert.deepEqual(scale.domain(), [0, 4]);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment