forked from dc-js/dc.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbubble-overlay-test.js
94 lines (86 loc) · 4.21 KB
/
bubble-overlay-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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
require("./env");
var vows = require('vows');
var assert = require('assert');
var suite = vows.describe('Bubble overlay chart');
suite.addBatch({
'creation': {
topic: function() {
var id = "bubble-overlay";
var div = d3.select("body").append("div").attr("id", id);
var svg = div.append("svg");
var chart = dc.bubbleOverlay("#" + id)
.svg(svg)
.dimension(stateDimension)
.group(stateValueSumGroup)
.transitionDuration(0)
.title(function(d){return "Title: " + d.key;})
.r(d3.scale.linear().domain([0, 500]))
.colors(['blue'])
.point("California", 100, 120)
.point("Colorado", 300, 120)
.point("Delaware", 500, 220)
.point("Ontario", 180, 90)
.point("Mississippi", 120, 220)
.point("Oklahoma", 200, 350);
chart.render();
return chart;
},
'an instance of dc chart should be generated':function(chart){
assert.isTrue(dc.instanceOfChart(chart));
},
'should be registered':function(chart) {
assert.isTrue(dc.hasChart(chart));
},
'correct number of overlay g should be generated':function(chart){
assert.equal(chart.selectAll("g.node")[0].length, 6);
},
'correct class name for overlay g should be generated':function(chart){
assert.equal(d3.select(chart.selectAll("g.node")[0][0]).attr("class"), "node california");
assert.equal(d3.select(chart.selectAll("g.node")[0][3]).attr("class"), "node ontario");
},
'correct number of overlay bubble should be generated':function(chart){
assert.equal(chart.selectAll("circle.bubble")[0].length, 6);
},
'correct translate for overlay g should be generated':function(chart){
assert.equal(d3.select(chart.selectAll("g.node")[0][0]).attr("transform"), "translate(100,120)");
assert.equal(d3.select(chart.selectAll("g.node")[0][3]).attr("transform"), "translate(180,90)");
},
'correct translate for circle should be generated':function(chart){
assert.equal(d3.select(chart.selectAll("circle.bubble")[0][0]).attr("r"), "25.4");
assert.equal(d3.select(chart.selectAll("circle.bubble")[0][3]).attr("r"), "17.7");
},
'correct label should be generated':function(chart){
assert.equal(d3.select(chart.selectAll("g.node text")[0][0]).text(), "California");
assert.equal(d3.select(chart.selectAll("g.node text")[0][3]).text(), "Ontario");
},
'label should only be generated once':function(chart){
chart.redraw();
assert.equal(chart.selectAll("g.node text")[0].length, 6);
},
'correct title should be generated':function(chart){
assert.equal(d3.select(chart.selectAll("g.node title")[0][0]).text(), "Title: California");
assert.equal(d3.select(chart.selectAll("g.node title")[0][3]).text(), "Title: Ontario");
},
'title should only be generated once':function(chart){
chart.redraw();
assert.equal(chart.selectAll("g.node title")[0].length, 6);
},
'correct color for circle should be filled':function(chart){
assert.equal(d3.select(chart.selectAll("circle.bubble")[0][0]).attr("fill"), "blue");
assert.equal(d3.select(chart.selectAll("circle.bubble")[0][3]).attr("fill"), "blue");
},
'correct bubble should be highlighted when filter is active':function(chart){
chart.filter("Colorado");
chart.filter("California");
chart.redraw();
assert.equal(d3.select(chart.selectAll("g.node")[0][0]).attr("class"), "node california selected");
assert.equal(d3.select(chart.selectAll("g.node")[0][1]).attr("class"), "node colorado selected");
assert.equal(d3.select(chart.selectAll("g.node")[0][3]).attr("class"), "node ontario deselected");
},
'teardown': function() {
resetAllFilters();
resetBody();
}
}
});
suite.export(module);