-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.html
More file actions
719 lines (610 loc) · 27.7 KB
/
Copy pathanalysis.html
File metadata and controls
719 lines (610 loc) · 27.7 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
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>System V6 — Performance Analysis</title>
<link rel="stylesheet" href="css/styles.css">
<style>
.an-hero {
min-height: 35vh; display: flex; align-items: center; justify-content: center;
text-align: center; padding: 5rem 2rem 2rem; position: relative;
}
.an-hero::before {
content: ''; position: absolute; inset: 0;
background: radial-gradient(ellipse at 50% 80%, rgba(34,211,238,0.06) 0%, transparent 60%);
pointer-events: none;
}
.an { max-width: 1000px; margin: 0 auto; padding: 0 2rem 4rem; }
.an h2 {
font-family: var(--font-display); font-size: 1.5rem; font-weight: 700;
margin: 3rem 0 0.5rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border);
}
.an p { color: var(--text-dim); line-height: 1.7; margin-bottom: 0.8rem; font-size: 0.93rem; }
.an strong { color: var(--text); }
.chart-box {
background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
padding: 1.5rem; margin: 1.5rem 0; position: relative;
}
.chart-box h3 {
font-family: var(--font-mono); font-size: 0.85rem; color: var(--cyan); margin-bottom: 0.2rem;
}
.chart-box .sub {
font-size: 0.78rem; color: var(--text-muted); margin-bottom: 1rem;
}
.chart-box canvas { width: 100%; display: block; }
.legend { display: flex; gap: 1.2rem; flex-wrap: wrap; margin: 0.6rem 0; font-size: 0.78rem; }
.legend-item { display: flex; align-items: center; gap: 0.4rem; color: var(--text-dim); }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.insight {
background: rgba(34,211,238,0.04); border: 1px solid var(--cyan-dim);
border-radius: 8px; padding: 1rem 1.2rem; margin: 1rem 0;
font-size: 0.88rem; color: var(--text-dim);
}
.insight strong { color: var(--text); }
.insight .n { color: var(--cyan); font-family: var(--font-mono); font-weight: 600; }
.math-box {
background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
padding: 1.2rem 1.5rem; margin: 1rem 0; font-family: var(--font-mono); font-size: 0.85rem;
color: var(--text-dim); line-height: 1.8;
}
.math-box .label { color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; }
.math-box .val { color: var(--cyan); font-weight: 600; }
.math-box .bad { color: var(--red); font-weight: 600; }
.math-box .good { color: var(--green); font-weight: 600; }
/* Half-duplex visual */
.hd-compare {
display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin: 1.5rem 0;
}
.hd-card {
padding: 1.2rem; border-radius: 10px; text-align: center;
}
.hd-card.bad { background: rgba(248,113,113,0.04); border: 1px solid var(--red-dim); }
.hd-card.good { background: rgba(34,211,238,0.04); border: 1px solid var(--cyan-dim); }
.hd-card h4 { font-family: var(--font-mono); font-size: 0.8rem; margin-bottom: 0.5rem; }
.hd-card.bad h4 { color: var(--red); }
.hd-card.good h4 { color: var(--cyan); }
.hd-card canvas { width: 100%; display: block; margin: 0.5rem auto; }
.hd-card p { font-size: 0.82rem; color: var(--text-dim); margin: 0; }
@media (max-width: 700px) { .hd-compare { grid-template-columns: 1fr; } }
</style>
</head>
<body>
<nav id="navbar">
<div class="nav-inner">
<a href="index.html" class="logo">MESH<span>ROUTE</span></a>
<ul id="nav-menu">
<li><a href="index.html">Presentation</a></li>
<li><a href="simulator.html" style="color:var(--cyan)">Simulator</a></li>
<li><a href="how-it-works.html">How It Works</a></li>
<li><a href="analysis.html" class="active">Analysis</a></li>
<li><a href="summary.html">Summary</a></li>
</ul>
</div>
</nav>
<div class="an-hero">
<div>
<div class="hero-tag" style="opacity:1;animation:none">Data-Driven — Every Claim Measured</div>
<h1 class="hero-title" style="opacity:1;animation:none;font-size:clamp(1.8rem,4vw,3rem)">Performance <span class="accent">Analysis</span></h1>
<p class="hero-sub" style="opacity:1;animation:none;max-width:640px;margin:0.5rem auto">
System V6 vs Managed Flooding across 6 scenarios. Half-duplex radio, collisions, realistic LoRa EU868.
</p>
</div>
</div>
<div class="an">
<!-- 1. Delivery Rate -->
<h2>1. Delivery Rate Comparison</h2>
<p>The core question: <strong>what percentage of messages actually arrive?</strong></p>
<div class="chart-box">
<h3>Delivery Rate by Scenario</h3>
<div class="sub">Managed Flooding vs System V6 — higher is better</div>
<div class="legend">
<div class="legend-item"><div class="legend-dot" style="background:#f87171"></div>Managed Flood</div>
<div class="legend-item"><div class="legend-dot" style="background:#22d3ee"></div>System V6</div>
</div>
<canvas id="chart-delivery" height="340"></canvas>
</div>
<div class="insight">
<strong>Key finding:</strong> System V6 delivers <span class="n">3.7x–22x</span> more messages than managed flooding. In small/medium networks, System V6 achieves <span class="n">99–100%</span> delivery while flooding collapses to <span class="n">16–87%</span> under half-duplex.
</div>
<!-- 2. TX Efficiency -->
<h2>2. TX Efficiency</h2>
<p>Delivery rate alone is not enough — <strong>how many radio transmissions</strong> does each approach burn? Log scale reveals the gap.</p>
<div class="chart-box">
<h3>Total TX Count (log scale)</h3>
<div class="sub">Lower is better — less airtime consumed, more capacity for other traffic</div>
<div class="legend">
<div class="legend-item"><div class="legend-dot" style="background:#f87171"></div>Managed Flood</div>
<div class="legend-item"><div class="legend-dot" style="background:#22d3ee"></div>System V6</div>
</div>
<canvas id="chart-tx" height="340"></canvas>
</div>
<div class="insight">
At Bay Area 1200-node scale, System V6 uses <span class="n">6.5x fewer TX</span> than managed flooding while delivering <span class="n">22x more messages</span>. In small networks, the TX savings are <span class="n">10x</span>.
</div>
<!-- 3. Half-Duplex Cascade -->
<h2>3. The Half-Duplex Cascade Problem</h2>
<p>Half-duplex radios cannot transmit and receive simultaneously. When a mountain node broadcasts, <strong>all neighbors are blocked</strong> from receiving other traffic. This cascade effect is why flooding collapses at scale.</p>
<div class="hd-compare">
<div class="hd-card bad">
<h4>Flood: Mountain Node Broadcasts</h4>
<canvas id="canvas-hd-flood" height="200"></canvas>
<p>234 neighbors all blocked simultaneously.<br>Massive collision cascade.</p>
</div>
<div class="hd-card good">
<h4>System V6: Directed TX</h4>
<canvas id="canvas-hd-direct" height="200"></canvas>
<p>1 neighbor receives. 233 others remain free.<br>Minimal channel impact.</p>
</div>
</div>
<div class="insight">
This is the fundamental difference. A flood TX blocks <span class="n">N</span> neighbors. A directed TX blocks <span class="n">1</span>. With 234 neighbors on a mountain node, that is a <span class="n">234x</span> difference in channel impact per transmission.
</div>
<!-- 4. Path Quality Analysis -->
<h2>4. Path Quality — Why Dijkstra Beats BFS</h2>
<p>BFS finds the <strong>shortest</strong> path (fewest hops). Dijkstra finds the <strong>most reliable</strong> path (best link quality product). In real terrain, these are very different.</p>
<div class="math-box">
<div class="label">Mountain Path (BFS choice: 2 hops)</div>
Links: [0.05, 0.05] → P(delivery) = 0.05 × 0.05 = <span class="bad">0.25%</span><br>
With 3 retries: 1 − (1−0.0025)³ = <span class="bad">0.75%</span>
</div>
<div class="math-box">
<div class="label">Hill Path (Dijkstra choice: 5 hops)</div>
Links: [0.7, 0.6, 0.5, 0.6, 0.7] → P(delivery) = 0.7 × 0.6 × 0.5 × 0.6 × 0.7 = <span class="good">8.82%</span><br>
Per-hop with 3 retries: [0.973, 0.936, 0.875, 0.936, 0.973]<br>
P(end-to-end) = 0.973 × 0.936 × 0.875 × 0.936 × 0.973 = <span class="good">72.6%</span>
</div>
<div class="chart-box">
<h3>Path Reliability: Mountain (2-hop) vs Hill (5-hop)</h3>
<div class="sub">Per-hop retries transform a mediocre path into a reliable one — but only if individual links are decent</div>
<canvas id="chart-path" height="240"></canvas>
</div>
<div class="insight">
The 5-hop hill path is <span class="n">97x</span> more reliable than the 2-hop mountain path (72.6% vs 0.75%). BFS would choose the mountain. Dijkstra chooses the hills. <strong>Reliable path > short path.</strong>
</div>
<!-- 5. Scaling Behavior -->
<h2>5. Scaling Behavior</h2>
<p>The most surprising result: System V6 <strong>improves</strong> with more nodes while flooding <strong>degrades</strong>.</p>
<div class="chart-box">
<h3>Delivery Rate vs Network Size</h3>
<div class="sub">Bay Area topology: 235 nodes vs 1,200 nodes</div>
<div class="legend">
<div class="legend-item"><div class="legend-dot" style="background:#f87171"></div>Managed Flood</div>
<div class="legend-item"><div class="legend-dot" style="background:#22d3ee"></div>System V6</div>
</div>
<canvas id="chart-scaling" height="280"></canvas>
</div>
<div class="insight">
More nodes = more flooding collisions (6% → 4% delivery). But more nodes also = more overhearing = richer route tables. System V6 goes from <span class="n">84%</span> to <span class="n">88%</span> delivery. <strong>Density helps System V6, hurts flooding.</strong>
</div>
<!-- 6. Phase Breakdown -->
<h2>6. Phase Breakdown — How Messages Get Delivered</h2>
<p>For Bay Area 235 nodes: which protocol phase delivers each message?</p>
<div class="chart-box">
<h3>Message Delivery by Phase (Bay Area 235n, 200 messages)</h3>
<div class="sub">System V6’s four-phase fallback in action</div>
<canvas id="chart-phases" height="260"></canvas>
</div>
<div class="insight">
<span class="n">80</span> messages (40%) delivered by <strong>direct routing</strong> — zero exploration needed. <span class="n">7</span> by random walk. <span class="n">80</span> by scoped mini-flood. <span class="n">33</span> dropped (unreachable partitions). The protocol correctly escalates: try cheap first, expensive only when needed.
</div>
</div>
<footer>
<p>System V6 — Performance Analysis</p>
<p style="margin-top:0.3rem;font-size:0.75rem">By <strong style="color:var(--cyan)">Clemens Simon</strong> · 2026 · Data from Python simulator with half-duplex radio model</p>
</footer>
<script src="js/ui.js"></script>
<script>
(function() {
'use strict';
const C = {
cyan: '#22d3ee', red: '#f87171', green: '#4ade80', yellow: '#fbbf24',
orange: '#fb923c', purple: '#a78bfa', teal: '#14b8a6',
text: '#e2e8f0', dim: '#94a3b8', muted: '#64748b',
bg: '#0f172a', card: '#1a2236', border: '#2a3654',
};
// Data
const scenarios = [
{ label: 'Small\n(20n)', mfDel: 87, wfDel: 100, mfTx: 1640, wfTx: 159 },
{ label: 'Medium\n(100n)', mfDel: 27, wfDel: 100, mfTx: 3380, wfTx: 368 },
{ label: 'Kill 20%', mfDel: 16, wfDel: 100, mfTx: 2696, wfTx: 383 },
{ label: 'Stress\n30%', mfDel: 19, wfDel: 99, mfTx: 3380, wfTx: 492 },
{ label: 'Bay Area\n(235n)', mfDel: 6, wfDel: 84, mfTx: 6752, wfTx: 8894 },
{ label: 'Bay Area\n(1200n)', mfDel: 4, wfDel: 88, mfTx: 38644, wfTx: 5909 },
];
function initCanvas(id) {
const canvas = document.getElementById(id);
if (!canvas) return null;
const dpr = window.devicePixelRatio || 1;
const rect = canvas.getBoundingClientRect();
const w = rect.width || canvas.parentElement.clientWidth || 800;
const h = canvas.height || 340;
canvas.width = w * dpr;
canvas.height = h * dpr;
canvas.style.height = h + 'px';
const ctx = canvas.getContext('2d');
ctx.scale(dpr, dpr);
ctx.W = w; ctx.H = h;
return ctx;
}
// ── 1. Delivery Rate Bar Chart ──
function drawDelivery() {
const ctx = initCanvas('chart-delivery');
if (!ctx) return;
const W = ctx.W, H = ctx.H;
const pad = { top: 20, right: 20, bottom: 60, left: 50 };
const chartW = W - pad.left - pad.right;
const chartH = H - pad.top - pad.bottom;
const n = scenarios.length;
const gap = chartW / n;
const barW = Math.min(gap * 0.28, 32);
ctx.clearRect(0, 0, W, H);
// Grid
ctx.strokeStyle = C.border; ctx.lineWidth = 0.5;
ctx.font = '10px monospace'; ctx.fillStyle = C.muted; ctx.textAlign = 'right';
for (let p = 0; p <= 100; p += 25) {
const y = pad.top + chartH - (p / 100) * chartH;
ctx.beginPath(); ctx.moveTo(pad.left, y); ctx.lineTo(W - pad.right, y); ctx.stroke();
ctx.fillText(p + '%', pad.left - 6, y + 3);
}
for (let i = 0; i < n; i++) {
const s = scenarios[i];
const cx = pad.left + gap * i + gap / 2;
// MF bar
const mfH = (s.mfDel / 100) * chartH;
ctx.fillStyle = C.red; ctx.globalAlpha = 0.8;
ctx.fillRect(cx - barW - 2, pad.top + chartH - mfH, barW, mfH);
// WF bar
const wfH = (s.wfDel / 100) * chartH;
ctx.fillStyle = C.cyan; ctx.globalAlpha = 0.8;
ctx.fillRect(cx + 2, pad.top + chartH - wfH, barW, wfH);
ctx.globalAlpha = 1;
// Values
ctx.font = 'bold 10px monospace'; ctx.textAlign = 'center';
ctx.fillStyle = C.red;
ctx.fillText(s.mfDel + '%', cx - barW / 2 - 2, pad.top + chartH - mfH - 5);
ctx.fillStyle = C.cyan;
ctx.fillText(s.wfDel + '%', cx + barW / 2 + 2, pad.top + chartH - wfH - 5);
// Label
ctx.font = '9px monospace'; ctx.fillStyle = C.dim; ctx.textAlign = 'center';
const lines = s.label.split('\n');
lines.forEach((l, li) => ctx.fillText(l, cx, pad.top + chartH + 15 + li * 12));
}
}
// ── 2. TX Efficiency (log scale) ──
function drawTX() {
const ctx = initCanvas('chart-tx');
if (!ctx) return;
const W = ctx.W, H = ctx.H;
const pad = { top: 20, right: 20, bottom: 60, left: 55 };
const chartW = W - pad.left - pad.right;
const chartH = H - pad.top - pad.bottom;
const n = scenarios.length;
const gap = chartW / n;
const barW = Math.min(gap * 0.28, 32);
const maxLog = 5; // 10^5 = 100,000
ctx.clearRect(0, 0, W, H);
// Grid
ctx.strokeStyle = C.border; ctx.lineWidth = 0.5;
ctx.font = '10px monospace'; ctx.fillStyle = C.muted; ctx.textAlign = 'right';
const labels = ['1', '10', '100', '1K', '10K', '100K'];
for (let i = 0; i <= maxLog; i++) {
const y = pad.top + chartH - (i / maxLog) * chartH;
ctx.beginPath(); ctx.moveTo(pad.left, y); ctx.lineTo(W - pad.right, y); ctx.stroke();
ctx.fillText(labels[i], pad.left - 6, y + 3);
}
for (let i = 0; i < n; i++) {
const s = scenarios[i];
const cx = pad.left + gap * i + gap / 2;
// MF bar
const mfLogH = (Math.log10(Math.max(1, s.mfTx)) / maxLog) * chartH;
ctx.fillStyle = C.red; ctx.globalAlpha = 0.8;
ctx.fillRect(cx - barW - 2, pad.top + chartH - mfLogH, barW, mfLogH);
// WF bar
const wfLogH = (Math.log10(Math.max(1, s.wfTx)) / maxLog) * chartH;
ctx.fillStyle = C.cyan; ctx.globalAlpha = 0.8;
ctx.fillRect(cx + 2, pad.top + chartH - wfLogH, barW, wfLogH);
ctx.globalAlpha = 1;
// Values
ctx.font = '9px monospace'; ctx.textAlign = 'center';
ctx.fillStyle = C.red;
ctx.fillText(fmtNum(s.mfTx), cx - barW / 2 - 2, pad.top + chartH - mfLogH - 5);
ctx.fillStyle = C.cyan;
ctx.fillText(fmtNum(s.wfTx), cx + barW / 2 + 2, pad.top + chartH - wfLogH - 5);
// Label
ctx.font = '9px monospace'; ctx.fillStyle = C.dim; ctx.textAlign = 'center';
const lines = s.label.split('\n');
lines.forEach((l, li) => ctx.fillText(l, cx, pad.top + chartH + 15 + li * 12));
}
// "Lower = better" arrow
ctx.strokeStyle = C.green; ctx.lineWidth = 1.5;
const ax = pad.left + 14, ay1 = pad.top + chartH - 40, ay2 = pad.top + chartH - 10;
ctx.beginPath(); ctx.moveTo(ax, ay1); ctx.lineTo(ax, ay2); ctx.stroke();
ctx.beginPath(); ctx.moveTo(ax - 3, ay2 - 4); ctx.lineTo(ax, ay2); ctx.lineTo(ax + 3, ay2 - 4); ctx.stroke();
ctx.fillStyle = C.green; ctx.font = 'bold 8px monospace'; ctx.textAlign = 'center';
ctx.fillText('Better', ax, ay1 - 5);
}
function fmtNum(v) {
if (v >= 1e6) return (v / 1e6).toFixed(1) + 'M';
if (v >= 1e3) return (v / 1e3).toFixed(v >= 1e4 ? 0 : 1) + 'K';
return String(Math.round(v));
}
// ── 3. Half-Duplex Visual ──
function drawHDFlood() {
const ctx = initCanvas('canvas-hd-flood');
if (!ctx) return;
const W = ctx.W, H = ctx.H;
ctx.clearRect(0, 0, W, H);
const cx = W / 2, cy = H / 2;
// Mountain node (center)
ctx.beginPath(); ctx.arc(cx, cy, 14, 0, Math.PI * 2);
ctx.fillStyle = C.red; ctx.globalAlpha = 0.9; ctx.fill(); ctx.globalAlpha = 1;
ctx.font = 'bold 9px monospace'; ctx.fillStyle = '#fff'; ctx.textAlign = 'center';
ctx.fillText('TX', cx, cy + 3);
// Blocked neighbors
const ringCount = 24;
for (let i = 0; i < ringCount; i++) {
const angle = (i / ringCount) * Math.PI * 2;
const r = 55 + Math.random() * 25;
const nx = cx + Math.cos(angle) * r;
const ny = cy + Math.sin(angle) * r;
// Blocking wave
ctx.strokeStyle = 'rgba(248,113,113,0.2)'; ctx.lineWidth = 1;
ctx.beginPath(); ctx.moveTo(cx, cy); ctx.lineTo(nx, ny); ctx.stroke();
ctx.beginPath(); ctx.arc(nx, ny, 5, 0, Math.PI * 2);
ctx.fillStyle = 'rgba(248,113,113,0.5)'; ctx.fill();
}
// Broadcast wave rings
for (let r = 30; r <= 80; r += 20) {
ctx.beginPath(); ctx.arc(cx, cy, r, 0, Math.PI * 2);
ctx.strokeStyle = 'rgba(248,113,113,' + (0.3 - r * 0.003) + ')';
ctx.lineWidth = 1.5; ctx.stroke();
}
ctx.font = 'bold 10px monospace'; ctx.fillStyle = C.red; ctx.textAlign = 'center';
ctx.fillText('234 neighbors BLOCKED', cx, H - 10);
}
function drawHDDirect() {
const ctx = initCanvas('canvas-hd-direct');
if (!ctx) return;
const W = ctx.W, H = ctx.H;
ctx.clearRect(0, 0, W, H);
const cx = W / 2, cy = H / 2;
// Source node
ctx.beginPath(); ctx.arc(cx - 50, cy, 14, 0, Math.PI * 2);
ctx.fillStyle = C.cyan; ctx.globalAlpha = 0.9; ctx.fill(); ctx.globalAlpha = 1;
ctx.font = 'bold 9px monospace'; ctx.fillStyle = '#fff'; ctx.textAlign = 'center';
ctx.fillText('TX', cx - 50, cy + 3);
// Target node
ctx.beginPath(); ctx.arc(cx + 50, cy, 14, 0, Math.PI * 2);
ctx.fillStyle = C.green; ctx.globalAlpha = 0.9; ctx.fill(); ctx.globalAlpha = 1;
ctx.font = 'bold 9px monospace'; ctx.fillStyle = '#fff'; ctx.textAlign = 'center';
ctx.fillText('RX', cx + 50, cy + 3);
// Directed arrow
ctx.strokeStyle = C.cyan; ctx.lineWidth = 2.5;
ctx.beginPath(); ctx.moveTo(cx - 34, cy); ctx.lineTo(cx + 34, cy); ctx.stroke();
ctx.beginPath();
ctx.moveTo(cx + 30, cy - 5); ctx.lineTo(cx + 36, cy); ctx.lineTo(cx + 30, cy + 5);
ctx.stroke();
// Free neighbors (greyed out, not blocked)
const freeCount = 16;
for (let i = 0; i < freeCount; i++) {
const angle = (i / freeCount) * Math.PI * 2;
const r = 60 + Math.random() * 20;
const nx = cx + Math.cos(angle) * r;
const ny = cy + Math.sin(angle) * r;
ctx.beginPath(); ctx.arc(nx, ny, 4, 0, Math.PI * 2);
ctx.fillStyle = 'rgba(148,163,184,0.25)'; ctx.fill();
}
ctx.font = 'bold 10px monospace'; ctx.fillStyle = C.green; ctx.textAlign = 'center';
ctx.fillText('233 neighbors FREE', cx, H - 10);
}
// ── 4. Path Quality Chart ──
function drawPath() {
const ctx = initCanvas('chart-path');
if (!ctx) return;
const W = ctx.W, H = ctx.H;
const pad = { top: 30, right: 20, bottom: 40, left: 50 };
const chartW = W - pad.left - pad.right;
const chartH = H - pad.top - pad.bottom;
ctx.clearRect(0, 0, W, H);
// Grid
ctx.strokeStyle = C.border; ctx.lineWidth = 0.5;
ctx.font = '10px monospace'; ctx.fillStyle = C.muted; ctx.textAlign = 'right';
for (let p = 0; p <= 100; p += 25) {
const y = pad.top + chartH - (p / 100) * chartH;
ctx.beginPath(); ctx.moveTo(pad.left, y); ctx.lineTo(W - pad.right, y); ctx.stroke();
ctx.fillText(p + '%', pad.left - 6, y + 3);
}
const barW = 60;
const pairs = [
{ label: 'Mountain\n(2 hops)', raw: 0.25, retry: 0.75, color: C.red },
{ label: 'Hill\n(5 hops)', raw: 8.82, retry: 72.6, color: C.green },
];
const gap = chartW / pairs.length;
for (let i = 0; i < pairs.length; i++) {
const p = pairs[i];
const cx = pad.left + gap * i + gap / 2;
// Raw bar (dim)
const rawH = (p.raw / 100) * chartH;
ctx.fillStyle = p.color; ctx.globalAlpha = 0.25;
ctx.fillRect(cx - barW / 2 - 18, pad.top + chartH - rawH, barW * 0.7, rawH);
// Retry bar (bright)
const retH = (p.retry / 100) * chartH;
ctx.globalAlpha = 0.85;
ctx.fillRect(cx + 2, pad.top + chartH - retH, barW * 0.7, retH);
ctx.globalAlpha = 1;
// Values
ctx.font = 'bold 10px monospace'; ctx.textAlign = 'center';
ctx.fillStyle = p.color;
if (rawH > 5) {
ctx.fillText(p.raw + '%', cx - barW / 2 + 3, pad.top + chartH - rawH - 5);
} else {
ctx.fillText(p.raw + '%', cx - barW / 2 + 3, pad.top + chartH - 10);
}
ctx.fillText(p.retry + '%', cx + barW * 0.35 + 2, pad.top + chartH - retH - 5);
// Sub-labels
ctx.font = '8px monospace'; ctx.fillStyle = C.muted;
ctx.fillText('raw', cx - barW / 2 + 3, pad.top + chartH + 12);
ctx.fillText('+retry', cx + barW * 0.35 + 2, pad.top + chartH + 12);
// Label
ctx.font = '10px monospace'; ctx.fillStyle = C.dim; ctx.textAlign = 'center';
const lines = p.label.split('\n');
lines.forEach((l, li) => ctx.fillText(l, cx, pad.top + chartH + 24 + li * 12));
}
}
// ── 5. Scaling Behavior ──
function drawScaling() {
const ctx = initCanvas('chart-scaling');
if (!ctx) return;
const W = ctx.W, H = ctx.H;
const pad = { top: 30, right: 30, bottom: 50, left: 50 };
const chartW = W - pad.left - pad.right;
const chartH = H - pad.top - pad.bottom;
ctx.clearRect(0, 0, W, H);
// Grid
ctx.strokeStyle = C.border; ctx.lineWidth = 0.5;
ctx.font = '10px monospace'; ctx.fillStyle = C.muted; ctx.textAlign = 'right';
for (let p = 0; p <= 100; p += 25) {
const y = pad.top + chartH - (p / 100) * chartH;
ctx.beginPath(); ctx.moveTo(pad.left, y); ctx.lineTo(W - pad.right, y); ctx.stroke();
ctx.fillText(p + '%', pad.left - 6, y + 3);
}
// X axis labels
const points = [
{ nodes: 235, label: '235 nodes' },
{ nodes: 1200, label: '1,200 nodes' },
];
const mfData = [6, 4];
const wfData = [84, 88];
const x1 = pad.left + chartW * 0.25;
const x2 = pad.left + chartW * 0.75;
const xs = [x1, x2];
ctx.textAlign = 'center';
points.forEach((p, i) => {
ctx.fillStyle = C.dim; ctx.font = '10px monospace';
ctx.fillText(p.label, xs[i], pad.top + chartH + 16);
});
// MF line
ctx.strokeStyle = C.red; ctx.lineWidth = 2.5;
ctx.beginPath();
ctx.moveTo(x1, pad.top + chartH - (mfData[0] / 100) * chartH);
ctx.lineTo(x2, pad.top + chartH - (mfData[1] / 100) * chartH);
ctx.stroke();
// WF line
ctx.strokeStyle = C.cyan; ctx.lineWidth = 2.5;
ctx.beginPath();
ctx.moveTo(x1, pad.top + chartH - (wfData[0] / 100) * chartH);
ctx.lineTo(x2, pad.top + chartH - (wfData[1] / 100) * chartH);
ctx.stroke();
// Dots and labels
for (let i = 0; i < 2; i++) {
// MF dot
const mfY = pad.top + chartH - (mfData[i] / 100) * chartH;
ctx.beginPath(); ctx.arc(xs[i], mfY, 6, 0, Math.PI * 2);
ctx.fillStyle = C.red; ctx.fill();
ctx.font = 'bold 11px monospace'; ctx.fillStyle = C.red; ctx.textAlign = 'center';
ctx.fillText(mfData[i] + '%', xs[i], mfY - 12);
// WF dot
const wfY = pad.top + chartH - (wfData[i] / 100) * chartH;
ctx.beginPath(); ctx.arc(xs[i], wfY, 6, 0, Math.PI * 2);
ctx.fillStyle = C.cyan; ctx.fill();
ctx.font = 'bold 11px monospace'; ctx.fillStyle = C.cyan; ctx.textAlign = 'center';
ctx.fillText(wfData[i] + '%', xs[i], wfY - 12);
}
// Trend annotations
ctx.font = 'bold 10px monospace'; ctx.textAlign = 'left';
const midX = (x1 + x2) / 2;
// WF trend arrow (up)
const wfMidY = pad.top + chartH - (86 / 100) * chartH;
ctx.fillStyle = C.green;
ctx.fillText('+4pp', midX + 5, wfMidY - 2);
// MF trend arrow (down)
const mfMidY = pad.top + chartH - (5 / 100) * chartH;
ctx.fillStyle = C.red;
ctx.fillText('-2pp', midX + 5, mfMidY - 2);
// Legend labels
ctx.font = '10px monospace';
ctx.fillStyle = C.cyan; ctx.textAlign = 'right';
ctx.fillText('System V6', W - pad.right, pad.top + 15);
ctx.fillStyle = C.red;
ctx.fillText('Managed Flood', W - pad.right, pad.top + 30);
}
// ── 6. Phase Breakdown (donut) ──
function drawPhases() {
const ctx = initCanvas('chart-phases');
if (!ctx) return;
const W = ctx.W, H = ctx.H;
ctx.clearRect(0, 0, W, H);
const data = [
{ label: 'Directed', value: 80, color: C.cyan },
{ label: 'Walk', value: 7, color: C.teal },
{ label: 'Mini-Flood', value: 80, color: C.yellow },
{ label: 'Dropped', value: 33, color: '#64748b' },
];
const total = data.reduce((s, d) => s + d.value, 0);
const cx = W * 0.38, cy = H / 2;
const outerR = Math.min(cx - 30, cy - 20, 100);
const innerR = outerR * 0.55;
let startAngle = -Math.PI / 2;
data.forEach(d => {
const sliceAngle = (d.value / total) * Math.PI * 2;
const endAngle = startAngle + sliceAngle;
ctx.beginPath();
ctx.arc(cx, cy, outerR, startAngle, endAngle);
ctx.arc(cx, cy, innerR, endAngle, startAngle, true);
ctx.closePath();
ctx.fillStyle = d.color; ctx.globalAlpha = 0.85;
ctx.fill();
ctx.globalAlpha = 1;
// Percentage in slice (if big enough)
if (sliceAngle > 0.3) {
const midAngle = startAngle + sliceAngle / 2;
const labelR = (outerR + innerR) / 2;
const lx = cx + Math.cos(midAngle) * labelR;
const ly = cy + Math.sin(midAngle) * labelR;
ctx.font = 'bold 11px monospace'; ctx.fillStyle = '#fff';
ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
ctx.fillText(d.value, lx, ly);
}
startAngle = endAngle;
});
// Center text
ctx.font = 'bold 14px monospace'; ctx.fillStyle = C.text;
ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
ctx.fillText('200', cx, cy - 6);
ctx.font = '9px monospace'; ctx.fillStyle = C.dim;
ctx.fillText('messages', cx, cy + 10);
// Legend on right
const legendX = W * 0.62;
let legendY = cy - data.length * 15;
data.forEach(d => {
const pct = ((d.value / total) * 100).toFixed(0);
ctx.fillStyle = d.color;
ctx.fillRect(legendX, legendY, 14, 14);
ctx.font = '12px monospace'; ctx.fillStyle = C.text;
ctx.textAlign = 'left'; ctx.textBaseline = 'middle';
ctx.fillText(d.label, legendX + 20, legendY + 7);
ctx.fillStyle = C.dim; ctx.font = '11px monospace';
ctx.fillText(d.value + ' (' + pct + '%)', legendX + 20, legendY + 22);
legendY += 38;
});
ctx.textBaseline = 'alphabetic';
}
// ── Render all ──
function renderAll() {
drawDelivery();
drawTX();
drawHDFlood();
drawHDDirect();
drawPath();
drawScaling();
drawPhases();
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', renderAll);
else renderAll();
setTimeout(renderAll, 500);
window.addEventListener('resize', renderAll);
})();
</script>
</body>
</html>