Create a gist now

Instantly share code, notes, and snippets.

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