Skip to content

Instantly share code, notes, and snippets.

@classiemilio
Last active July 27, 2016 00:22
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/a9782d641b86f79131e5617ea916f336 to your computer and use it in GitHub Desktop.
Save classiemilio/a9782d641b86f79131e5617ea916f336 to your computer and use it in GitHub Desktop.
describe('#renderLines', function() {
var xScale;
var yScale;
beforeEach(function() {
xScale = d3.scale.linear().domain([0, 10]).range([0, 100]);
yScale = d3.scale.linear().domain([0, 10]).range([0, 1000]);
});
it('renders lines correctly for a small 1-line data set', function() {
var data = [
[
{x: 0, y: 0},
{x: 0, y: 10},
{x: 10, y: 10}
]
];
renderLines(xScale, yScale, data);
var line = document.getElementsByTagName('path')[0];
assert.strictEqual(line.getAttribute('d'), 'M0,0L0,1000L100,1000');
});
it('renders lines correctly for a small 2-line data set', function() {
var data = [
[
{x: 0, y: 0},
{x: 0, y: 10},
{x: 10, y: 10}
],
[
{x: 0, y: 0.251},
{x: 1.25, y: 5},
{x: 10, y: 6.2}
]
];
renderLines(xScale, yScale, data);
var lines = document.getElementsByTagName('path');
assert.strictEqual(lines[0].getAttribute('d'), 'M0,0L0,1000L100,1000');
assert.strictEqual(lines[1].getAttribute('d'), 'M0,25.1L12.5,500L100,620');
});
it('renders lines correctly for a 1-line data set with 15 data points', function() {
var data = [
[
{x: 0, y: 0},
{x: 0.5, y: 0.251},
{x: 1, y: 1.2},
{x: 1.5, y: 5},
{x: 2, y: 5.01},
{x: 2.5, y: 2.5},
{x: 3, y: 2.666},
{x: 3.5, y: 8.01},
{x: 4, y: 1.01},
{x: 4.5, y: 10},
{x: 5, y: 9.99},
{x: 5.5, y: 7.59},
{x: 6, y: 8},
{x: 6.5, y: 6.9},
{x: 7, y: 7}
]
];
renderLines(xScale, yScale, data);
var line = document.getElementsByTagName('path')[0];
assert.strictEqual(line.getAttribute('d'), 'M0,0L5,25.1L10,120L15,500L20,501L25,250L30,266.6L35,800.9999999999999L40,101L45,1000L50,999L55.00000000000001,759L60,800L65,690.0000000000001L70,700');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment