Skip to content

Instantly share code, notes, and snippets.

@classiemilio
Last active July 26, 2016 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save classiemilio/aa2a3e707723a5685dc5709a67d4aece to your computer and use it in GitHub Desktop.
Save classiemilio/aa2a3e707723a5685dc5709a67d4aece to your computer and use it in GitHub Desktop.
/* Implementation */
function renderCircles(xScale, yScale, data) {
d3.selectAll('circle')
.data(data)
.enter()
.append('circle')
.attr('cx', circleCX.bind(undefined, xScale)
.attr('cy', circleCY.bind(undefined, yScale);
}
function circleCX(xScale, datum) {
return xScale(datum.x);
}
function circleCY(yScale, datum) {
return yScale(datum.y);
}
/* Test */
describe('#circleCX', function() {
it('returns the correct values', function() {
var xScale = d3.scale.linear().domain([0, 10]).range([0, 100]);
assert.strictEqual(circleCX(xScale, { x: 0, y: 0 }), 0);
assert.strictEqual(circleCX(xScale, { x: 5, y: 0 }), 50);
assert.strictEqual(circleCX(xScale, { x: 9.9, y: 0 }), 99);
assert.strictEqual(circleCX(xScale, { x: 10, y: 0 }), 100);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment