-
Notifications
You must be signed in to change notification settings - Fork 0
/
force25.html
426 lines (373 loc) · 13.8 KB
/
force25.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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<html>
<head>
<meta charset="utf-8">
<title>力导向图</title>
</head>
<style>
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>
var source1 = "mapping.csv";
var map = [];
var idornameflag = true;
var currentId = -100;
d3.csv(source1, function (error, csvdata) {
if (error) throw error;
for (var i = 0; i < csvdata.length; i++) {
map[csvdata[i].key] = csvdata[i].value;
}
});
function idorname(f) {
if (f == 1) idornameflag = true;
if (f == 2) idornameflag = false;
fun(currentId);
}
function output(chap, ans) {
var resulttext = "";
/*var url = location.search;
console.log(url);
var url = location.search;
var Request = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1) //去掉?号
var strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
Request[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}*/
/*var chap = 0;
chap = Request.chap;
var ans = Request.ans;*/
/*document.write(chap);
document.write(ans);*/
//alert("chap=" + chap);
var count = -1;
var flag = false;
var st = "[";
var source = "sa" + chap + ".txt";
//document.write(source);
d3.text(source, function (error, text) {
if (error) throw error;
var st1 = "";
for (var i = 0; i < text.length; i++) {
if (text[i] == '=') {
count++;
if (count == ans) flag = true;
}
if (flag) {
if (idornameflag == false) {
if (text[i] == "," || text[i] == "]") {
//console.log(st1);
if (text[i] != "]") st = st + map[parseInt(st1)] + ", "; else st = st + map[parseInt(st1)];
st1 = "";
} else {
if (text[i] != "[" && text[i] != "=") st1 = st1 + text[i];
}
//st = st + text[i];
if (text[i] == ']') break;
}else {
if (text[i] == "," || text[i] == "]") {
//console.log(st1);
if (text[i] != "]") st = st + st1 + ", "; else st = st + st1;
st1 = "";
} else {
if (text[i] != "[" && text[i] != "=") st1 = st1 + text[i];
}
//st = st + text[i];
if (text[i] == ']') break;
}
}
}
st = st + "]";
resulttext = resulttext + "Within " + chap + " nodes, node ";
resulttext = resulttext + ans;
resulttext = resulttext + " = " + st;
//console.log(resulttext);
var obj_label = document.getElementById("test");
obj_label.innerHTML = resulttext;
});
}
function fun(i) {
currentId = i;
if (i == -100) {
var obj_label = document.getElementById("test");
obj_label.innerHTML = "这里显示点压缩前的内容,把鼠标放在点上可以显示点的内容";
} else {
output(chap, i);
}
/*
var obj_label = document.getElementById("test");
obj_label.innerHTML = output(chap, i);*/
}
function fun2() {
var obj_text = document.getElementById("textArea").value;
console.log(obj_text);
if (obj_text == -100) {
var obj_label = document.getElementById("test");
obj_label.innerHTML = "这里显示点压缩前的内容,把鼠标放在点上可以显示点的内容";
} else {
output(chap, obj_text);
}
}
/*var nodes = [ { name: "0" }, { name: "1" },
{ name: "2" }, { name: "3" },
{ name: "4" }, { name: "5" },
{ name: "6" },{name: "0"} ];
var edges = [ { source : 0 , target: 1 } , { source : 0 , target: 2 } ,
{ source : 0 , target: 3 } , { source : 1 , target: 4 } ,{ source : 3 , target: 4 } ,
{ source : 1 , target: 5 } , { source : 1 , target: 6 } ];
edges[7]={ source : 7 , target: 0 };*/
//var url = location.search;
/*console.log(url);*/
var url = location.search;
var Request = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1) //去掉?号
var strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
Request[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
var chap = Request.chap;
if (chap == null) chap = 25;
var nodes = [];
var edges = [];
var flag = [];
for (var i = 0; i <= 200; i++) flag[i] = 0;
var source = "sa" + chap + ".csv";
d3.csv(source, function (error, csvdata) {
if (error) {
}
var max = 0;
for (var i = 0; i < csvdata.length; i++) {
var s = parseInt(csvdata[i].s);
var t = parseInt(csvdata[i].t);
/*var s1 = parseInt(csvdata[i].s1);
var s2 = parseInt(csvdata[i].s2);
var s3 = parseInt(csvdata[i].s3);
var s4 = parseInt(csvdata[i].s4);
var max1 = -1;
var t1 = parseInt(csvdata[i].t1);
var t2 = parseInt(csvdata[i].t2);
var t3 = parseInt(csvdata[i].t3);
var t4 = parseInt(csvdata[i].t4);
var max2 = -1;
if (s1 > max1) {
max1 = s1;
flag[s] = 1;
}
if (s2 > max1) {
max1 = s2;
flag[s] = 2;
}
if (s3 > max1) {
max1 = s3;
flag[s] = 3;
}
if (s4 > max1) {
max1 = s4;
flag[s] = 4;
}
if (t1 > max2) {
max2 = t1;
flag[t] = 1;
}
if (t2 > max2) {
max2 = t2;
flag[t] = 2;
}
if (t3 > max2) {
max2 = t3;
flag[t] = 3;
}
if (t4 > max2) {
max2 = t4;
flag[t] = 4;
}*/
if (s > max) max = s;
if (t > max) max = t;
flag[s]++;
flag[t]++;
edges[i] = {source: s, target: t};
//document.write(edges[i].source+"\n"+edges[i].target+"\n");
}
max = chap - 1;
for (var i = 0; i <= max; i++) {
nodes[i] = {name: i};
}
//求最大值和最小值
var maxvalue = max;
var minvalue = 0;
//定义一个线性比例尺,将最小值和最大值之间的值映射到[0, 1]
var linear = d3.scale.linear()
.domain([minvalue, maxvalue])
.range([0, 100]);
var a = d3.rgb(50, 55, 155); //浅蓝色
var b = d3.rgb(230, 60, 65); //蓝色
//颜色插值函数
var computeColor = d3.interpolate(a, b);
var col = [];
for (var i = 0; i <= max; i++) {
var t = linear(flag[i]);
col[i] = computeColor(t);
}
/*for (var i=0;i<=20000;i++)
{
if (flag[i]>1000) flag[i]=19; else
if (flag[i]>100) flag[i]=15; else
if (flag[i]>10) flag[i]=10; else
flag[i]=5;
}*/
/*var nodes=[];
var edges=[];
var max=1010;
for( var i=0; i<1000; i++ ){
var s = i;
var t = i+1;
if ( s>max ) max=s;
if ( t>max ) max=t;
edges[i]={ source : s , target: t };
//document.write(edges[i].source+"\n");
//document.write(edges[i]);
}
for (var i=0;i<=max;i++)
{
nodes[i]={ name: i };
}*/
var width = 2000;
var height = 2000;
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var force = d3.layout.force()
.nodes(nodes) //指定节点数组
.links(edges) //指定连线数组
.size([width, height]) //指定范围
.linkDistance(200) //指定连线长度
.charge(-600); //相互之间的作用力
force.start(); //开始作用
//添加连线
var svg_edges = svg.selectAll("line")
.data(edges)
.enter()
.append("line")
.style("stroke", "#ccc")
.style("stroke-width", 3);
var color = d3.scale.category20();
//添加节点
var svg_nodes = svg.selectAll("circle")
.data(nodes)
.enter()
.append("circle")
.attr("r", 20)
.on("dblclick", function (d) {
var nextpage = "output.html?chap=" + chap + "&ans=" + d.name;
window.open(nextpage);
})
.on("mouseover", function (d, i) {
fun(i);
console.log(d3.select(this).style("fill", "Lime"));
})
.on("mouseout", function (d, i) {
//fun(i);
console.log(d3.select(this).style("fill", col[i].toString()));
})
.style("fill", function (d, i) {
/*var t = linear(flag[i]);
var col = computeColor(t);
return col.toString();*/
return col[i].toString();
/*var color1 = d3.rgb(255, 30, 0);
if (flag[i] == 4) {
var color1 = d3.rgb(255, 0, 0);
}
if (flag[i] == 3) {
var color1 = d3.rgb(255, 255, 0);
}
if (flag[i] == 2) {
var color1 = d3.rgb(255, 0, 255);
}
if (flag[i] == 1) {
var color1 = d3.rgb(0, 0, 255);
}
return color1;*/
})
.call(force.drag); //使得节点能够拖动
//添加描述节点的文字
var svg_texts = svg.selectAll("text")
.data(nodes)
.enter()
.append("text")
.style("fill", "black")
.style("font-size", 40)
.attr("dx", 10)
.attr("dy", 4)
.text(function (d) {
return d.name;
//return null;
});
force.on("tick", function () { //对于每一个时间间隔
//更新连线坐标
svg_edges.attr("x1", function (d) {
return d.source.x;
})
.attr("y1", function (d) {
return d.source.y;
})
.attr("x2", function (d) {
return d.target.x;
})
.attr("y2", function (d) {
return d.target.y;
});
//更新节点坐标
svg_nodes.attr("cx", function (d) {
return d.x;
})
.attr("cy", function (d) {
return d.y;
});
//更新文字坐标
svg_texts.attr("x", function (d) {
return d.x;
})
.attr("y", function (d) {
return d.y;
});
});
});
</script>
<font style='font-size:100px; color:#000000'>Visualized by D3js, k = </font>
<script>
document.write("<font style='font-size:100px; color:#000000'>" + chap + "</font>");
</script>
<br><br>
<input type="button" value="25" style="height:150px;width:200px;font-size:50px;"
onclick="javascrtpt:window.location.href='force25.html?chap=25'"><!--
<a href="force25.html?chap=25"><font size="80"><input type="button">25</input></font></a>-->
<input type="button" value="50" style="height:150px;width:200px;font-size:50px;"
onclick="javascrtpt:window.location.href='force25.html?chap=50'"><!--
<a href="force25.html?chap=50"><font size="80">50</font></a>-->
<input type="button" value="75" style="height:150px;width:200px;font-size:50px;"
onclick="javascrtpt:window.location.href='force25.html?chap=75'"><!--
<a href="force25.html?chap=100"><font size="80">75</font></a>-->
<input type="button" value="100" style="height:150px;width:200px;font-size:50px;"
onclick="javascrtpt:window.location.href='force25.html?chap=100'"><!--
<a href="force25.html?chap=100"><font size="80">100</font></a>-->
<input type="button" value="125" style="height:150px;width:200px;font-size:50px;"
onclick="javascrtpt:window.location.href='force25.html?chap=125'"><!--
<a href="force25.html?chap=125"><font size="80">125</font></a>-->
<input type="button" value="150" style="height:150px;width:200px;font-size:50px;"
onclick="javascrtpt:window.location.href='force25.html?chap=150'">
<input type='button' value='hide' style="height:150px;width:200px;font-size:50px;" onclick="fun(-100)"/>
<input type='button' value='id' style="height:150px;width:200px;font-size:50px;" onclick="idorname(1)"/>
<input type='button' value='name' style="height:150px;width:200px;font-size:50px;" onclick="idorname(2)"/>
</a>
<br>
<input type="text" id="textArea" style="height:150px;width:400px;font-size:80px;"/>
<input type='button' value='search' style="height:150px;width:200px;font-size:50px;" onclick="fun2()"/>
<label id="test" style="height:2000px;width:2000px;font-size:100px; float:right">这里显示点压缩前的内容,把鼠标放在点上可以显示点的内容</label>
</body>
</html>