-
Notifications
You must be signed in to change notification settings - Fork 1
/
list.js
135 lines (117 loc) · 3.46 KB
/
list.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
var elemTopData,
metaTopData;
// dispatch.on("dataLoaded.list", function(meta, metaTop, metaTopGenre, elemDistTop, elemTop){
dispatch.on("dataLoaded.list",function(allData){
var metaTop = allData.metaTop,
metaTopGenre = allData.metaTopGenre,
elemTop = allData.elemTop,
elemDistTop = allData.elemDistTop;
elemTopData = elemTop;
metaTopData = metaTop;
list = d3.select("#column-right").select(".list")
.selectAll(".collection")
.data(metaTop);
list.exit().remove();
listEnter = list.enter()
.append('li')
.attr("class","collection");
list.merge(listEnter)
.html(function(d){ return "<b>Title:</b> " + d.title + " <br> <b>Author:</b> " + d.author})
.attr("id", function(d){ return d.filename; })
.style("color", function(d) {return scaleColor(d.genre); })
.style("opacity", 0.8);
var i = 0;
d3.selectAll(".collection")
.on("mouseenter",function(d){
dispatch.call("highlight", null, d, i);
// d3.select(this)
// .style("font-weight","bold");
})
.on("mouseleave",function(d){
dispatch.call("unhighlight", null, d);
})
.on("click",function(d){
window.open(d.url);
});
});
dispatch.on("highlight.list", function(d,i){
// d3.selectAll(".collection")
// .filter(function(e){
// if(d.filename == e.filename){ console.log("they match!");}
// return d.filename == e.filename; })
// .classed("selectedItem",true); //don't think this happens
d3.selectAll(".collection")
.transition()
.duration(100)
// .style("font-weight",function(e){
// if(d.filename == e.filename){
// return "bold";
// }
// })
.style("opacity",function(e){
if(d.filename != e.filename){
return 0.2;
}
// else{ console.log(d.title); }
});
if(i == 1){
var list = document.getElementById("list"),
targetli = document.getElementById(d.filename);
list.scrollTop = targetli.offsetTop - 298; //298 is offsetTop for the first element
}
});
dispatch.on("highlightmeta.list",function(d,i){
d3.selectAll(".collection")
.transition()
.duration(100)
.style("display",function(e){
if((e.isTop == 1) && (e.mainGenre == d.key)){
return "list-item";
}
else{ return "none"; }
});
// .style("opacity",function(e){
// if((e.isTop == 1) && (e.mainGenre == d.key)){
// return 1;
// }
// else{ return 0.2; }
// });
});
dispatch.on("highlightelem.list",function(d,i){
var idSet = new Set();
elemTopData.forEach(function(e){
if(d.key == e.element){ idSet.add(e.filename); }
});
d3.selectAll(".collection")
.transition()
.duration(100)
.style("display",function(e){
if((e.isTop == 1) && (idSet.has(e.filename))){
return "list-item";
}
else{ return "none"; }
});
// .style("opacity",function(e){
// if((e.isTop == 1) && (idSet.has(e.filename))){
// return 1;
// }
// else{ return 0.2; }
// });
});
dispatch.on("unhighlight.list", function(d){
// d3.selectAll("collection")
// .classed("selectedItem",false);
d3.selectAll(".collection")
.transition()
.duration(200)
// .style("font-weight","normal")
.style("display","list-item")
.style("opacity",1);
});
// dispatch.on("filterlistmeta", function(d){
// d3.selectAll(".collection")
// .filter(function(e){ return e.mainGenre != d.key})
// .transition()
// .duration(200)
// .style("display","none");
// });