-
Notifications
You must be signed in to change notification settings - Fork 353
/
multiscale-test.js
64 lines (59 loc) · 1.99 KB
/
multiscale-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var vows = require("vows"),
d3 = require("d3"),
load = require("../load"),
assert = require("assert");
var suite = vows.describe('mpld3.path')
suite.addBatch({
"multiscale": {
topic: load("utils/util").document(),
"A multiscale object": {
topic: function(mpld3) {
return mpld3.multiscale(d3.scale.linear()
.domain([0, 1])
.range([10, 20]),
d3.scale.linear()
.domain([10, 20])
.range([100, 200]));
},
"has the expected domain": function(m){
assert.deepEqual(m.domain(), [0, 1]);
},
"has the expected range": function(m){
assert.deepEqual(m.range(), [100, 200]);
},
"converts from domain to range as expected": function(m){
assert.equal(m(0.5), 150);
}
},
"A modified multiscale object": {
topic: function(mpld3) {
var scale1 = d3.scale.linear()
.domain([0, 1])
.range([10, 20]);
var scale2 = d3.scale.linear()
.domain([10, 20])
.range([100, 200]);
return [scale1, scale2, mpld3.multiscale(scale1, scale2)];
},
"has the expected domain": function(tup){
var s1 = tup[0], s2 = tup[1], m = tup[2];
assert.deepEqual(m.domain(), s1.domain());
},
"has the expected range": function(tup){
var s1 = tup[0], s2 = tup[1], m = tup[2];
assert.deepEqual(m.range(), s2.range());
},
"correctly behaves when domain/range are modified": function(tup){
var s1 = tup[0], s2 = tup[1], m = tup[2];
// modify domain and range
m.domain([-1, 1]);
assert.deepEqual(m.domain(), s1.domain());
m.range([8, 16]);
assert.deepEqual(m.range(), s2.range());
// check the new multiscale mapping
assert.deepEqual(m(3.14), s2(s1(3.14)));
}
}
}
});
suite.export(module);