-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsl.html
More file actions
168 lines (142 loc) · 3.51 KB
/
Copy pathsl.html
File metadata and controls
168 lines (142 loc) · 3.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
165
166
167
168
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<html>
<style>
svg {
background-color: ;
}
</style>
<div id="svg1">
</div>
<div id="svg2">
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<script>
function gew(attribute,val)
{
var matchingElements = [];
var allElements = document.getElementsByTagName('*');
for (var i = 0, n = allElements.length; i < n; i++)
{
if (allElements[i].getAttribute(attribute) !== null)
{
if(allElements[i].getAttribute(attribute) == val)
{
matchingElements.push(allElements[i]);
}
}
}
return matchingElements;
}
function myFunction()
{
var data;
d3.json("sl.php",function(error, data) {
console.log("ins");
console.log(data.nodes[1]);
var w = window.innerWidth;
var h = window.innerHeight;
var c10 = d3.scale.category10();
var svg = d3.select("#svg1")
.append("svg")
.attr("width", w/2)
.attr("height", h);
var links = svg.selectAll("link")
.data(data.links)
.enter()
.append("line")
.attr("class", "link")
.attr("x1", function(l) {
var sourceNode = data.nodes.filter(function(d, i) {
return i == l.source
})[0];
d3.select(this).attr("y1", sourceNode.y);
return sourceNode.x
})
.attr("x2", function(l) {
var targetNode = data.nodes.filter(function(d, i) {
return i == l.target
})[0];
d3.select(this).attr("y2", targetNode.y);
return targetNode.x
})
.attr("source_node", function(l) {
var sourceNode = data.nodes.filter(function(d, i) {
return i == l.source
})[0];
return sourceNode.name;
})
.attr("target_node", function(l) {
var targetNode = data.nodes.filter(function(d, i) {
return i == l.target
})[0];
return targetNode.name;
})
.attr("stroke", "black")
.attr("stroke-width", function(d) {
return d.value/150;
});
var c=5;
var elem = svg.selectAll("body")
.data(data.nodes)
elemEnter = elem.enter()
.append("g")
var nodes = svg.selectAll("node")
.data(data.nodes)
.enter()
.append("circle")
.attr("class", "node")
.attr("cx", function(d) {
// return (Math.random() * 400);
return d.x;
})
.attr("cy", function(d) {
//return (Math.random() * 300);
return d.y;
})
.attr("fill-opacity", 0.5)
.attr("r", 15)
.attr("nname",function(d) {return d.name;} )
.attr("fill", function(d, i) {
return c10(i);
})
.on("mouseover", function(){
var sn = gew("source_node",this.getAttribute("nname"));
var tn = gew("target_node",this.getAttribute("nname"));
var i=0
for(i=0;i<sn.length;i++)
{
sn[i].setAttribute("stroke", "red");
}
var i=0
for(i=0;i<tn.length;i++)
{
tn[i].setAttribute("stroke", "red");
}
})
.on("mouseout", function(){
var sn = gew("source_node",this.getAttribute("nname"));
var tn = gew("target_node",this.getAttribute("nname"));
var i=0
for(i=0;i<sn.length;i++)
{
sn[i].setAttribute("stroke", "black");
}
var i=0
for(i=0;i<tn.length;i++)
{
tn[i].setAttribute("stroke", "black");
}
});
elemEnter.append("text")
.attr("dx", function(d){return -20})
.text(function(d){return d.name})
.attr("font-size", "10px")
.attr("x",function(d) {return d.x;} )
.attr("y",function(d) {return d.y;} )
.attr("id",function(d) {return d.name;} );
// #####################################################################################
});
}
</script>
<body onload="myFunction()">
</html>