Spaces:
Running
Running
File size: 11,569 Bytes
4d1fbe9 e75b376 4d1fbe9 e75b376 4d1fbe9 e75b376 4d1fbe9 e75b376 4d1fbe9 e75b376 4d1fbe9 e75b376 4d1fbe9 e75b376 4d1fbe9 e75b376 4d1fbe9 | 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 | // Scrollytelling functionality
class ScrollytellingEngine {
constructor() {
this.scenes = document.querySelectorAll('.scene');
this.progressBar = document.querySelector('.progress-bar');
this.currentScene = 0;
this.init();
}
init() {
// Set up intersection observer for scene detection
this.setupIntersectionObserver();
// Set up scroll progress tracking
this.setupScrollProgress();
// Initialize first scene
this.activateScene(0);
}
setupIntersectionObserver() {
const options = {
root: null,
rootMargin: '0px',
threshold: this.buildThresholdList()
};
this.observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const sceneIndex = parseInt(entry.target.dataset.scene);
this.activateScene(sceneIndex);
}
});
}, options);
this.scenes.forEach(scene => {
this.observer.observe(scene);
});
}
buildThresholdList() {
const thresholds = [];
const numSteps = 20;
for (let i = 1.0; i <= numSteps; i++) {
const ratio = i / numSteps;
thresholds.push(ratio);
}
thresholds.push(0);
return thresholds;
}
setupScrollProgress() {
window.addEventListener('scroll', () => {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
const scrollHeight = document.documentElement.scrollHeight - window.innerHeight;
const scrollProgress = (scrollTop / scrollHeight) * 100;
if (this.progressBar) {
this.progressBar.style.width = `${scrollProgress}%`;
}
});
}
activateScene(index) {
// Update all scenes
this.scenes.forEach((scene, i) => {
if (i === index) {
scene.classList.add('active');
} else {
scene.classList.remove('active');
}
});
this.currentScene = index;
this.updateVisualization(index);
}
updateVisualization(sceneIndex) {
const visualizationContainer = document.querySelector('.sticky > div');
if (!visualizationContainer) return;
// Update visualization based on current scene
switch(sceneIndex) {
case 0:
visualizationContainer.innerHTML = this.createScene0Visualization();
break;
case 1:
visualizationContainer.innerHTML = this.createScene1Visualization();
break;
case 2:
visualizationContainer.innerHTML = this.createScene2Visualization();
break;
case 3:
visualizationContainer.innerHTML = this.createScene3Visualization();
break;
case 4:
visualizationContainer.innerHTML = this.createScene4Visualization();
break;
case 5:
visualizationContainer.innerHTML = this.createScene5Visualization();
break;
case 6:
visualizationContainer.innerHTML = this.createScene6Visualization();
break;
case 7:
visualizationContainer.innerHTML = this.createScene7Visualization();
break;
case 8:
visualizationContainer.innerHTML = this.createScene8Visualization();
break;
default:
visualizationContainer.innerHTML = this.createDefaultVisualization();
}
}
createScene0Visualization() {
return `
<div class="w-full max-w-lg bg-gray-800 rounded-lg p-6 shadow-xl">
<h3 class="text-lg font-semibold text-blue-400 mb-4">Cheater Dynamics</h3>
<svg viewBox="0 0 400 300" class="system-diagram">
<rect x="50" y="50" width="300" height="200" fill="#1e293b" rx="8" />
<circle cx="100" cy="150" r="20" fill="#10b981" class="good-cell" />
<circle cx="200" cy="150" r="20" fill="#ef4444" class="cheater-cell" />
<text x="100" y="190" fill="#d1d5db" text-anchor="middle" font-size="12">Good Cell</text>
<text x="200" y="190" fill="#d1d5db" text-anchor="middle" font-size="12">Cheater</text>
<text x="200" y="240" fill="#60a5fa" text-anchor="middle" font-size="14" font-weight="bold">Type-2 Cheaters: Transcribe but fail to translate</text>
</svg>
</div>
`;
}
createScene1Visualization() {
return `
<div class="w-full max-w-lg bg-gray-800 rounded-lg p-6 shadow-xl">
<h3 class="text-lg font-semibold text-blue-400 mb-4">Constraints & Requirements</h3>
<svg viewBox="0 0 400 300" class="system-diagram">
<rect x="50" y="50" width="300" height="200" fill="#1e293b" rx="8" />
<text x="200" y="100" fill="#60a5fa" text-anchor="middle" font-size="16" font-weight="bold">No Tags Allowed</text>
<circle cx="150" cy="150" r="15" fill="#ef4444" />
<circle cx="250" cy="150" r="15" fill="#ef4444" />
<text x="150" y="180" fill="#d1d5db" text-anchor="middle" font-size="12">His-tag</text>
<text x="250" y="180" fill="#d1d5db" text-anchor="middle" font-size="12">Intein</text>
<text x="200" y="240" fill="#60a5fa" text-anchor="middle" font-size="14" font-weight="bold">Pristine Product, Universal QC</text>
</svg>
</div>
`;
}
createScene2Visualization() {
return `
<div class="w-full max-w-lg bg-gray-800 rounded-lg p-6 shadow-xl">
<h3 class="text-lg font-semibold text-blue-400 mb-4">Dual Stress Sensors</h3>
<svg viewBox="0 0 400 300" class="system-diagram">
<rect x="50" y="50" width="300" height="200" fill="#1e293b" rx="8" />
<circle cx="120" cy="120" r="15" fill="#f59e0b" class="sensor-active" />
<circle cx="280" cy="120" r="15" fill="#f59e0b" class="sensor-active" />
<text x="120" y="180" fill="#d1d5db" text-anchor="middle" font-size="12">σ32 Sensor</text>
<text x="280" y="180" fill="#d1d5db" text-anchor="middle" font-size="12">σE/Cpx Sensor</text>
<text x="200" y="240" fill="#60a5fa" text-anchor="middle" font-size="14" font-weight="bold">Native Stress Pathways</text>
</svg>
</div>
`;
}
createScene3Visualization() {
return `
<div class="w-full max-w-lg bg-gray-800 rounded-lg p-6 shadow-xl">
<h3 class="text-lg font-semibold text-blue-400 mb-4">Production Gate Logic</h3>
<svg viewBox="0 0 400 300" class="system-diagram">
<rect x="50" y="50" width="300" height="200" fill="#1e293b" rx="8" />
<text x="200" y="120" fill="#60a5fa" text-anchor="middle" font-size="16" font-weight="bold">(Scyt ∨ Senv) ∧ PM</text>
<rect x="180" y="140" width="40" height="20" fill="#8b5cf6" class="gate-active" rx="4" />
<text x="200" y="240" fill="#60a5fa" text-anchor="middle" font-size="14" font-weight="bold">Stress OR + ProductionMode AND</text>
</svg>
</div>
`;
}
createScene4Visualization() {
return `
<div class="w-full max-w-lg bg-gray-800 rounded-lg p-6 shadow-xl">
<h3 class="text-lg font-semibold text-blue-400 mb-4">Actuator & Latch</h3>
<svg viewBox="0 0 400 300" class="system-diagram">
<rect x="50" y="50" width="300" height="200" fill="#1e293b" rx="8" />
<path d="M 100 150 L 150 150 L 150 130 L 180 150 L 150 170 L 150 150" fill="#dc2626" class="latch-flipped" />
<text x="200" y="240" fill="#60a5fa" text-anchor="middle" font-size="14" font-weight="bold">Flp-ssrA + FRT-Toxin</text>
</svg>
</div>
`;
}
createScene5Visualization() {
return `
<div class="w-full max-w-lg bg-gray-800 rounded-lg p-6 shadow-xl">
<h3 class="text-lg font-semibold text-blue-400 mb-4">Translation Certificate</h3>
<svg viewBox="0 0 400 300" class="system-diagram">
<rect x="50" y="50" width="300" height="200" fill="#1e293b" rx="8" />
<path d="M 120 140 L 160 140 L 160 160 L 120 160 Z" fill="#059669" class="certificate-issued" />
<text x="200" y="240" fill="#60a5fa" text-anchor="middle" font-size="14" font-weight="bold">Ribosomal Re-initiation</text>
</svg>
</div>
`;
}
createScene6Visualization() {
return `
<div class="w-full max-w-lg bg-gray-800 rounded-lg p-6 shadow-xl">
<h3 class="text-lg font-semibold text-blue-400 mb-4">Dual-Plug Antidote</h3>
<svg viewBox="0 0 400 300" class="system-diagram">
<rect x="50" y="50" width="300" height="200" fill="#1e293b" rx="8" />
<circle cx="120" cy="120" r="15" fill="#3b82f6" class="antidote-active" />
<circle cx="280" cy="120" r="15" fill="#3b82f6" class="antidote-active" />
<text x="120" y="180" fill="#d1d5db" text-anchor="middle" font-size="12">Repressor</text>
<text x="280" y="180" fill="#d1d5db" text-anchor="middle" font-size="12">sRNA</text>
<text x="200" y="240" fill="#60a5fa" text-anchor="middle" font-size="14" font-weight="bold">Transcriptional + Translational Suppression</text>
</svg>
</div>
`;
}
createScene7Visualization() {
return `
<div class="w-full max-w-lg bg-gray-800 rounded-lg p-6 shadow-xl">
<h3 class="text-lg font-semibold text-blue-400 mb-4">System Partitioning</h3>
<svg viewBox="0 0 400 300" class="system-diagram">
<rect x="50" y="50" width="300" height="200" fill="#1e293b" rx="8" />
<rect x="80" y="80" width="120" height="40" fill="#1e40af" rx="4" />
<rect x="220" y="80" width="120" height="40" fill="#1e40af" rx="4" />
<text x="140" y="100" fill="#ffffff" text-anchor="middle" font-size="12">Genome Core</text>
<rect x="220" y="140" width="120" height="40" fill="#3730a3" rx="4" />
<text x="280" y="120" fill="#ffffff" text-anchor="middle" font-size="12">Plasmid App</text>
<text x="200" y="240" fill="#60a5fa" text-anchor="middle" font-size="14" font-weight="bold">Stable Decision Logic + Swappable Components</text>
</svg>
</div>
`;
}
createScene8Visualization() {
return `
<div class="w-full max-w-lg bg-gray-800 rounded-lg p-6 shadow-xl">
<h3 class="text-lg font-semibold text-blue-400 mb-4">Performance Metrics</h3>
<svg viewBox="0 0 400 300" class="system-diagram">
<rect x="50" y="50" width="300" height="200" fill="#1e293b" rx="8" />
<rect x="120" y="100" width="160" height="80" fill="#1e293b" rx="8" />
<text x="200" y="120" fill="#10b981" text-anchor="middle" font-size="16" font-weight="bold">≥10× Enrichment</text>
<text x="200" y="160" fill="#60a5fa" text-anchor="middle" font-size="14">Target Enrichment</text>
<text x="200" y="200" fill="#ef4444" text-anchor="middle" font-size="14">False Commit Risk ≤0.1%</text>
</svg>
</div>
`;
}
createDefaultVisualization() {
return `
<div class="w-full max-w-lg bg-gray-800 rounded-lg p-6 shadow-xl">
<h3 class="text-lg font-semibold text-blue-400 mb-4">System Overview</h3>
<svg viewBox="0 0 400 300" class="system-diagram">
<rect x="50" y="50" width="300" height="200" fill="#1e293b" rx="8" />
<text x="200" y="150" fill="#60a5fa" text-anchor="middle" dominant-baseline="middle" font-size="16" font-weight="bold">Synthetic Biology QC System</text>
</svg>
</div>
`;
}
}
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
new ScrollytellingEngine();
// Set up reduced motion support
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
document.body.classList.add('reduced-motion');
}
}); |