-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
331 lines (268 loc) · 10.5 KB
/
Copy pathindex.html
File metadata and controls
331 lines (268 loc) · 10.5 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
<!DOCTYPE html>
<html>
<head>
<title>FullBrain</title>
<style>
body, html {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background-color:rgb(24, 24, 24);
overflow: hidden;
display: flex;
flex-direction: column;
font-family: Helvetica, sans-serif;
}
.svg-container {
overflow-x: hidden;
overflow-y: hidden;
display: flex;
align-items: flex-start;
scroll-snap-type: x mandatory mandatory;
flex-grow: 1;
}
.svg-item {
flex-shrink: 0;
width: 100%;
height: 100%;
scroll-snap-align: start;
position: relative;
}
#textArea {
height: auto;
color: whitesmoke;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-bottom: 20px;
}
#acronymDisplay {
font-size: 36px;
margin-top: 10px;
}
#nameDisplay {
font-size: 20;
margin-top: 12px;
}
#svgContainer {
filter: hue-rotate(0deg);
}
#brainContainer {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
}
.brain {
display: flex;
flex-direction: column;
align-items: center;
width: 45%; /* Adjusted width to ensure SVGs fit side by side */
}
#svgContainer1, #svgContainer2 {
max-width: 100%; /* Ensure SVGs scale within their containers */
height: auto;
}
</style>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const svgContainer = document.querySelector('#svgContainer');
const svgPath = 'SVG_IDs_fills/';
const numSVGs = 527 ;
let autoScrollSpeed = 10;
let autoScrollInterval;
let isPlaying = false;
const acronymDisplay = document.getElementById('acronymDisplay');
const nameDisplay = document.getElementById('nameDisplay');
for (let i = numSVGs; i > 0; i--) {
const svgElement = document.createElement('div');
svgElement.classList.add('svg-item');
fetch(`${svgPath}P56_Annotation_${(i-1).toString().padStart(4, '0')}.svg`)
.then(response => response.text())
.then(data => {
svgElement.innerHTML = data;
const svgPaths = svgElement.querySelectorAll('path');
svgPaths.forEach(path => {
const originalStrokeWidth = path.style.strokeWidth || '0.5';
path.addEventListener('mouseover', function() {
if (path.style.fill !== 'none') {
const computedStyle = getComputedStyle(path);
const colorRGB = computedStyle.fill;
const colorHex = rgbToHex(colorRGB);
getData(colorHex).then(data => {
const [id, hex, acronym, name] = data;
acronymDisplay.textContent = `${acronym}`;
nameDisplay.textContent = `${name}`;
});
path.style.strokeWidth = '1';
path.style.stroke = 'black';
path.style.strokeOpacity = '0.5'
path.style.strokeDasharray = (1)
}
});
path.addEventListener('mouseout', function() {
if (path.style.fill !== 'none') {
acronymDisplay.textContent = '';
nameDisplay.textContent = '';
path.style.strokeWidth = originalStrokeWidth;
path.style.stroke = 'none';
path.style.fillOpacity = 1
}
});
});
});
svgContainer.appendChild(svgElement);
}
const svgItems = Array.from(svgContainer.querySelectorAll('.svg-item'));
let currentIndex = 0;
function showCurrentSVG() {
svgItems[currentIndex].style.display = 'block';
}
function hideCurrentSVG() {
svgItems[currentIndex].style.display = 'none';
}
function showNextSVG() {
hideCurrentSVG();
currentIndex = (currentIndex + 1) % numSVGs;
showCurrentSVG();
}
function showPreviousSVG() {
hideCurrentSVG();
if (currentIndex === 0) {
currentIndex = numSVGs - 1;
} else {
currentIndex--;
}
showCurrentSVG();
}
function startAutoScroll() {
autoScrollInterval = setInterval(() => {
if (isPlaying) {
showPreviousSVG();
}
}, autoScrollSpeed);
}
function pauseAutoScroll() {
clearInterval(autoScrollInterval);
}
showCurrentSVG();
startAutoScroll();
function handleScroll(event) {
event.preventDefault();
const delta = Math.sign(event.deltaY);
if (delta > 0) {
showNextSVG();
} else if (delta < 0) {
showPreviousSVG();
}
}
svgContainer.addEventListener('wheel', handleScroll);
let startY;
let isSwiping = false;
svgContainer.addEventListener('touchstart', function(event) {
startY = event.touches[0].clientY;
isSwiping = true;
}, false);
svgContainer.addEventListener('touchmove', function(event) {
if (!isSwiping) return;
let deltaY = startY - event.touches[0].clientY;
// Introduce a threshold for deltaY, for example, 50 pixels
if (Math.abs(deltaY) > 50) {
if (deltaY > 0) {
showNextSVG();
} else {
showPreviousSVG();
}
isSwiping = false; // Reset the flag after handling the swipe
}
event.preventDefault(); // Prevent default behavior to improve responsiveness
}, false);
// function togglePlayPause() {
// isPlaying = !isPlaying;
// if (isPlaying) {
// startAutoScroll();
// } else {
// pauseAutoScroll();
// }
// }
function handleKeyPress(event) {
switch (event.code) {
case 'Space':
event.preventDefault();
togglePlayPause();
break;
case 'ArrowRight':
event.preventDefault();
if (isPlaying) togglePlayPause();
showPreviousSVG();
break;
case 'ArrowLeft':
event.preventDefault();
if (isPlaying) togglePlayPause();
showNextSVG();
break;
default:
break;
}
}
document.addEventListener('keydown', handleKeyPress);
});
// Helper function to convert RGB color to hex color
function rgbToHex(rgb) {
const values = rgb.match(/\d+/g);
const hexValues = values.map(value => {
const hex = parseInt(value).toString(16);
return hex.length === 1 ? "0" + hex : hex;
});
const hexWithoutHash = hexValues.join("").toUpperCase();
return hexWithoutHash;
}
// Helper function to get the data from the JSON array
async function getData(hex) {
const response = await fetch('color_acronym_name_mapping.json');
const jsonData = await response.json();
const data = jsonData.find(item => item[1].toLowerCase() === hex.toLowerCase()) || [];
return data;
}
</script>
</head>
<body>
<div class="svg-container" id="svgContainer"></div>
<div id="textArea">
<p id="acronymDisplay"></p>
<p id="nameDisplay"></p>
</div>
<!-- Slider for hue rotation -->
<div id="brainContainer">
<div class="brain">
<!-- First Brain SVG and Sliders -->
<div id="svgContainer1">
</div>
<!-- Slider for hue rotation -->
<input type="range" min="0" max="360" value="0" class="hueSlider" style="width: 100%; margin: 10px 0;">
<!-- Slider for desaturation -->
<input type="range" min="0" max="100" value="0" class="desatSlider" style="width: 100%; margin: 10px 0;">
</div>
</div>
<script>
// JavaScript to update hue rotation and desaturation based on slider values
const hueSliders = document.querySelectorAll('.hueSlider');
const desatSliders = document.querySelectorAll('.desatSlider');
const svgContainers = document.querySelectorAll('[id^="svgContainer"]');
hueSliders.forEach((slider, index) => {
slider.addEventListener('input', function() {
const hueValue = slider.value;
svgContainers[index].style.filter = `hue-rotate(${hueValue}deg) grayscale(${desatSliders[index].value}%)`;
});
});
desatSliders.forEach((slider, index) => {
slider.addEventListener('input', function() {
const desatValue = slider.value;
svgContainers[index].style.filter = `hue-rotate(${hueSliders[index].value}deg) grayscale(${desatValue}%)`;
});
});
</script>
</body>
</html>