Skip to content

Commit 995c70c

Browse files
committed
simple test coverage of d3.svg.diagonal
1 parent aa18d82 commit 995c70c

1 file changed

Lines changed: 46 additions & 1 deletion

File tree

test/svg/diagonal-test.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,54 @@ suite.addBatch({
1010
"diagonal": {
1111
topic: load("svg/diagonal").expression("d3.svg.diagonal"),
1212

13-
"x defaults to a function accessor": function(diagonal) {
13+
"source defaults to a function accessor": function(diagonal) {
14+
var d = diagonal().target({x:5, y:5});
15+
assert.pathEqual(d({source: {x:1, y:1}}), "M1,1C1,3 5,3 5,5");
16+
assert.pathEqual(d({source: {x:5, y:1}}), "M5,1C5,3 5,3 5,5");
17+
},
18+
"source can be defined as a constant": function(diagonal) {
19+
var d = diagonal().target({x:5, y:5});
20+
assert.pathEqual(d.source({x:1, y:1})(), "M1,1C1,3 5,3 5,5");
21+
assert.pathEqual(d.source({x:5, y:1})(), "M5,1C5,3 5,3 5,5");
22+
},
23+
"source can be defined as a function of data or index": function(diagonal) {
24+
var d = diagonal().source(f).target({x:5, y:5}), o = {}, t = {}, dd, ii, tt;
25+
function f(d,i) { dd = d; ii = i; tt = this; return {x:42, y:42}; }
26+
assert.pathEqual(d.call(t, o, 2), "M42,42C42,23.500000 5,23.500000 5,5");
27+
28+
assert.equal(dd, o, "expected data, got {actual}");
29+
assert.equal(ii, 2, "expected data, got {actual}");
30+
assert.equal(tt, t, "expected data, got {actual}");
31+
},
32+
"target defaults to a function accessor": function(diagonal) {
33+
var d = diagonal().source({x:1, y:1});
34+
assert.pathEqual(d({target: {x:5, y:5}}), "M1,1C1,3 5,3 5,5");
35+
assert.pathEqual(d({target: {x:5, y:1}}), "M1,1C1,1 5,1 5,1");
36+
},
37+
"target can be defined as a constant": function(diagonal) {
38+
var d = diagonal().source({x:1, y:1});
39+
assert.pathEqual(d.target({x:5, y:5})(), "M1,1C1,3 5,3 5,5");
40+
assert.pathEqual(d.target({x:5, y:1})(), "M1,1C1,1 5,1 5,1");
41+
},
42+
"target can be defined as a function of data or index": function(diagonal) {
43+
var d = diagonal().source({x:1, y:1}).target(f), o = {}, t = {}, dd, ii, tt;
44+
function f(d,i) { dd = d; ii = i; tt = this; return {x:42, y:42}; }
45+
assert.pathEqual(d.call(t, o, 2), "M1,1C1,21.500000 42,21.500000 42,42");
46+
47+
assert.equal(dd, o, "expected data, got {actual}");
48+
assert.equal(ii, 2, "expected data, got {actual}");
49+
assert.equal(tt, t, "expected data, got {actual}");
50+
},
51+
"projection defaults to identity": function(diagonal) {
1452
var d = diagonal();
53+
assert.deepEqual(d.projection()({x:1, y:1}),[1, 1]);
1554
},
55+
"custom projection function can be set": function(diagonal) {
56+
var d = diagonal().source({x:1, y:1}).target({x:5, y:5});
57+
assert.pathEqual(d.projection(function(d) {
58+
return [d.x * 2, d.y * 2];
59+
})(),"M2,2C2,6 10,6 10,10");
60+
}
1661
}
1762
});
1863

0 commit comments

Comments
 (0)