forked from mpl-annf/mpl-annf.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
167 lines (167 loc) · 6.14 KB
/
index.html
File metadata and controls
167 lines (167 loc) · 6.14 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
165
166
167
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Approximate Nearest Neighbor Field</title>
<script type="text/javascript" src="d3.js"></script>
</head>
<script type="text/javascript">
d3.csv("vis.csv", function(data) {
var dot_data = Array();
var line_data = Array();
var field_with_line_data = Array();
// Data filtering and clustering.
for (idx = 0; idx < data.length; idx++) {
data[idx]["X1"] = parseFloat( data[idx]["X1"] );
data[idx]["Y1"] = parseFloat( data[idx]["Y1"] );
data[idx]["X2"] = parseFloat( data[idx]["X2"] );
data[idx]["Y2"] = parseFloat( data[idx]["Y2"] );
data[idx]["XMid"] = parseFloat( data[idx]["XMid"] );
data[idx]["YMid"] = parseFloat( data[idx]["YMid"] );
data[idx]["X3"] = parseFloat( data[idx]["X3"] );
data[idx]["Y3"] = parseFloat( data[idx]["Y3"] );
data[idx]["X4"] = parseFloat( data[idx]["X4"] );
data[idx]["Y4"] = parseFloat( data[idx]["Y4"] );
data[idx]["X5"] = parseFloat( data[idx]["X5"] );
data[idx]["Y5"] = parseFloat( data[idx]["Y5"] );
data[idx]["X6"] = parseFloat( data[idx]["X6"] );
data[idx]["Y6"] = parseFloat( data[idx]["Y6"] );
if (data[idx]["Label1"] == "Dot")
dot_data.push(data[idx]);
else if (data[idx]["Label1"] == "Line")
line_data.push(data[idx]);
else if (data[idx]["Label1"] == "Field"){
if(data[idx]["Label2"] == "Line")
field_with_line_data.push(data[idx]);
}
}
// Setup SVG canvas.
var size = 4500;
var x_threshold = 2350;
var y_threshold = 2100;
var svg1 = d3.select("body")
.append("svg")
.attr("width", size)
.attr("height", size);
// Reverse y axis to fit the convention followed by SVG formate and code.
var y_scale = d3.scaleLinear()
.domain([0, 5000])
.range([5000, 0])
// Setup the background color.
svg1.selectAll("background")
.data([1])
.enter()
.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", size)
.attr("height", size)
.attr("fill", "white");
// Draw the Approximate Nearest Neighbor Field.
// moves the grey square subfields
svg1.selectAll("field_with_line")
.data(field_with_line_data)
.enter()
.append("rect")
.attr("x", function(d) { return d["X1"] / 10 - 3350 + x_threshold; })
.attr("y", function(d) { return y_scale(d["Y1"] / 10) - (d["Y2"] - d["Y1"]) / 10 - 2600 + y_threshold; })
.attr("width", function(d) { return (d["X2"] - d["X1"]) / 10; })
.attr("height", function(d) { return (d["Y2"] - d["Y1"]) / 10; })
.attr("style", "stroke:white")
.attr("stroke-width", 2)
.attr("fill", "grey")
.attr("opacity", 0.25)
.on("mouseover", function(d) {
d3.select(this)
.transition()
.duration(1000)
.attr("opacity", 0.8);
// a part of "X"
svg1.append("line")
.attr("id", "name1")
.attr("style", "stroke:white")
.attr("stroke-width", 2)
.attr("x1", d["XMid"] / 10 - 3350 + x_threshold)
.attr("y1", y_scale(d["YMid"] / 10) - 2600 + y_threshold)
.attr("x2", d["XMid"] / 10 - 3350 + x_threshold)
.attr("y2", y_scale(d["YMid"] / 10) - 2600 + y_threshold)
.transition()
.duration(1000)
.attr("x1", d["XMid"] / 10 - 5 - 3350 + x_threshold)
.attr("y1", y_scale(d["YMid"] / 10) - 5 - 2600 + y_threshold)
.attr("x2", d["XMid"] / 10 + 5 - 3350 + x_threshold)
.attr("y2", y_scale(d["YMid"] / 10) + 5 - 2600 + y_threshold);
// nearest element
svg1.append("line")
.attr("id", "name0")
.attr("x1", d["X3"] / 10 - 3350 + x_threshold)
.attr("y1", y_scale(d["Y3"] / 10) - 2600 + y_threshold)
.attr("x2", d["X4"] / 10 - 3350 + x_threshold)
.attr("y2", y_scale(d["Y4"] / 10) - 2600 + y_threshold)
.attr("style", "stroke:black")
.attr("stroke-width", 2.5)
.transition()
.duration(1000)
.attr("style", "stroke:royalblue")
.attr("stroke-width", 3.5);
// second nearest element
svg1.append("line")
.attr("id", "name0")
.attr("x1", d["X5"] / 10 - 3350 + x_threshold)
.attr("y1", y_scale(d["Y5"] / 10) - 2600 + y_threshold)
.attr("x2", d["X6"] / 10 - 3350 + x_threshold)
.attr("y2", y_scale(d["Y6"] / 10) - 2600 + y_threshold)
.attr("style", "stroke:black")
.attr("stroke-width", 2.5)
.transition()
.duration(1000)
.attr("style", "stroke:hotpink")
.attr("stroke-width", 3.5);
// another part of "X"
svg1.append("line")
.attr("id", "name1")
.attr("style", "stroke:white")
.attr("stroke-width", 2)
.attr("x1", d["XMid"] / 10 - 3350 + x_threshold)
.attr("y1", y_scale(d["YMid"] / 10) - 2600 + y_threshold)
.attr("x2", d["XMid"] / 10 - 3350 + x_threshold)
.attr("y2", y_scale(d["YMid"] / 10) - 2600 + y_threshold)
.transition()
.duration(1000)
.attr("x1", d["XMid"] / 10 + 5 - 3350 + x_threshold)
.attr("y1", y_scale(d["YMid"] / 10) - 5 - 2600 + y_threshold)
.attr("x2", d["XMid"] / 10 - 5 - 3350 + x_threshold)
.attr("y2", y_scale(d["YMid"] / 10) + 5 - 2600 + y_threshold);
})
.on("mouseout", function(d) {
d3.select(this)
.transition()
.duration(500)
.attr("opacity", 0.2);
svg1.selectAll("#name0")
.transition()
.duration(500)
.attr("stroke-width", 0)
.remove();
svg1.selectAll("#name1")
.transition()
.duration(500)
.attr("stroke-width", 0)
.remove();
});
// Draw the basic elements.
// black lines on ANNF
svg1.selectAll("line")
.data(line_data)
.enter()
.append("line")
.attr("x1", function(d) { return d["X1"] / 10 - 3350 + x_threshold; })
.attr("y1", function(d) { return y_scale(d["Y1"] / 10) - 2600 + y_threshold; })
.attr("x2", function(d) { return d["X2"] / 10 - 3350 + x_threshold; })
.attr("y2", function(d) { return y_scale(d["Y2"] / 10) - 2600 + y_threshold; })
.attr("style", "stroke:black")
.attr("stroke-width", 2);
});
</script>
</body>
</html>