Last active
July 26, 2016 21:19
-
-
Save classiemilio/aa2a3e707723a5685dc5709a67d4aece to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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