-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgradient_map.html
More file actions
225 lines (191 loc) · 8.72 KB
/
gradient_map.html
File metadata and controls
225 lines (191 loc) · 8.72 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Pulsed Gradient History: Tags Ignited</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
:root {
--bg:#0b0c10; --panel:#10131a; --fg:#e9eef8; --muted:#97a3b6;
--edge:#b9c7dd; --edge-lit:#e7f0ff; --node:#6aa6ff; --node-lit:#a7caff;
--chip:#0f1522; --chip-border:#2a3442; --chip-hover:#172033; --chip-text:#e6edf3;
}
html,body { height:100%; margin:0; background:var(--bg); color:var(--fg); font:14px/1.35 system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial }
svg { width:100%; height:100% ; display:block }
/* UI card */
.wrap { position:fixed; top:14px; right:14px; background:linear-gradient(180deg,var(--panel),rgba(16,19,26,.92));
border:1px solid rgba(255,255,255,.08); border-radius:14px; padding:12px 14px; box-shadow:0 10px 28px rgba(0,0,0,.35); max-width:min(740px,70vw) }
.title { font-weight:800; margin-bottom:4px }
.sub { color:var(--muted); margin:0 0 8px 0; font-size:11px; line-height:1.35 } /* smaller explainer */
.row { display:flex; gap:8px; align-items:center; flex-wrap:wrap }
.chip, .pill { font-size:13px } /* match all controls */
.chip { display:inline-flex; align-items:center; gap:6px; background:var(--chip); border:1px solid var(--chip-border); color:var(--chip-text);
border-radius:999px; padding:6px 12px; cursor:pointer; user-select:none }
.chip:active, .chip:hover { background:var(--chip-hover) }
.chip[aria-pressed="true"]{ outline:2px solid #2d4a7a }
.pill { background:var(--chip); border:1px solid var(--chip-border); border-radius:10px; padding:6px 10px; color:var(--chip-text) }
.pulse-pill { width:100%; margin-top:6px; font-size:12px; /* smaller pulse line */
max-width:calc(70vw - 28px); overflow:hidden; text-overflow:ellipsis; white-space:nowrap }
/* graph styles */
.link { stroke:var(--edge); stroke-opacity:.10 } /* base slightly lighter */
.link.dim { stroke-opacity:.04 }
.link.lit { stroke:var(--edge-lit); stroke-opacity:.26; stroke-width:.95px } /* fainter + thinner */
.node { fill:var(--node); opacity:.45 }
.node.lit { fill:var(--node-lit); opacity:.84 } /* less dominant */
.label { font-size:12px; fill:#d9e7ff; pointer-events:none; paint-order:stroke; stroke:#0b0c10; stroke-width:3px; opacity:0; }
.label.lit { opacity:.96 }
</style>
<script src="https://cdn.jsdelivr.net/npm/d3@7"></script>
<script src="data.js"></script>
<script src="normalize_data.js"></script> <!-- 👈 inserted here -->
<script defer src="map.js"></script>
</head>
<body>
<svg id="g" role="img" aria-label="Pulsed Gradient Map"></svg>
<div class="wrap" id="ui">
<div class="title">Pulsed Gradient History: Tags Ignited</div>
<div class="sub">Each pulse is a gradient. As it passes, its tags ignite; only links between lit tags intensify. Pan/zoom is live.</div>
<!-- controls row -->
<div class="row">
<button class="chip" id="play" aria-pressed="false">▶︎ Play</button>
<button class="chip" id="pause" aria-pressed="true">⏸︎ Pause</button>
<span class="pill">Speed <span id="speedVal">2.0</span></span>
<button class="chip" data-speed="1">1×</button>
<button class="chip" data-speed="2">2×</button>
<button class="chip" data-speed="3">3×</button>
</div>
<!-- active pulse always shown beneath controls -->
<div class="pill pulse-pill" id="pulseTitle">Pulse —</div>
</div>
<script>
(function(){
const Q = new URLSearchParams(location.search);
const AUTOPLAY = Q.get('autoplay') === '1';
const SPACING = Math.max(1, +(Q.get('spacing')||6));
const speedEl = document.getElementById('speedVal');
const playBtn = document.getElementById('play');
const pauseBtn = document.getElementById('pause');
const pulseTitle = document.getElementById('pulseTitle');
const DATA = (window.PHI_DATA && typeof window.PHI_DATA === 'object') ? window.PHI_DATA : { nodes:[], links:[] };
const nodes = (DATA.nodes||[]).map(d => ({ id: d.id, centrality: d.centrality }));
const idToNode = new Map(nodes.map(n => [n.id, n]));
const links = (DATA.links||[])
.map(l => ({ source: idToNode.get(l.source) || {id:l.source}, target: idToNode.get(l.target) || {id:l.target} }))
.filter(l => l.source && l.source.id && l.target && l.target.id);
// reconstruct pulse list from pulsesByTag
const pulseMap = new Map();
const byTag = DATA.pulsesByTag || {};
for (const [tag, arr] of Object.entries(byTag)) {
if (!Array.isArray(arr)) continue;
for (const p of arr) {
const key = (p.id || p.title || p.date || JSON.stringify(p));
if (!pulseMap.has(key)) pulseMap.set(key, { title:p.title||p.id||'Pulse', date:p.date||'', tags:new Set() });
pulseMap.get(key).tags.add(tag);
}
}
let pulses = Array.from(pulseMap.values())
.map(x => ({...x, tags:[...x.tags]}))
.sort((a,b) => String(a.date||'').localeCompare(String(b.date||'')));
if (!pulses.length) pulses = [{title:'Pulse', date:'', tags:nodes.slice(0,8).map(n=>n.id)}];
// svg + layers
const svg = d3.select('#g');
const root = svg.append('g');
const linkLayer = root.append('g').attr('class','links');
const nodeLayer = root.append('g').attr('class','nodes');
const labelLayer= root.append('g').attr('class','labels');
const zoom = d3.zoom().scaleExtent([0.35, 4]).on('zoom', ev => root.attr('transform', ev.transform));
svg.call(zoom);
// layout
const deg = new Map();
links.forEach(l => {
deg.set(l.source.id, (deg.get(l.source.id)||0)+1);
deg.set(l.target.id, (deg.get(l.target.id)||0)+1);
});
const rScale = d3.scaleSqrt()
.domain([1, Math.max(2, d3.max(Array.from(deg.values()))||3)])
.range([3, 12]);
const sim = d3.forceSimulation(nodes)
.force('link', d3.forceLink(links).id(d=>d.id).distance(60).strength(0.35))
.force('charge', d3.forceManyBody().strength(-180))
.force('center', d3.forceCenter(window.innerWidth/2, window.innerHeight/2))
.force('collide', d3.forceCollide().radius(d => rScale((deg.get(d.id)||1))*1.4));
window.addEventListener('resize', () => {
sim.force('center', d3.forceCenter(window.innerWidth/2, window.innerHeight/2));
sim.alpha(0.1).restart();
});
// draw
const linkSel = linkLayer.selectAll('line')
.data(links)
.join('line')
.attr('class','link');
const nodeSel = nodeLayer.selectAll('circle')
.data(nodes, d=>d.id)
.join('circle')
.attr('class','node')
.attr('r', d => rScale((deg.get(d.id)||1)));
const labelSel = labelLayer.selectAll('text')
.data(nodes, d=>d.id)
.join('text')
.attr('class','label')
.attr('text-anchor','middle')
.text(d=>d.id);
sim.on('tick', () => {
linkSel
.attr('x1', d=>d.source.x).attr('y1', d=>d.source.y)
.attr('x2', d=>d.target.x).attr('y2', d=>d.target.y);
nodeSel.attr('cx', d=>d.x).attr('cy', d=>d.y);
labelSel.attr('x', d=>d.x).attr('y', d=>d.y - rScale((deg.get(d.id)||1)) - 6);
});
setTimeout(()=> sim.alphaTarget(0).alpha(0.02), 1200);
// pulser
let k = 0;
let playing = AUTOPLAY;
let speed = 2; // 1/2/3
speedEl.textContent = speed.toFixed(1);
function setUIPlaying(p){
playBtn.setAttribute('aria-pressed', String(p));
pauseBtn.setAttribute('aria-pressed', String(!p));
}
setUIPlaying(playing);
function formatPulseTitle(p){
const t = p?.title || 'Pulse';
const d = p?.date ? ` — ${p.date}` : '';
return `${t}${d}`;
}
function applyPulse(pulse){
const lit = new Set(pulse?.tags || []);
pulseTitle.textContent = formatPulseTitle(pulse);
nodeSel.classed('lit', d => lit.has(d.id));
labelSel.classed('lit', d => lit.has(d.id));
linkSel
.classed('lit', d => lit.has(d.source.id) && lit.has(d.target.id))
.classed('dim', d => !(lit.has(d.source.id) && lit.has(d.target.id)));
}
function step(){
applyPulse(pulses[k % pulses.length]);
k = (k + 1) % pulses.length;
}
playBtn.onclick = () => { playing = true; setUIPlaying(true); };
pauseBtn.onclick = () => { playing = false; setUIPlaying(false); };
document.querySelectorAll('[data-speed]').forEach(btn=>{
btn.addEventListener('click', ()=>{
speed = +btn.getAttribute('data-speed') || 2;
speedEl.textContent = speed.toFixed(1);
});
});
// show first pulse right away
applyPulse(pulses[0]);
const interval = () => (SPACING / Math.max(0.25, speed)) * 1000;
let last = performance.now();
function frame(now){
if (playing && (now - last) >= interval()){
step(); last = now;
}
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
if (AUTOPLAY) { playing = true; setUIPlaying(true); }
})();
</script>
</body>
</html>