-
Notifications
You must be signed in to change notification settings - Fork 1
/
Force-Directed Graph Sample.html
42 lines (39 loc) · 1.18 KB
/
Force-Directed Graph Sample.html
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
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/coffeescript"></script>
<script>
# Removes nodes from input array
# based on current filter setting.
# Returns array of nodes
filterNodes = (allNodes) ->
filteredNodes = allNodes
if filter == "popular" or filter == "obscure"
playcounts = allNodes.map((d) -> d.playcount).sort(d3.ascending)
cutoff = d3.quantile(playcounts, 0.5)
filteredNodes = allNodes.filter (n) ->
if filter == "popular"
n.playcount > cutoff
else if filter == "obscure"
n.playcount <= cutoff
filteredNodes
# Public function to update highlighted nodes from search
network.updateSearch = (searchTerm) ->
searchRegEx = new RegExp(searchTerm.toLowerCase())
node.each (d) ->
element = d3.select(this)
match = d.name.toLowerCase().search(searchRegEx)
if searchTerm.length > 0 and match >= 0
element.style("fill", "#F38630")
.style("stroke-width", 2.0)
.style("stroke", "#555")
d.searched = true
else
d.searched = false
element.style("fill", (d) -> nodeColors(d.artist))
.style("stroke-width", 1.0)
</script>
</body>
</html>