3
var vows = require("vows"),
4
assert = require("assert");
6
var suite = vows.describe("d3.svg.area.radial");
11
return d3.svg.area.radial;
14
"radius is an alias for setting innerRadius and outerRadius": function(area) {
15
var a = area().radius(f);
17
assert.equal(a.radius(), f);
18
assert.equal(a.innerRadius(), f);
19
assert.equal(a.outerRadius(), f);
21
"radius is an alias for getting outerRadius": function(area) {
22
var a = area().outerRadius(f);
24
assert.equal(a.radius(), f);
27
"angle is an alias for setting startAngle and endAngle": function(area) {
28
var a = area().angle(f);
30
assert.equal(a.angle(), f);
31
assert.equal(a.startAngle(), f);
32
assert.equal(a.endAngle(), f);
34
"angle is an alias for getting endAngle": function(area) {
35
var a = area().endAngle(f);
37
assert.equal(a.angle(), f);
40
"innerRadius defaults to a function accessor": function(area) {
42
assert.pathEqual(a([[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-10L16.829420,-10.806046L18.185949,8.322937L1.411200,9.899925L0,-10L0,-20L0,-20L0,-10Z");
43
assert.typeOf(a.innerRadius(), "function");
45
"innerRadius can be defined as a constant": function(area) {
46
var a = area().innerRadius(30);
47
assert.pathEqual(a([[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-10L16.829420,-10.806046L18.185949,8.322937L1.411200,9.899925L0,-30L0,-30L0,-30L0,-30Z");
48
assert.equal(a.innerRadius(), 30);
50
"innerRadius can be defined as a function": function(area) {
51
var a = area().innerRadius(f), t = {}, dd = [], ii = [], tt = [];
52
function f(d, i) { dd.push(d); ii.push(i); tt.push(this); return 30; }
53
assert.pathEqual(a.call(t, [[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-10L16.829420,-10.806046L18.185949,8.322937L1.411200,9.899925L0,-30L0,-30L0,-30L0,-30Z");
54
assert.deepEqual(dd, [[10, 0], [20, 1], [20, 2], [10, 3]], "expected data, got {actual}");
55
assert.deepEqual(ii, [0, 1, 2, 3], "expected index, got {actual}");
56
assert.deepEqual(tt, [t, t, t, t], "expected this, got {actual}");
59
"outerRadius defaults to a function accessor": function(area) {
61
assert.pathEqual(a([[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-10L16.829420,-10.806046L18.185949,8.322937L1.411200,9.899925L0,-10L0,-20L0,-20L0,-10Z");
62
assert.typeOf(a.outerRadius(), "function");
64
"outerRadius can be defined as a constant": function(area) {
65
var a = area().outerRadius(30);
66
assert.pathEqual(a([[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-30L25.244130,-16.209069L27.278923,12.484405L4.233600,29.699775L0,-10L0,-20L0,-20L0,-10Z");
67
assert.equal(a.outerRadius(), 30);
69
"outerRadius can be defined as a function": function(area) {
70
var a = area().outerRadius(f), t = {}, dd = [], ii = [], tt = [];
71
function f(d, i) { dd.push(d); ii.push(i); tt.push(this); return 30; }
72
assert.pathEqual(a.call(t, [[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-30L25.244130,-16.209069L27.278923,12.484405L4.233600,29.699775L0,-10L0,-20L0,-20L0,-10Z");
73
assert.deepEqual(dd, [[10, 0], [20, 1], [20, 2], [10, 3]], "expected data, got {actual}");
74
assert.deepEqual(ii, [0, 1, 2, 3], "expected index, got {actual}");
75
assert.deepEqual(tt, [t, t, t, t], "expected this, got {actual}");
78
"startAngle defaults to zero": function(area) {
80
assert.pathEqual(a([[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-10L16.829420,-10.806046L18.185949,8.322937L1.411200,9.899925L0,-10L0,-20L0,-20L0,-10Z");
81
assert.equal(a.startAngle(), 0);
83
"startAngle can be defined as a constant": function(area) {
84
var a = area().startAngle(Math.PI / 2);
85
assert.pathEqual(a([[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-10L16.829420,-10.806046L18.185949,8.322937L1.411200,9.899925L10,0L20,0L20,0L10,0Z");
86
assert.equal(a.startAngle(), Math.PI / 2);
88
"startAngle can be defined as a function": function(area) {
89
var a = area().startAngle(f), t = {}, dd = [], ii = [], tt = [];
90
function f(d, i) { dd.push(d); ii.push(i); tt.push(this); return Math.PI / 2; }
91
assert.pathEqual(a.call(t, [[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-10L16.829420,-10.806046L18.185949,8.322937L1.411200,9.899925L10,0L20,0L20,0L10,0Z");
92
assert.deepEqual(dd, [[10, 0], [20, 1], [20, 2], [10, 3]], "expected data, got {actual}");
93
assert.deepEqual(ii, [0, 1, 2, 3], "expected index, got {actual}");
94
assert.deepEqual(tt, [t, t, t, t], "expected this, got {actual}");
97
"endAngle defaults to a function accessor": function(area) {
99
assert.pathEqual(a([[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-10L16.829420,-10.806046L18.185949,8.322937L1.411200,9.899925L0,-10L0,-20L0,-20L0,-10Z");
100
assert.typeOf(a.endAngle(), "function");
102
"endAngle can be defined as a constant": function(area) {
103
var a = area().endAngle(Math.PI / 2);
104
assert.pathEqual(a([[10, 0], [20, 1], [20, 2], [10, 3]]), "M10,0L20,0L20,0L10,0L0,-10L0,-20L0,-20L0,-10Z");
105
assert.equal(a.endAngle(), Math.PI / 2);
107
"endAngle can be defined as a function": function(area) {
108
var a = area().endAngle(f), t = {}, dd = [], ii = [], tt = [];
109
function f(d, i) { dd.push(d); ii.push(i); tt.push(this); return Math.PI / 2; }
110
assert.pathEqual(a.call(t, [[10, 0], [20, 1], [20, 2], [10, 3]]), "M10,0L20,0L20,0L10,0L0,-10L0,-20L0,-20L0,-10Z");
111
assert.deepEqual(dd, [[10, 0], [20, 1], [20, 2], [10, 3]], "expected data, got {actual}");
112
assert.deepEqual(ii, [0, 1, 2, 3], "expected index, got {actual}");
113
assert.deepEqual(tt, [t, t, t, t], "expected this, got {actual}");
116
"if innerRadius === outerRadius, radius is only evaluated once per point": function(area) {
117
var a = area().radius(f), t = {}, dd = [], ii = [], tt = [];
118
function f(d, i) { dd.push(d); ii.push(i); tt.push(this); return 30; }
119
assert.pathEqual(a.call(t, [[10, 0], [20, 1], [20, 2], [10, 3]]), "M0,-30L25.244130,-16.209069L27.278923,12.484405L4.233600,29.699775L0,-30L0,-30L0,-30L0,-30Z");
120
assert.deepEqual(dd, [[10, 0], [20, 1], [20, 2], [10, 3]], "expected data, got {actual}");
121
assert.deepEqual(ii, [0, 1, 2, 3], "expected index, got {actual}");
122
assert.deepEqual(tt, [t, t, t, t], "expected this, got {actual}");
124
"if startAngle === endAngle, angle is only evaluated once per point": function(area) {
125
var a = area().angle(f), t = {}, dd = [], ii = [], tt = [];
126
function f(d, i) { dd.push(d); ii.push(i); tt.push(this); return Math.PI / 2; }
127
assert.pathEqual(a.call(t, [[10, 0], [20, 1], [20, 2], [10, 3]]), "M10,0L20,0L20,0L10,0L10,0L20,0L20,0L10,0Z");
128
assert.deepEqual(dd, [[10, 0], [20, 1], [20, 2], [10, 3]], "expected data, got {actual}");
129
assert.deepEqual(ii, [0, 1, 2, 3], "expected index, got {actual}");
130
assert.deepEqual(tt, [t, t, t, t], "expected this, got {actual}");
133
"interpolate defaults to linear": function(area) {
134
assert.equal(area().interpolate(), "linear");
136
"interpolate can be defined as a constant": function(area) {
137
var a = area().interpolate("step-before");
138
assert.pathEqual(a([[0, 0], [1, 1]]), "M0,0V-0.540302H0.841471L0,-1H0V0Z");
139
assert.equal(a.interpolate(), "step-before");
142
"tension defaults to .7": function(area) {
143
assert.equal(area().tension(), .7);
145
"tension can be specified as a constant": function(area) {
146
var a = area().tension(.5);
147
assert.equal(a.tension(), .5);
150
"returns null if input points array is empty": function(area) {
151
assert.isNull(area()([]));
154
"interpolate(linear)": {
155
"supports linear interpolation": testInterpolation("linear")
158
"interpolate(step)": {
159
"supports step-before interpolation": testInterpolation("step-before"),
160
"supports step-after interpolation": testInterpolation("step-after")
163
"interpolate(basis)": {
164
"supports basis interpolation": testInterpolation("basis"),
165
"supports basis-open interpolation": testInterpolation("basis-open")
168
"interpolate(cardinal)": {
169
"supports cardinal interpolation": testInterpolation("cardinal"),
170
"supports cardinal-open interpolation": testInterpolation("cardinal-open")
173
"interpolate(monotone)": {
174
"supports monotone interpolation": testInterpolation("monotone")
179
// A radial area is just a transformation of a Cartesian line.
180
function testInterpolation(interpolate) {
181
var data = [[10, 0], [20, 1], [20, 2], [10, 3]];
183
var radial = d3.svg.area.radial()
184
.innerRadius(function(d) { return d[0]; })
185
.outerRadius(function(d) { return d[0] * 2; })
186
.angle(function(d) { return d[1]; });
188
var cartesian = d3.svg.area()
189
.x0(function(d) { return d[0] * Math.cos(d[1] - Math.PI / 2); })
190
.x1(function(d) { return 2 * d[0] * Math.cos(d[1] - Math.PI / 2); })
191
.y0(function(d) { return d[0] * Math.sin(d[1] - Math.PI / 2); })
192
.y1(function(d) { return 2 * d[0] * Math.sin(d[1] - Math.PI / 2); });
195
assert.pathEqual(radial.interpolate(interpolate)(data), cartesian.interpolate(interpolate)(data));
199
suite.export(module);