-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpack_clusters.js
149 lines (128 loc) · 4.67 KB
/
pack_clusters.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
var diameter = 960,
format = d3.format(",d"),
dataSource;
var body = d3.select("body");
var pack = d3.layout.pack()
.size([diameter - 4, diameter - 4])
.children(function(d) {
return d.values; // accessor for children
})
.padding(4)
.value(function(d) { return 4; });
var svg = body.append("svg")
.attr("width", diameter)
.attr("height", diameter)
.append("g")
.attr("transform", "translate(2,2)");
d3.csv("testing.csv", function(error, csvData) {
if (error) throw error;
function getData(sort_by) {
if(!sort_by){
var jazzdata = { name: "jazzsolos", values: csvData };
return jazzdata;
} else {
var column = sort_by;
var data = d3.nest()
.key(function(d) { return d[column]; })
.entries(csvData);
var jazzdata = { name: "jazzsolos", values: data };
return jazzdata;
};
};
var data = getData();
var nodes = svg.datum(data).selectAll(".node")
.data(pack.nodes)
.enter()
.append("g");
var titles = nodes.append("title")
.attr("x", function(d) { return d.x; })
.attr("y", function(d) { return d.y; })
.text(function(d) { return d.title; });
var circles = nodes.append("circle")
.attr("stroke", "black")
.attr("class", function(d) { return !d.children ? "leaf" : "non-leaf"; })
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
.attr("r", function(d) { return d.r; })
.on("mouseover", function() {
d3.select(this).classed("active",
function(d) {
return !d.children ? true : false
});
})
.on("mouseout", function(){
d3.select(this).classed("active", false);
});
circles.on("click", function() {
d3.select(this).transition().attr("r", 100);
});
function updateVis() {
if (dataSource == 0) {
pack.value(function(d) { return 4; });
var data1 = pack.nodes(getData("style"));
}
if (dataSource == 1) {
pack.value(function(d) { return 4; });
var data1 = pack.nodes(getData("performer"));
}
if (dataSource == 2) {
pack.value(function(d) { return 4; });
var data1 = pack.nodes(getData("instrument"));
}
if (dataSource == 3) {
pack.value(function(d) { return 4; });
var data1 = pack.nodes(getData("tempoclass"));
}
if (dataSource == 4) {
pack.value(function(d) { return 4; });
var data1 = pack.nodes(getData("rhythmfeel"));
}
if (dataSource == 5) {
pack.value(function(d) { return 4; });
var data1 = pack.nodes(getData("key"));
}
if (dataSource == 6) {
pack.value(function(d) { return 4; });
var data1 = pack.nodes(getData("chorus_count"));
}
if (dataSource == 7) {
pack.value(function(d) { return 4; });
var data1 = pack.nodes(data);
};
titles.attr("x", function(d) { return d.x; })
.attr("y", function(d) { return d.y; })
.text(function(d) { return d.title; });
circles.transition()
.duration(5000)
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
.attr("r", function(d) { return d.r; });
};
var buttonData = ["Style", "Performer", "Instrument", "Tempo Class", "Rhythm Feel", "Key", "Chorus Count", "Release"];
var buttonDiv = d3.select("body").append("svg")
.attr("width", diameter + 50)
.attr("height", 50);
var buttons = buttonDiv.selectAll(".updateButton")
.data(buttonData)
.enter()
.append('g')
.attr("class", "updateButton")
.on("click", function(d, i) {
dataSource = i;
updateVis();
});
buttons.append("rect")
.attr("x", function(d, i) { return (i * 110) + 100; })
.attr("width", 110)
.attr("height", 35)
.attr("ry", 5)
.style("stroke", "#787878")
.style("fill", "tan");
buttons.append("text")
.attr("x", function(d, i) { return (i * 110) + (100 / 2) + 98; })
.attr("y", 12)
.attr("dy", "0.35em")
.style("text-anchor", "middle")
.style("font-size", "15px")
.text(function(d) { return d; });
});