-
Notifications
You must be signed in to change notification settings - Fork 0
/
coauthorship.html
346 lines (306 loc) · 13.8 KB
/
coauthorship.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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-RPKGFED7WP"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-RPKGFED7WP');
</script>
<meta charset="utf-8">
<!-- Yandex.Metrika counter -->
<script type="text/javascript" >
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
m[i].l=1*new Date();
for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
ym(98757050, "init", {
clickmap:true,
trackLinks:true,
accurateTrackBounce:true,
webvisor:true
});
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/98757050" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<!-- /Yandex.Metrika counter -->
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="description" content="Kyrgyz NLP Co-Authorship Interactive Visualization"/>
<title>KyrgyzNLP Co-Authorship Graph</title>
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Source+Sans+Pro:300,300i,600"/>
<link rel="stylesheet" href="/style.css"/>
<link rel="icon" href="/favicon.svg" type="image/svg+xml"/>
<script>
</script>
<style>
.node { stroke: #fff; stroke-width: 3px; }
.link { stroke: #ccc; stroke-opacity: 0.3; }
.node-label { font-size: 9px; fill: #777; pointer-events: none; }
.link-label { font-size: 10px; fill: #999; pointer-events: none; opacity: 0.0;}
.popup {
position: absolute;
background-color: rgba(0, 0, 0, 0.8);
color: #fff;
padding: 10px;
border-radius: 5px;
display: none;
z-index: 1000;
font-size: 14px;
}
#graph {
width: 760x;
height: 400px;
border: 1px solid gray;
}
svg {
width: 100%;
height: 100%;
}
.export-button {
//position: absolute;
//top: 10px;
//left: 10px;
padding: 10px 15px;
//width:150px;
margin: 10px;
background-color: #BFD3E6;
color: black;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 12px;
}
.export-button:hover {
background-color: #45a049;
}
</style>
<script src="https://d3js.org/d3.v7.min.js"></script>
</head>
<body>
<div class="container">
<header class="masthead">
<h1 class="masthead-title">
<a href="">KyrgyzNLP Co-Authorship Graph</a>
</h1>
<nav class="masthead-nav">
</nav>
</header>
<div class="content list">
This is a webpage accompanying the talk <a href="/pdf/kyrgyz-nlp-slides_2024.pdf">KyrgyzNLP: Challenges, Progress, and Future</a>
given on October 18th, 2024 at the <a href="https://aistconf.org/">AIST-2024</a> conference.
<br/><br/>
Each node is the author, edges are papers. Scroll to zoom in/out, and drag the nodes with left click.
<br/><br/>
<div id="graph">
<svg></svg>
</div>
<button class="export-button" onclick="exportSVG()">Export as SVG</button>
<button class="export-button" onclick="location.href='/'">Go Back</button>
<div id="popup" class="popup"></div>
</div>
<script>
// Define global variables
let authorsIndex, bibliography, authorPositions;
let nodes = {}, links = {};
let normalizedPositions = {};
// Load JSON files and initialize the graph
function loadJSON(filename, callback) {
fetch('static/' + filename)
.then(response => response.json())
.then(data => callback(data))
.catch(error => console.error('Error loading JSON:', error));
}
// Function to normalize positions and initialize nodes
function fetchAndInitializePositions() {
const nodeArray = Object.values(nodes);
nodeArray.forEach(node => {
if (normalizedPositions[node.id]) {
node.x = normalizedPositions[node.id].x;
node.y = normalizedPositions[node.id].y;
node.fx = normalizedPositions[node.id].x;
node.fy = normalizedPositions[node.id].y;
}
});
// Release fixed positions after initialization
setTimeout(() => {
nodeArray.forEach(node => {
node.fx = null;
node.fy = null;
});
}, 100); // Release nodes after
}
// Load author positions and normalize them
loadJSON('author_positions.json', data => {
authorPositions = data;
// Normalize positions
const width = 760;
const height = 400;
authorPositions.forEach(pos => {
normalizedPositions[pos.author_id] = {
x: (pos.x - Math.min(...authorPositions.map(p => p.x))) / (Math.max(...authorPositions.map(p => p.x)) - Math.min(...authorPositions.map(p => p.x))) * width,
y: (pos.y - Math.min(...authorPositions.map(p => p.y))) / (Math.max(...authorPositions.map(p => p.y)) - Math.min(...authorPositions.map(p => p.y))) * height
};
});
// Load authors index and bibliography
loadJSON('authors_index.json', data => {
authorsIndex = data;
loadJSON('bibliography_joined.json', visualizeGraph);
});
});
// Visualize the graph after all data is loaded
function visualizeGraph(bibliography) {
// Construct nodes and links
for (const [refKey, entry] of Object.entries(bibliography)) {
const authorIDs = entry.author.split(' and ');
authorIDs.forEach(authorID => {
if (!nodes[authorID]) {
nodes[authorID] = { id: authorID, name_ru: authorsIndex[authorID]?.ru || authorID, name_en: authorsIndex[authorID]?.en || authorID, papers: 0 };
}
nodes[authorID].papers += 1;
});
for (let i = 0; i < authorIDs.length; i++) {
for (let j = i + 1; j < authorIDs.length; j++) {
const linkKey = authorIDs[i] + '-' + authorIDs[j];
if (!links[linkKey]) {
links[linkKey] = { source: authorIDs[i], target: authorIDs[j], label: refKey };
}
}
}
}
// Initialize positions for nodes
fetchAndInitializePositions();
// Continue with D3 visualization
const nodeArray = Object.values(nodes);
const linkArray = Object.values(links);
const width = window.innerWidth, height = window.innerHeight;
// Define color scale for nodes based on the number of papers
const colorScale = d3.scaleLinear()
.domain([1, d3.max(nodeArray, d => d.papers)])
.range(["#BFD3E6", "#4A6FA5"]);
const svg = d3.select("svg")
//.attr("width", width).attr("height", height)
.call(d3.zoom().scaleExtent([0.5, 5]).on("zoom", (event) => {
svgGroup.attr("transform", event.transform);
}));
const svgGroup = svg.append("g");
const link = svgGroup.append("g").selectAll("line")
.data(linkArray).enter().append("line")
.attr("class", "link");
const linkLabel = svgGroup.append("g").selectAll("text")
.data(linkArray).enter().append("text")
.attr("class", "link-label")
.attr("dy", ".0em")
.text(d => d.label);
const node = svgGroup.append("g").selectAll("circle")
.data(nodeArray).enter().append("circle")
.attr("class", "node")
.attr("r", 8)
.attr("fill", d => colorScale(d.papers))
.on("click", showPopup)
.call(d3.drag().on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended));
const nodeLabel = svgGroup.append("g").selectAll("text")
.data(nodeArray).enter().append("text")
.attr("class", "node-label")
.attr("dy", "1em")
.attr("dx", "-3em")
.text(d => d.name_en);
// Define the tick function for simulation
const simulation = d3.forceSimulation(nodeArray)
.force("link", d3.forceLink(linkArray).distance(20).id(d => d.id))
.force("charge", d3.forceManyBody().strength(-1.0))
.force("center", d3.forceCenter(width / 2, height / 2))
.force("boundingBox", boundingBoxForce(width / 1.1, height / 1.1))
.force("collision", d3.forceCollide().radius(20).strength(0.1)) // Add collision force
.alphaDecay(0.01) // Increased decay for faster settling
.on("tick", ticked);
// Bounding box force function
function boundingBoxForce(width, height) {
return function(alpha) {
nodeArray.forEach(node => {
if (node.x < 0) node.vx += (0 - node.x) * alpha;
if (node.x > width) node.vx += (width - node.x) * alpha;
if (node.y < 0) node.vy += (0 - node.y) * alpha;
if (node.y > height) node.vy += (height - node.y) * alpha;
});
};
}
function ticked() {
link.attr("x1", d => d.source.x).attr("y1", d => d.source.y)
.attr("x2", d => d.target.x).attr("y2", d => d.target.y);
linkLabel.attr("x", d => (d.source.x + d.target.x) / 2)
.attr("y", d => (d.source.y + d.target.y) / 2);
node.attr("cx", d => d.x).attr("cy", d => d.y);
nodeLabel.attr("x", d => d.x).attr("y", d => d.y - 10);
}
function dragstarted(event, d) {
if (!event.active) simulation.alphaTarget(0.3).restart();
d.fx = d.x; d.fy = d.y;
}
function dragged(event, d) { d.fx = event.x; d.fy = event.y; }
function dragended(event, d) {
if (!event.active) simulation.alphaTarget(0);
d.fx = null; d.fy = null;
}
// Show popup on node click
function showPopup(event, d) {
const popup = document.getElementById('popup');
popup.style.left = (event.pageX + 15) + 'px'; // Offset for better visibility
popup.style.top = (event.pageY + 15) + 'px';
popup.innerHTML = `<strong>Author:</strong><br>${d.name_ru} (${d.name_en})<br>Papers: ${d.papers}`;
popup.style.display = 'block';
}
svg.on("click", () => {
document.getElementById('popup').style.display = 'none';
});
}
// Enhanced Export SVG function
function exportSVG() {
const svgElement = document.querySelector("#graph svg");
// Get all CSS styles from the document
const styles = getComputedStyles();
// Clone the original SVG element to modify it safely
const svgClone = svgElement.cloneNode(true);
// Create a <style> element and add the CSS rules
const styleElement = document.createElement("style");
styleElement.textContent = styles;
svgClone.prepend(styleElement);
// Serialize the cloned SVG with styles
const serializer = new XMLSerializer();
const source = serializer.serializeToString(svgClone);
const svgBlob = new Blob([source], { type: "image/svg+xml;charset=utf-8" });
const url = URL.createObjectURL(svgBlob);
// Create a temporary download link and trigger the download
const downloadLink = document.createElement("a");
downloadLink.href = url;
downloadLink.download = "kyrgyz-nlp-coauthorship-network.svg";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
URL.revokeObjectURL(url);
}
// Function to get computed CSS styles from the document
function getComputedStyles() {
let cssRules = "";
// Iterate over all stylesheets
for (let sheet of document.styleSheets) {
try {
if (sheet.cssRules) {
// Iterate over all rules in the stylesheet
for (let rule of sheet.cssRules) {
cssRules += rule.cssText + "\n";
}
}
} catch (e) {
console.warn("Cannot access stylesheet rules: ", e);
}
}
return cssRules;
}
</script>
</div>
</body>
</html>