Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
/* 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