-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.html
395 lines (329 loc) · 13 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Twitter Circle Visualization</title>
<link rel="icon" href="https://pbs.twimg.com/profile_images/1692481211888025600/lUJUEO_p_400x400.jpg" type="image/png">
<script src="https://d3js.org/d3.v6.min.js"></script>
<style>
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-size: 2rem;
position: relative;
margin:0;
padding: 0;
display: flex;
flex-direction: column; /* Stack elements vertically */
align-items: center;
justify-content: flex-start; /* Align content to the top */
height: 100vh;
margin: 0;
background: linear-gradient(to bottom right, #fdf6e3, #e2c38a);
color: #CF2D01;
}
.node-foreign-object {
transition: transform 0.2s; /* Smooth transition for any transforms */
transform-origin: 50% 50%; /* Center the scaling transformation */
transform-box: fill-box; /* Refer to the object's bounding box for the origin */
border-radius: 50%; /* Keeps the circular shape */
overflow: hidden; /* Ensures the content does not spill out on scale */
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); /* May remove this if feels cringe */
}
.node-foreign-object:hover {
transform: scale(1.4); /* Enlarges the foreignObject on hover */
cursor: pointer;
}
.node-img {
width: 100%;
height: 100%;
object-fit: cover; /* Cover the area without stretching */
border-radius: 50%; /* Ensures the image is circular */
}
label {
margin-bottom: 20px; /* Space between the label and the slider */
font-size: 1.5rem; /* Larger font size for readability */
}
#slider-container {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
position: absolute; /* Position the container absolutely */
bottom: 10px; /* Adjust the bottom position as needed */
left: 50%; /* Center the container horizontally */
transform: translateX(-50%); /* Adjust for the container's width */
text-align: center;
}
svg {
width: 100vw;
height:100vh;
}
svg#network {
max-width: 95vw; /* Limit SVG size for very large screens */
max-height: 95vh; /* Adjust height automatically */
margin-top: 10px; /* Add space between the slider and the SVG */
}
#pfpCountSlider {
-webkit-appearance: none;
width: 25vw;
height: 15px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
#pfpCountSlider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #CF2D01;
cursor: pointer;
}
#pfpCountSlider::-moz-range-thumb {
width: 25px;
height: 25px;
border-radius: 50%;
background: #CF2D01;
cursor: pointer;
}
@media (max-width: 768px) { /* Adjustments for tablets and mobile phones */
#slider-container {
width: 90%; /* Make the slider container take more space */
}
#pfpCountSlider {
width: 100%; /* Make the slider adapt to the container width */
}
svg#network {
max-width: 100%; /* Allow the SVG to fill the container on smaller screens */
}
}
#cornerImage {
position: absolute;
bottom: 4vh;
left: 6vw;
width: auto; /* Adjust the width automatically to maintain aspect ratio */
height: 25vh; /* Start with a relative height, adjust as needed */
max-width: 35vw; /* Ensures the image does not exceed this width */
max-height: 35vh; /* Ensures the image does not exceed this height */
min-width: 100px;
min-height: 100px;
}
#leaderboardButton {
position: absolute;
top: 2vh; /* 2% of the viewport height */
right: 2vw; /* 5% of the viewport width */
padding: 0.5vw 1vw; /* Scales padding with the viewport width */
background-color: inherit;
color: #CF2D01;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.2s ease-in-out;
font-size: 1.5rem; /* Optionally make the font size responsive */
}
#leaderboardButton:hover {
background-color: #ecb679; /* Slightly darker shade for hover effect */
}
#dmStatsButton {
position: absolute;
top: 8vh; /* 2% of the viewport height */
right: 2vw; /* 5% of the viewport width */
padding: 0.5vw 1vw; /* Scales padding with the viewport width */
background-color: inherit;
color: #CF2D01;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.2s ease-in-out;
font-size: 1.5rem; /* Optionally make the font size responsive */
}
#dmStatsButton:hover {
background-color: #ecb679; /* Slightly darker shade for hover effect */
}
.custom-tooltip {
display: none; /* Hide tooltip by default */
position: absolute;
background-color: white;
color: #CF2D01;
padding: 5px 10px;
border-radius: 6px;
font-size: 0.75rem;
z-index: 10;
}
.node-username {
fill: #ff6f42;
font-weight: bold;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
font-size: 10px;
}
#toggleUsernamesButton {
position: absolute;
top: 14vh;
right: 2vw;
padding: 0.5vw 1vw;
background-color: inherit;
color: #CF2D01;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.2s ease-in-out;
font-size: 1.5rem;
}
#toggleUsernamesButton:hover {
background-color: #ecb679;
}
</style>
</head>
<body>
<div id="tooltip" class="custom-tooltip"></div>
<button id="leaderboardButton">Leaderboard</button>
<button id="dmStatsButton" class="navigation-button">DM stats</button>
<button id="toggleUsernamesButton">Toggle Usernames</button>
<img src="https://images.gamebanana.com/img/ico/sprays/627d932c150ba.png" alt="Description" id="cornerImage">
<svg id="network" width="2000" height="3000"></svg>
<div id="slider-container">
<label for="pfpCountSlider"><span id="pfpCount">200</span></label>
<input type="range" id="pfpCountSlider" min="1" max="200" value="200" step="1">
</div>
<script>
// Load the data from the JSON file
document.getElementById('leaderboardButton').addEventListener('click', function() {
window.location.href = 'leaderboard.html';
});
document.getElementById('dmStatsButton').addEventListener('click', function() {
window.location.href = 'dm_stats.html';
});
let center = { x: 0, y: 0 };
function updateCenter() {
const svg = d3.select('#network').node();
const width = svg.clientWidth || svg.parentNode.clientWidth;
const height = svg.clientHeight || svg.parentNode.clientHeight;
center.x = width / 2;
center.y = height / 2;
}
d3.json('final_weights_with_pics.json').then(function(data) {
updateCenter();
data = data.slice(0, 200)
const maxProfiles = data.length;
document.getElementById('pfpCountSlider').max = maxProfiles;
document.getElementById('pfpCountSlider').value = maxProfiles / 2;
document.getElementById('pfpCount').textContent = 100; // Default to all
const svg = d3.select('#network'),
width = +svg.attr("width"),
height = +svg.attr("height"),
nodeRadius = 30, // Radius for the profile images
spacingBetweenNodes = 2, // Spacing between nodes
spacingBetweenCircles = 20; // Spacing between concentric circles
let centralNodeRadius = nodeRadius * 1.5;
// Function to calculate positions
function calculatePositions(data, startRadius) {
let currentRadius = startRadius, // Adjust initial radius to start from outside the center node
currentAngle = 0,
positions = [],
nodesInThisCircle,
circumference;
// Place the center node
if (data.length > 0 && data[0].imageSrc !== null) {
positions.push({ twitterUsername: data[0].twitterUsername, imageSrc: data[0].imageSrc, x: center.x, y: center.y, radius: centralNodeRadius });
}
// Start from the second item if the first one is used for the center node
data.slice(1).forEach((d, i) => {
if (d.imageSrc === null) {
return
}
circumference = 2 * Math.PI * (currentRadius);
nodesInThisCircle = Math.floor(circumference / (nodeRadius * 2 + spacingBetweenNodes));
if (currentAngle >= 2 * Math.PI) {
currentRadius += (nodeRadius * 2) + spacingBetweenCircles; // Adjust for next circle
currentAngle = 0; // Reset angle for next circle
}
const x = center.x + Math.cos(currentAngle) * currentRadius;
const y = center.y + Math.sin(currentAngle) * currentRadius;
positions.push({ twitterUsername: d.twitterUsername, imageSrc: d.imageSrc, x, y });
// Update for next node
currentAngle += (2 * Math.PI) / nodesInThisCircle;
});
return positions;
}
function drawNodes(filteredData) {
// Clear existing SVG content
svg.selectAll("*").remove();
const nodePositions = calculatePositions(filteredData, nodeRadius * 2 + spacingBetweenCircles);
const simulation = d3.forceSimulation(nodePositions)
.force("center", d3.forceCenter(center.x, center.y))
.force("collide", d3.forceCollide().radius(d => nodeRadius * 1.5).strength(0.7));
// Run the simulation for a few iterations
for (let i = 0; i < 15; ++i) simulation.tick();
// Draw the nodes
nodePositions.forEach(function(d) {
const currentRadius = d.radius || nodeRadius;
const foreignObject = svg.append('foreignObject')
.attr('class', 'node-foreign-object')
.attr('x', d.x - currentRadius)
.attr('y', d.y - currentRadius)
.attr('width', currentRadius * 2)
.attr('height', currentRadius * 2)
.on('mouseover', function(event) {
// Show tooltip
d3.select('#tooltip')
.style('display', 'block')
.html(d.twitterUsername); // Use innerHTML or textContent if plain text
})
.on('mousemove', function(event) {
// Position tooltip
d3.select('#tooltip')
.style('left', (event.pageX + 10) + 'px')
.style('top', (event.pageY + 10) + 'px');
})
.on('mouseout', function() {
// Hide tooltip
d3.select('#tooltip').style('display', 'none');
});
const div = foreignObject.append('xhtml:div')
.style('width', `${currentRadius * 2}px`)
.style('height', `${currentRadius * 2}px`)
.style('border-radius', '50%')
.style('overflow', 'hidden');
div.append('xhtml:img')
.attr('class', 'node-img')
.attr('src', d.imageSrc)
.style('width', '100%')
.style('height', '100%')
.attr('onerror', "this.src='https://assets.pokemon.com/assets/cms2/img/pokedex/full/054.png'")
.on('click', () => window.open(`https://twitter.com/${d.twitterUsername}`, '_blank'));
svg.append('text')
.attr('class', 'node-username')
.attr('x', d.x)
.attr('y', d.y + currentRadius + 15) // Position the text below the circle
.attr('text-anchor', 'middle')
.style('font-size', '12px')
.text(d.twitterUsername);
});
}
drawNodes(data.slice(0, 100));
document.getElementById('pfpCountSlider').addEventListener('input', function() {
updateCenter();
const value = this.value;
const filteredData = data.slice(0, value);
document.getElementById('pfpCount').textContent = value; // Update the displayed count
drawNodes(filteredData); // Redraw with the filtered data
});
window.addEventListener('resize', function() {
updateCenter();
// You may need to call a function to redraw your visualization here
// For example:
const value = document.getElementById('pfpCountSlider').value
const filteredData = data.slice(0, value);
drawNodes(filteredData); // Assuming 'data' is accessible, or you need to manage its scope
});
let usernamesVisible = true;
document.getElementById('toggleUsernamesButton').addEventListener('click', function() {
usernamesVisible = !usernamesVisible;
svg.selectAll('.node-username')
.style('display', usernamesVisible ? 'block' : 'none');
});
});
</script>
</body>
</html>