-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathd34.html
267 lines (208 loc) · 6.04 KB
/
d34.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
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<link rel = "stylesheet" type = "text/css" href = "http://underd0g.co/projects/projectstyle.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
</head>
<body>
<style>
@font-face {
font-family: myfont;
src: url(slkscr.ttf);
font-size: 14px;
}
body {
font-family: myfont;
font-weight: 300;
font-size: 1.2em;
line-height: 3.7em;
background: #121212;
}
p{
background-color: #222;
color: white;
}
#top{
background: #222;
}
#col{
color: white;
}
text{
stroke-width: 0.09;
stroke: white;
fill: white;
}
.node {
color: white;
stroke-width: 1.0px;
fill: white;
}
.link {
stroke: #555;
stroke-width: 1.0px;
}
.node text {
font: 13px ;
}
input {
width: 35%;
background: transparent;
border: none;
font-family: myfont;
font-size: 36;
color: #c0a79a;
padding-top: 150px;
}
input:focus {
outline: 0;
}
input::placeholder {
color: #fbfbfb;
}
#form-search {
margin: 1em 2em;
}
</style>
<div class="container"><center>
<form id="form-search" action="https://duckduckgo.com/" method="get" autocomplete="off">
<input id="search" placeholder="" type="text" name="q" autofocus="">
</form>
</center>
<div class="row" align='center'>
<div class="col-xsm-12" id = "col">
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
//setup for the d3 SVG
// testing a resize method using the browser measurements
// var width = window.innerWidth,
// height = window.innerHeight;
var width = 450,
height = 450;
//Set up the colour scale
var color = d3.scale.category20c()
// var color = d3.scaleOrdinal() // D3 Version 4
// .domain(["9", "7", "1"])
.range(["#EC1850", "#8fa1b3" , "#B19CD9"]);
//Set up the force layout
var force = d3.layout.force()
.gravity(0.05)
.charge(-150)
.linkDistance(80)
.size([width, height]);
//yes this is an svg
var svg = d3.select(".col-xsm-12").append("svg")
.attr("width", width)
.attr("height", height);
// hard-code some json
var graph = {
"nodes":[
{"name":"facebook","group":1, url: "https://facebook.com"},
{"name":"twitter","group":1, url: "https://twitter.com"},
{"name":"Reddit","group":1, url: "https://reddit.com"},
{"name":"youtube","group":9, url: "http://youtube.com"},
{"name":"gmail","group":9, url: "https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin"},
{"name":"wiki","group":9, url: "https://wikipedia.org"},
{"name":"l0bster","group":7, url: "https://l0bster.ru"},
{"name":"2f30","group":7,url:"https://2f30.org"}
],
"links":[
{"source":1,"target":0,"value":1},
{"source":2,"target":0,"value":2},
{"source":4,"target":3,"value":3},
{"source":5,"target":4,"value":3},
{"source":5,"target":3,"value":4},
{"source":6,"target":5,"value":5},
{"source":6,"target":0,"value":5},
{"source":2,"target":1,"value":5},
{"source":7,"target":6,"value":5}
]
}
//Creates the graph data structure out of the json data
force.nodes(graph.nodes)
.links(graph.links)
.start();
//Create all the line svgs but without locations yet
var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("line")
.attr("class", "link")
.attr('font-color', 'white')
.style("stroke-width", function (d) {
return Math.sqrt(d.value);
});
//Do the same with the circles for the nodes
var node = svg.selectAll(".node")
.data(graph.nodes)
.enter().append("g")
.attr("class", "node")
.call(force.drag);
node.append("circle")
.attr("r", 10)
.attr('font-color', 'white')
.style("fill", function (d) {
return color(d.group);
})
//give my children some attributes!
node.each(function(d){
var thisNode = d3.select(this);
if (!d.children) {
thisNode.append("svg:a")
.attr("xlink:href",function(d) { return d.url; })
.attr("target", "_blank")
//.text(function(d) { return d.url; }) (this isnt clugy enough)
.append("text", "fill", "white")
.attr("dx", 8)
.attr("dy", 3)
.attr("text-anchor", "start")
.attr('font-color', 'white')
.attr('font-color', 'white')
.text( function(d) { return d.name; });
} else {
thisNode.append("text")
.attr("dx", -8)
.attr("dy", 3)
.attr("text-anchor", "end")
.attr('font-color', 'white')
.text(function(d) { return d.name; });
}
});
// force be with you
force.on("tick", function () {
link.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;
});
//Changed
d3.selectAll("circle").attr("cx", function (d) {
return d.x;
})
.attr("cy", function (d) {
return d.y;
});
d3.selectAll("text").attr("x", function (d) {
return d.x;
})
.attr("y", function (d) {
return d.y;
});
});
</script>
</div>
</div>
</div>
</div>
</body>
</html>