-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvis.js
More file actions
165 lines (138 loc) · 4.51 KB
/
vis.js
File metadata and controls
165 lines (138 loc) · 4.51 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
var dataset;
d3.csv("executionscor2.csv", function(error, data) {
if (error) { //If error is not null, something went wrong.
console.log(error); //Log the error.
} else { //If no error, the file loaded correctly. Yay!
dataset = data;
console.log(dataset); //Log the data.
generateVis();
// hideLoadingMsg();
}
});
var w = 1000;
var h = 800;
function generateVis() {
var xScale = d3.scale.ordinal()
.domain(d3.range(dataset.length))
.rangeRoundBands([0, w], 0.05);
var yScale = d3.scale.linear()
.domain([0, d3.max(dataset)])
.range([0, h]);
//Create SVG element
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
svg.selectAll("circle")
.data(dataset)
.enter()
.append("circle")
.attr("cx", function(d) {
return 900*Number(d.xcor) + 220;
})
.attr("cy", function(d) {
return 900*Number(d.ycor) + 360;
})
.attr("r", 4)
//.style.visibility = "visible";
//.attr("visibility", "visible")
.attr("fill", function(d) {
return d.typecol;
})
.attr("width", xScale.rangeBand())
.attr("height", function(d) {
return yScale(d);
})
.on("mouseover",function(d) {
console.log(d.num);
d3.select(this)
.attr("fill", "black")
var xPosition = parseFloat(d3.select(this).attr("x")) + xScale.rangeBand() / 2;
var yPosition = parseFloat(d3.select(this).attr("y")) / 2 + h / 2;
//Update the tooltip position and value
// d3.select("#tooltip")
// .select("#value")
// .text(d.LastS);
// .text(function(d) {
//
// });
if (d.Type != "laststatement") {
d3.select("#tooltip")
.select("#value")
.text(d.Type);
} else {
d3.select("#tooltip")
.select("#value")
.text(d.LastS);
}
if (d.form != "y") {
changeimage(d.image);
} else {
changeimage("nophoto.jpg");
}
//Show the tooltip
d3.select("#tooltip").classed("hidden", false);
})
.on("mouseout",function(d) {
//console.log(d.num);
d3.select(this)
.attr("fill", function(d) {
return d.typecol;
})
//Hide the tooltip
d3.select("#tooltip").classed("hidden", true);
});
d3.select("#button1")
.on("click", function(d) {
svg.selectAll("circle")
.attr("visibility", "hidden");
// if (svg.selectAll("circle").style.visibility == "visible") {
// console.log(svg.selectAll("circle").style.visibility);
// svg.selectAll("circle")
// .attr("visibility", "hidden");
// } else {
// console.log(svg.selectAll("circle").style.visibility);
// svg.selectAll("circle")
// .attr("visibility", "visible");
// }
})
d3.select("#button2")
.on("click", function(d) {
alert("hi");
})
d3.select("#button3")
.on("click", function(d) {
alert("hi");
})
}
function changeimage(d) {
document.getElementById("photo").src = d;
}
// function updateData() {
// // Select the section we want to apply our changes to
// var svg = d3.select("body").transition();
// // Make the changes
// svg.select("circle") // change the line
// .duration(750)
// .style.visibilty="hidden";
// svg.select(".x.axis") // change the x axis
// .duration(750)
// .call(xAxis);
// svg.select(".y.axis") // change the y axis
// .duration(750)
// .call(yAxis);
// });
// }
function addimage(d) {
// var newphoto = document.createElement("span");
// console.log(newphoto);
// document.getElementByID("photo").style.visibilty="visible";
var img = new Image();
img.src = d
photo.appendChild(img);
}
function removeimage(d) {
// var img = document.getElementById("photo");
// img.parentNode.removeChild(img);
// document.getElementByID("photo").style.visibilty="hidden";
}