-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
78 lines (58 loc) · 2.03 KB
/
main.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
let state = {
depth:0,
data:null,
unchangeableData:[]
}
//Read the data
d3.csv("./pca_4.csv", function (data) {
state.unchangeableData = data.filter(function (d) {
return d.budget > 35000000 && d.gross < 381000000 && d.gross > 1500000
})
state.data = state.unchangeableData
initScatterplot(state.unchangeableData)
createSunburstVisualization(state.unchangeableData);
createBubbleVizualization(state.unchangeableData)
initMovieList(state.unchangeableData)
})
function updateData(labels, names){
let newData = state.data
let replace = false
if (state.depth > labels.length) {
let ogData = state.unchangeableData
let tempData = ogData.filter(function (d, i) {
return newData.indexOf(d) < 0
})
replace = true
newData = filter(labels, names, tempData)
}
else if (state.depth < labels.length) {
newData = filter(labels, names, newData)
state.data = newData
}
state.depth = labels.length
//state.data = newData
updateBubble(newData, replace)
updateList(newData, replace)
updateScatterData(newData, replace)
return newData
}
function filter(labels, names, newData){
if (labels.length == 1) {
newData = newData.filter(function (d) {
return (d[labels[0]] == names[0]);
})
}else if(labels.length == 2) {
let scoreArray = names[1].split('-');
let intArray = [parseInt(scoreArray[0]),parseInt(scoreArray[1])]
newData = newData.filter(function (d) {
return (d[labels[0]] == names[0] && (d[labels[1]] <= intArray[1] && d[labels[1]] >= intArray[0]))
})
}else if(labels.length == 3) {
let scoreArray = names[1].split('-');
let intArray = [parseInt(scoreArray[0]),parseInt(scoreArray[1])]
newData = newData.filter(function (d) {
return (d[labels[2]] == names[2] && d[labels[0]] == names[0] && (d[labels[1]] <= intArray[1] && d[labels[1]] >= intArray[0]))
})
}
return newData
}