-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathveg.js
87 lines (58 loc) · 2.09 KB
/
veg.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
var vegetate = function() {
if (verbose) { console.log('vegetate'); }
// document.getElementById("plant").value = "Stop planting";
// document.getElementById("plant").onclick = function() {stopVeg();};
document.getElementById("plant").disabled = true;
document.getElementById("noplant").disabled = false;
var nearby = [];
svg.selectAll("path")
.on("mouseover", function(d, i) {
nearby = []
svg.selectAll(".detectable").each(function () {
if (neighboring(i, this.id) | neighboring(this.id,i)){
nearby.push(this.id);
}
})
for (var j = 0; j<nearby.length; j++){
svg.select('path#path-'+nearby[j])
.style('fill', function(d,i) {return greens(pts[nearby[j]].veg+1)});
}})
.on("mousedown", function(d,i) {
for (var j = 0; j<nearby.length; j++){
pts[nearby[j]].veg++;
colors[nearby[j]] = greens(pts[nearby[j]].veg)
}
path.style("fill", function(d, i) { return colors[i] });
})
.on("mouseout", function(d, i) {
path.style("fill", function(d, i) { return colors[i] });
});
var linkedByIndex = {};
for (i = 0; i < pts.length; i++) { linkedByIndex[i + "," + i] = 1; }
d3_geom_voronoi.links(pts).forEach(function (d) {
linkedByIndex[d.source.k + "," + d.target.k] = 1;
});
function neighboring(a, b) { return linkedByIndex[a + "," + b]; }
}
// var stopVeg = function() {
//
// if (verbose) { console.log('stopVeg'); }
//
// document.getElementById("plant").value = "Click to plant more vegetation";
// document.getElementById("plant").onclick = function() {vegetate();};
//
// svg.selectAll("path")
// .on("click", function(d, i) {if (pts[i].veg>3) { pts[i].veg = 3;}})
//
// }
//
var resetVeg = function() {
if (verbose) { console.log('resetVeg'); }
for (var i=0; i<pts.length; i++){ pts[i].veg = 0; }
document.getElementById("plant").value = "Click to plant vegetation";
document.getElementById("plant").onclick = function() {vegetate();};
document.getElementById("noplant").disabled = true;
document.getElementById("plant").disabled = false;
svg.selectAll("path").on("click", function(d, i) {})
draw_initial();
}