Skip to content

Commit b5a857f

Browse files
committed
Add test for svg.line.radial.
1 parent 8f78f5e commit b5a857f

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

test/svg/line-radial-test.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
require("../env");
2+
require("../../d3");
3+
4+
var vows = require("vows"),
5+
assert = require("assert");
6+
7+
var suite = vows.describe("d3.svg.line.radial");
8+
9+
suite.addBatch({
10+
"line.radial": {
11+
topic: function() {
12+
return d3.svg.line.radial;
13+
},
14+
15+
"radius defaults to a function accessor": function(line) {
16+
var l = line();
17+
assert.pathEqual(l([[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-10L16.82941969615793,-10.806046117362794L18.185948536513635,8.32293673094285L1.4112000805986715,9.899924966004454");
18+
assert.typeOf(l.radius(), "function");
19+
},
20+
"radius can be defined as a constant": function(line) {
21+
var l = line().radius(30);
22+
assert.pathEqual(l([[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-30L25.244129544236895,-16.20906917604419L27.278922804770453,12.484405096414275L4.233600241796014,29.699774898013363");
23+
assert.equal(l.radius(), 30);
24+
},
25+
"radius can be defined as a function": function(line) {
26+
var l = line().radius(f), t = {}, dd = [], ii = [], tt = [];
27+
function f(d, i) { dd.push(d); ii.push(i); tt.push(this); return 30; }
28+
assert.pathEqual(l.call(t, [[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-30L25.244129544236895,-16.20906917604419L27.278922804770453,12.484405096414275L4.233600241796014,29.699774898013363");
29+
assert.deepEqual(dd, [[10, 0], [20, 1], [20, 2], [10, 3]], "expected data, got {actual}");
30+
assert.deepEqual(ii, [0, 1, 2, 3], "expected index, got {actual}");
31+
assert.deepEqual(tt, [t, t, t, t], "expected this, got {actual}");
32+
},
33+
34+
"angle defaults to a function accessor": function(line) {
35+
var l = line();
36+
assert.pathEqual(l([[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-10L16.82941969615793,-10.806046117362794L18.185948536513635,8.32293673094285L1.4112000805986715,9.899924966004454");
37+
assert.typeOf(l.angle(), "function");
38+
},
39+
"angle can be defined as a constant": function(line) {
40+
var l = line().angle(Math.PI / 2);
41+
assert.pathEqual(l([[10, 0], [20, 1], [20, 2], [10, 3]]), "M10,0L20,0L20,0L10,0");
42+
assert.equal(l.angle(), Math.PI / 2);
43+
},
44+
"angle can be defined as a function": function(line) {
45+
var l = line().angle(f), t = {}, dd = [], ii = [], tt = [];
46+
function f(d, i) { dd.push(d); ii.push(i); tt.push(this); return Math.PI / 2; }
47+
assert.pathEqual(l.call(t, [[10, 0], [20, 1], [20, 2], [10, 3]]), "M10,0L20,0L20,0L10,0");
48+
assert.deepEqual(dd, [[10, 0], [20, 1], [20, 2], [10, 3]], "expected data, got {actual}");
49+
assert.deepEqual(ii, [0, 1, 2, 3], "expected index, got {actual}");
50+
assert.deepEqual(tt, [t, t, t, t], "expected this, got {actual}");
51+
},
52+
"angle is defined in radians, with zero at 12 o'clock": function(line) {
53+
var l = line().angle(0);
54+
assert.pathEqual(l([[10, Math.PI], [20, Math.PI / 3]]), "M0,-10L0,-20");
55+
assert.equal(l.angle(), 0);
56+
},
57+
58+
"interpolate defaults to linear": function(line) {
59+
assert.equal(line().interpolate(), "linear");
60+
},
61+
"interpolate can be defined as a constant": function(line) {
62+
var l = line().interpolate("cardinal");
63+
assert.pathEqual(l([[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-10Q15.010824842506567,-12.638339790457078,16.82941969615793,-10.806046117362794C19.557311976634978,-8.057605607721365,20.498681478847523,5.217041068437762,18.185948536513635,8.32293673094285Q16.64412657495771,10.393533839279574,1.4112000805986715,9.899924966004454");
64+
assert.equal(l.interpolate(), "cardinal");
65+
},
66+
67+
// We could test the other interpolation modes here, but that'd be redundant.
68+
69+
"tension defaults to .7": function(line) {
70+
assert.equal(line().tension(), .7);
71+
},
72+
"tension can be specified as a constant": function(line) {
73+
var l = line().tension(.5);
74+
assert.equal(l.tension(), .5);
75+
},
76+
77+
"returns null if input points array is empty": function(line) {
78+
assert.isNull(line()([]));
79+
}
80+
}
81+
});
82+
83+
suite.export(module);

test/svg/line-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ suite.addBatch({
7171
assert.isNull(line()([]));
7272
},
7373

74+
"interpolate(linear)": {
75+
"supports linear interpolation": function(line) {
76+
var l = line().interpolate("linear");
77+
assert.pathEqual(l([[0, 0], [1, 1], [2, 0], [3, 1], [4, 0]]), "M0,0L1,1L2,0L3,1L4,0");
78+
}
79+
},
80+
7481
"interpolate(step)": {
7582
"supports step-before interpolation": function(line) {
7683
var l = line().interpolate("step-before");

0 commit comments

Comments
 (0)