-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
135 lines (113 loc) · 3.51 KB
/
index.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
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
<html>
<head>
<style>
.line {
fill: none;
stroke: black;
}
.point {
fill: #999;
stroke: #fff;
}
.point.scanned {
fill: #23FF00;
stroke: #999;
}
.point.selected {
fill: red;
stroke: #999;
}
.halo {
fill: none;
stroke: red;
}
</style>
</head>
<body>
<script src="kd-tree.js"></script>
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>
var width = 1900,
height = 700;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var arrayData = new Array();
var archivoCsv = new XMLHttpRequest();
var fileRuta = 'iris.csv';
archivoCsv.open("GET", fileRuta, false);
archivoCsv.send(null);
var txt = archivoCsv.responseText;
const text = txt.split(",");
for (var i = 0; i < text.length-1; i=i+5) {
// !isNaN(text[i]*1)?arrayData.push(text[i]*1):arrayData.push((text[i]));
arrayData.push({
x:(text[i]*1),y:(text[i+1]*1),z:(text[i+2]*1),w:(text[i+3]*1),value:text[i+4]
})
}
// console.log(arrayData);
var data1 = arrayData.map(function (arrayData) {
return {
x: (width * arrayData.x)/10,
y: (height * arrayData.y)/10,
x: (width * arrayData.z)/10,
y: (height * arrayData.w)/10
//(value: d3.random.normal()()
};
});
//var data2 = arrayData.map(function (arrayData) {
// return {
// x: (width * arrayData.z)/10,
// y: (height * arrayData.w)/10,
// value: d3.random.normal()()
// };
//});
var data = data1//.concat(data2);
console.log(data)
// var data = d3.range(188)
// .map(function() {
// return {
// x: width * Math.random(),
// y: height * Math.random(),
// value: d3.random.normal()() // just for testing purposes
// };
// });
// console.log(data)
var tree = KDTree()
.x(function(d) { return d.x; })
.y(function(d) { return d.y; })
//.z(function(d) { return d.z; })
//.w(function(d) { return d.w; })
(data);
svg.append("g").attr("class", "lines")
.selectAll(".line").data(tree.lines([[0, 0], [width, height]]))
.enter().append("path")
.attr("class", "line")
.attr("d", d3.svg.line());
var points = svg.append("g").attr("class", "points")
.selectAll(".point").data(tree.flatten())
.enter().append("circle")
.attr("class", "point")
.attr("cx", function (d) { return d.location[0]; })
.attr("cy", function (d) { return d.location[1]; })
.attr("r", 5);
var halo = svg.append("circle").attr("class", "halo");
update([width / 2, height / 2]);
svg.append("rect").attr("class", "event-canvas")
.attr("width", width)
.attr("height", height)
.attr("fill-opacity", 0)
.on("mousemove", function () { update(d3.mouse(this)); });
function update(target) {
var nearest = tree.find(target, 1);
points
.classed("scanned", function (d) { return nearest.scannedNodes.indexOf(d) !== -1; })
.classed("selected", function (d) { return nearest.nearestNodes.indexOf(d) !== -1; });
halo
.attr("cx", target[0])
.attr("cy", target[1])
.attr("r", nearest.maxDistance);
}
</script>
</body>
</html>