-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
687 lines (566 loc) · 27.1 KB
/
index.html
File metadata and controls
687 lines (566 loc) · 27.1 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
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>critical methods in spatial research</title>
<link rel="stylesheet" href="./main.css">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300&display=swap" rel="stylesheet">
<script src="https://www.gstatic.com/charts/loader.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-J2SEN9LXNV"></script>
<script src="https://d3js.org/d3.v6.min.js"></script>
</head>
<body>
<div class="top-bar">
<div class="title">
<a onclick="location.reload();">
Methods and Tutorials in Spatial Research
</a>
</div>
<div class="button-container" id="about">
<a href="about.html">About</a>
</div>
</div>
<div class="column">
<div class="column-left" >
<div id="side-panel" >
<p>
In connection with our research, the Center for Spatial Research and project collaborators have developed tutorials in critical mapping and data visualization. Tutorials are crafted to provide the technical expertise necessary for critically-minded spatial research across a broad range of disciplines. This growing library is designed to be a resource for students, faculty, and practitioners engaging in spatial research at Columbia University and beyond.
</p>
<input type="text" id="searchInput" class="search-input" placeholder="search by author, key terms, method ...">
<button onclick="search()" id="searchButton">></button>
<p style="margin-top: 35px; font-weight: bold;">
Workshop Panels:
</p>
<div class="panel-button-wrapper">
<div id="VisualCodeButton" class="panel-button"></div>
<span class="button-text">Visual Code</span>
</div>
<div class="panel-button-wrapper">
<div id="mappingConflictButton" class="panel-button"></div>
<div class="button-text">Mapping Conflict</div>
</div>
<div class="panel-button-wrapper">
<div id="counterNarrativesButton" class="panel-button"></div>
<span class="button-text">Counter Narratives</span>
</div>
<div class="panel-button-wrapper">
<div id="localDataButton" class="panel-button"></div>
<span class="button-text">Local Data</span>
</div>
<div class="panel-button-wrapper">
<div id="networksButton" class="panel-button"></div>
<span class="button-text">Network Models</span>
</div>
<div class="panel-button-wrapper">
<div id="forensicsButton" class="panel-button"></div>
<span class="button-text">Counter Forensics</span>
</div>
<hr style="width: 97%; margin: 20px auto;">
<p style="font-weight: bold;">
Center for Spatial Research
</p>
<div class="panel-button-wrapper">
<div id="csrButton" class="panel-button"></div>
<span class="button-text">Projects</span>
</div>
</div>
</div>
<div class="column-main-viz">
<div id="visualize-container">Visualize By:</div>
<div class="button-container">
<button class="flex-project" id="show-projects">PROJECT NAMES</button>
<button class="flex-author" id="show-authors">AUTHOR NAMES</button>
</div>
<div id="networkviz"></div>
</div>
</div>
<script>
let data;
function loadData() {
d3.json("tutorials.json").then(function(loadedData) {
data = loadedData;
visualizeData();
});
}
loadData();
function visualizeData() {
// Set initial dimensions
const width = window.innerWidth;
const height = window.innerHeight;
// Define margins with left margin based on a percentage of the viewport width
const margin = {
top: 0,
right: 0,
bottom: 0,
left: 0
// left: 0.2* width // 10% of the viewport width
};
// Adjust the inner width of the content (excluding margins)
const adjustedWidth = width - margin.left - margin.right;
const adjustedHeight = height - margin.top - margin.bottom;
// Append the SVG object to the div with id 'networkviz'
const svg = d3.select("#networkviz")
.append("svg")
.attr("width", '100%') // Set width to 100% to allow resizing
.attr("height", '100%') // Set height to 100% for full window
.append("g")
//Extract all unique panel names and create links to the tutorials within each panel. These links represent relationships between different items within the same panel.
var panels = Array.from(new Set(data.tutorials.map(tutorial => tutorial.panel)));
// Creating the links
var links = [];
var tagLinks =[]
var panelLinks =[] //this separation is pointless
panels.forEach(panel => {
var tutorialsInPanel = data.tutorials.filter(tutorial => tutorial.panel === panel);
for (let i = 0; i < tutorialsInPanel.length; i++) {
for (let j = i + 1; j < tutorialsInPanel.length; j++) {
if (tutorialsInPanel[i].project !== tutorialsInPanel[j].project) {
panelLinks.push({
source: tutorialsInPanel[i].project,
target: tutorialsInPanel[j].project,
panel: panel // Add the panel name to the link object
});
}
}
}
});
// Extract tags for each project
const projectTags = data.tutorials.map(tutorial => ({ project: tutorial.project, tags: tutorial.tags }));
projectTags.forEach((source, i) => {
projectTags.slice(i + 1).forEach(target => {
// Check if there are common words in tags between source and target
const commonTags = [];
source.tags.forEach(sourceTag => {
target.tags.forEach(targetTag => {
const sourceWords = sourceTag.split(" ");
const targetWords = targetTag.split(" ");
sourceWords.forEach(word => {
if (targetWords.includes(word)) {
commonTags.push(word);
}
});
});
});
if (commonTags.length > 0) {
// If there are common words, create a link between the projects
tagLinks.push({ source: source.project, target: target.project, commonTags: commonTags });
}
});
});
const allLinks = links.concat(tagLinks, panelLinks);
// Define a function to get the color class based on the panel name
function getNodeColor(panel) {
switch (panel) {
case "Visual Code":
return "panel-VisualCode";
case "Mapping Conflict":
return "panel-MappingConflict";
case "Counter Narrative":
return "panel-CounterNarrative";
case "Local Data":
return "panel-LocalData";
case "Network Models":
return "panel-NetworkModels";
case "Counter Forensics":
return "panel-CounterForensics";
default:
return "panel-Default";
}
}
// Returns the linked CSS class name for style definition based on the panel name.
function getLinkClassName(panel) {
return `link ${panel.replace(/\s+/g, '')}`; // Remove spaces and lowercase
}
// Create a <line> element for each linked data and assign CSS class names based on the panel name.
const link = svg
.selectAll("line")
.data(allLinks)
.enter()
.append("line")
.attr("class", function(d) {
if (d.panel) {
return getLinkClassName(d.panel); // Assign the class dynamically based on panel name
} else {
return "link"; // Default class for links without a panel
}
});
function getNodePanel(node) {
const tutorial = data.tutorials.find(tutorial => tutorial.project === node.project);
return tutorial ? tutorial.panel : ""; // Return panel if tutorial exists, otherwise return an empty string
}
// Creates a <circle> element for each tutorial data, sets the radius, and assigns CSS classes and colors based on the panel name. Each node also holds the original panel name.
const node = svg
.selectAll("circle")
.data(data.tutorials)
.join("circle")
.attr("r", 10)
.attr("class", d => `node panel-${d.panel.replace(/\s+/g, '')} ${getNodeColor(d.panel)}`)
.each(function(d) {
d3.select(this).attr("original-panel", d.panel); // Store the original panel name
})
.call(
d3.drag()
.on("start", dragstarted)
.on("drag",dragged)
.on("end", dragended)
);
// Reheat the simulation when drag starts, and fix the subject position.
function dragstarted(event) {
if (!event.active) simulation.alphaTarget(0.3).restart();
event.subject.fx = event.subject.x;
event.subject.fy = event.subject.y;
}
// Update the subject (dragged node) position during drag.
function dragged(event) {
event.subject.fx = event.x;
event.subject.fy = event.y;
}
function dragended(event) {
if (!event.active) simulation.alphaTarget(0);
event.subject.fx = null;
event.subject.fy = null;
}
const wrapText = (text, maxWidth) => {
if (typeof text !== "string") {
text = String(text || ''); // Convert non-strings to empty strings or ensure it's a string
}
const words = text.split(/\s+/); // Split text into words
let lines = [];
let currentLine = [];
words.forEach(word => {
currentLine.push(word);
const currentLineStr = currentLine.join(" ");
const testText = svg.append("text").text(currentLineStr).attr("class", "test-wrap"); // Temporary element for testing width
if (testText.node().getComputedTextLength() > maxWidth) {
currentLine.pop(); // Remove the last word if width exceeds maxWidth
lines.push(currentLine.join(" ")); // Push the valid line to lines array
currentLine = [word]; // Start a new line with the word that overflowed
}
testText.remove(); // Clean up the temporary text element
});
// Add the last line
if (currentLine.length > 0) {
lines.push(currentLine.join(" "));
}
return lines;
};
var xTextOffset = 0;
let showAuthor = true;
d3.select("#show-authors").on("click", function() {
showAuthor = true;
updateTextContent(); // Call the function to update text content
setFocusClass(this);
});
// Display projects
d3.select("#show-projects").on("click", function() {
showAuthor = false;
updateTextContent(); // Call the function to update text content
setFocusClass(this);
});
function yTextOffset(){
if(svgWidth > 800){
return 30;
}
else {
return 15
};
}
// Function to update text content based on showAuthor
function updateTextContent() {
svg.selectAll("text").remove(); // Clear previous text elements
svg.selectAll("text").data(data.tutorials)
.enter()
.append("text")
.attr("class", "node-text")
.attr("x", d => d.cx + xTextOffset)
.attr("y", d => d.cy + yTextOffset())
.each(function(d) {
d3.select(this).selectAll("tspan").remove(); // Clear previous tspans
const textContent = showAuthor ? d.authors : d.project;
const yOffset = svgWidth > 800 ? 20 : 10;
const lines = wrapText(textContent, 0.05 * window.innerWidth + 63.25);
// const lines = wrapText(textContent, 0.098 * window.innerWidth + 50);
let dy = 0;
lines.forEach(line => {
d3.select(this)
.append("tspan")
.attr("x", d.x + xTextOffset)
.attr("y", d.y + dy + yTextOffset())
.text(line);
dy += yOffset;
});
});
}
// Function to set focus class on buttons
function setFocusClass(button) {
d3.selectAll(".button-container button").classed("custom-focus", false); // Remove custom class from all buttons
d3.select(button).classed("custom-focus", true); // Add custom class to the clicked button
}
var svgWidth = parseFloat(d3.select("#networkviz").style("width"));
var svgHeight = parseFloat(d3.select("#networkviz").style("height"));
const collideWidth = svgWidth > 800 ? (Math.min(svgWidth, svgHeight)/10) : (Math.min(svgWidth, svgHeight)/8);
const simulation = d3.forceSimulation(data.tutorials)
.force("link", d3.forceLink(allLinks) // This force provides links between nodes
.id(d => d.project) // This provide the id of a node
.links(allLinks) // and this the list of links
)
.force("charge", d3.forceManyBody() // This adds repulsion between nodes.
.strength(-1 * Math.min(svgWidth, svgHeight) / 300)
)
.force("center", d3.forceCenter(svgWidth/2, svgHeight/2)) // bring to center
// .force("collide", d3.forceCollide(Math.min(svgWidth, svgHeight)/10))
.force("collide", d3.forceCollide(collideWidth))
.on("tick", ticked);
//TO DO this is temp fix for intial text wrap
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function clickVisual() {
// console.log("Waiting 2 seconds...");
await delay(1000);
document.getElementById('show-projects').click();
// console.log("Function executed after 2 seconds");
}
clickVisual();
function ticked() {
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; });
node
.attr("cx", function (d) { return d.x+1; })
.attr("cy", function(d) { return d.y-1; });
const text = svg.selectAll("text").remove()
svg.selectAll("text")
.data(data.tutorials)
.enter()
.append("text")
.attr("class", "node-text")
.attr("x", d => d.cx + xTextOffset) // Modify the location of the <text>
.attr("y", d => d.cy + yTextOffset())
.each(function(d){
const yOffset = svgWidth > 800 ? 20 : 10;
const textContent = showAuthor ? d.authors : d.project;
const lines = wrapText(textContent, 0.05 * window.innerWidth + 63.25);
let dy = 0; // Initial y offset
lines.forEach(line => {
d3.select(this)
.append("tspan")
.attr("x",d.x)
.attr("y",d.y + dy + yTextOffset())
.text(line);
dy += yOffset; // Increase dy for the next line
});
d3.select(this)
.attr("original-panel", d.panel); // Store the original panel name
});
}
//onclick link to individual tutorial pages
svg.selectAll(".node")
.on("click", handleClick);
function handleClick(event, d) {
const projectName = d.project.replace(/[\s:.,-]+/g, '');
const baseUrl = `${window.location.origin}${window.location.pathname.replace('index.html', '')}`;
const projectUrl = `${baseUrl}tutorials/${projectName}.html`;
window.open(projectUrl, '_blank'); // open in new window
}
// Handle window resize to adjust the SVG dimensions dynamically
window.addEventListener('resize', resize); // TODO: is this working?
function resize() {
const newWidth = window.innerWidth;
const newHeight = window.innerHeight;
// Update the viewBox to match the new window size
svg.attr("viewBox", `0 0 ${newWidth} ${newHeight}`);
// Adjust other elements if necessary based on the new size
// Example: re-scale text, paths, etc. as needed
}
}
function search() {
var searchText = document.getElementById("searchInput").value.toLowerCase();
// Filter the data based on search text
var filteredData = data.tutorials.filter(function(item) {
return (
item.project.toLowerCase().includes(searchText) ||
item.authors.some(author => author.toLowerCase().includes(searchText)) ||
item.tags.some(tag => tag.toLowerCase().includes(searchText))
);
});
// Update visualization with filtered data
highlightNodes(filteredData);
}
let searchLinks = [];
function highlightNodes(filteredData) {
// Reset styles for all nodes
d3.selectAll(".node")
.attr("r", 10)
.style("stroke-width", "2px");
// Highlight filtered nodes
d3.selectAll(".node")
.filter(function(d) {
return filteredData.some(function(item) {
return item.project === d.project;
});
})
.attr("r", 12)
.style("stroke-width", "5px");
d3.selectAll(".link")
.style("stroke-width", function(d) {
const sourceConnected = filteredData.some(function(item) {
return item.project === d.source.project;
});
const targetConnected = filteredData.some(function(item) {
return item.project === d.target.project;
});
if (sourceConnected && targetConnected) {
searchLinks.push(d); // Store the filtered link
return "3px"; // Set stroke width to 3px for links connected to filtered nodes on both ends
} else {
return "1px"; // Set stroke width to 1px for other links
}
})
.style("opacity", function(d) {
const sourceConnected = filteredData.some(function(item) {
return item.project === d.source.project;
});
const targetConnected = filteredData.some(function(item) {
return item.project === d.target.project;
});
return (sourceConnected && targetConnected) ? 1.0 : 0.6; // Set opacity to 1 for links connected to filtered nodes on both ends
});
}
// Function to toggle highlight based on panel
const originalNodeStrokeColors = {};
function toggleHighlightByTag(tag, highlight) {
const normalizedTag = tag.toLowerCase(); // Normalize the tag to lower case
const taggedNodes = document.querySelectorAll('.node');
const taggedLinks = document.querySelectorAll('.link');
const highlightedNodes = new Set(); // Set to store currently highlighted nodes
taggedNodes.forEach(node => {
const nodeData = d3.select(node).data()[0]; // Get the data bound to the node
const nodeTags = nodeData.tags.map(t => t.toLowerCase()); // Normalize node tags to lower case
if (nodeTags.includes(normalizedTag)) {
if (highlight && normalizedTag === 'csr') {
if (!originalNodeStrokeColors[nodeData.project]) {
originalNodeStrokeColors[nodeData.project] = node.style.stroke; // Store original stroke color
}
node.style.strokeWidth = '5px'; // Set stroke width to 5px
node.setAttribute('r', 12); // Increase circle radius size
node.style.stroke = '#29AAE1'; // Set stroke color to #29AAE1 for csr tag
} else if (highlight) {
node.style.strokeWidth = '5px'; // Set stroke width to 5px
node.setAttribute('r', 12); // Increase circle radius size
} else {
node.style.strokeWidth = '2px'; // Restore default stroke width
node.setAttribute('r', 10); // Restore default circle radius size
if (normalizedTag === 'csr') {
node.style.stroke = originalNodeStrokeColors[nodeData.project] || ''; // Restore original stroke color for csr tag
}
}
highlightedNodes.add(nodeData.project); // Add node project to highlighted set
}
});
taggedLinks.forEach(link => {
const linkData = d3.select(link).data()[0]; // Get the data bound to the link
const sourceNode = linkData.source.project;
const targetNode = linkData.target.project;
if (highlightedNodes.has(sourceNode) && highlightedNodes.has(targetNode)) {
if (highlight) {
link.style.strokeWidth = '3px';
} else {
link.style.strokeWidth = '1px'; // Restore default stroke width
}
} else {
link.style.strokeWidth = '1px'; // Restore default stroke width for unhighlighted links
}
});
}
function toggleHighlight(panel, highlight) {
const panelNodes = document.querySelectorAll(`.node.panel-${panel}`);
const panelLinks = document.querySelectorAll(`.link.${panel}`);
panelNodes.forEach(node => {
if (highlight) {
node.style.strokeWidth = '5px'; // Set stroke width to 5px
node.setAttribute('r', 12); // Increase circle radius size
} else {
node.style.strokeWidth = '2px'; // Restore default stroke width
node.setAttribute('r', 10); // Restore default circle radius size
}
});
panelLinks.forEach(link => {
if (highlight) {
link.style.strokeWidth = '3px'; // Set stroke width to 5px
} else {
link.style.strokeWidth = '1px'; // Restore default stroke width
}
});
}
// Get the VisualCode button element
const visualCodeButton = document.getElementById('VisualCodeButton');
const mappingConflictButton = document.getElementById('mappingConflictButton');
const counterNarrativesButton = document.getElementById('counterNarrativesButton');
const localDataButton = document.getElementById('localDataButton');
const networksButton = document.getElementById('networksButton');
const forensicsButton = document.getElementById('forensicsButton');
const csrButton = document.getElementById('csrButton');
// Add click event listener
visualCodeButton.addEventListener('click', function() {
this.classList.toggle('highlighted');
toggleHighlight('VisualCode', this.classList.contains('highlighted'));
});
mappingConflictButton.addEventListener('click', function() {
this.classList.toggle('highlighted');
toggleHighlight('MappingConflict', this.classList.contains('highlighted'));
});
counterNarrativesButton.addEventListener('click', function() {
this.classList.toggle('highlighted');
toggleHighlight('CounterNarrative', this.classList.contains('highlighted'));
});
localDataButton.addEventListener('click', function() {
this.classList.toggle('highlighted');
toggleHighlight('LocalData', this.classList.contains('highlighted'));
});
networksButton.addEventListener('click', function() {
this.classList.toggle('highlighted');
toggleHighlight('NetworkModels', this.classList.contains('highlighted'));
});
forensicsButton.addEventListener('click', function() {
this.classList.toggle('highlighted');
toggleHighlight('CounterForensics', this.classList.contains('highlighted'));
});
csrButton.addEventListener('click', function() {
this.classList.toggle('highlighted');
toggleHighlightByTag('csr', this.classList.contains('highlighted'));
});
// press "esc" to reset the function toggleHighlight, toggleHighlightByTag, and the buttons (visualCodeButton, mappingConflictButton, counterNarrativesButton, localDataButton, networksButton, forensicsButton, and csrButton)
function resetAll() {
// Clear highlighted buttons
document.querySelectorAll('.panel-button').forEach(button => {
button.classList.remove('highlighted');
});
// Reset highlight states
d3.selectAll(".node")
.attr("r", 10)
.style("stroke-width", "2px");
d3.selectAll(".link")
.style("stroke-width", "1px")
.style("opacity", 0.6);
// Clear any specific highlight for tags
Object.keys(originalNodeStrokeColors).forEach(project => {
const node = d3.select(`.node[data-project="${project}"]`);
node.style("stroke", originalNodeStrokeColors[project] || ''); // Restore original stroke color
});
// Clear stored links
searchLinks = [];
}
// Attach reset function to the Esc key event
document.addEventListener('keydown', function(event) {
if (event.key === 'Escape') {
resetAll();
}
});
</script>
</body>
</html>