-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvisualization.qmd
More file actions
1443 lines (1350 loc) · 59.2 KB
/
Copy pathvisualization.qmd
File metadata and controls
1443 lines (1350 loc) · 59.2 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
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Chrono AI Region Map"
description: "Cross-product attack-region dependency graph: each node is an epic-level region, edges are dependencies, colored by closure stage, shaped by automation level. Click any node for the bilingual term entry. Configuration-driven (config.json + regions.json)."
format:
html:
toc: false
page-layout: full
include-in-header:
text: |
<link rel="stylesheet" href="https://unpkg.com/cytoscape@3.30.2/dist/cytoscape.min.css">
---
```{=html}
<style>
body { background: #fbfbfa; }
/* Lock the Quarto wrapper to viewport height (minus 62px navbar) so
the map shell can fit on a 13" laptop without forcing scroll.
Wrapper paddings and Quarto's default page footer are zeroed. */
#quarto-content {
height: calc(100vh - 62px) !important;
padding: 0 !important;
overflow: hidden;
}
main.content {
padding: 0 !important; margin: 0 !important;
max-width: 100% !important;
height: calc(100vh - 62px) !important;
overflow: hidden;
}
.page-footer, #quarto-content > footer { display: none !important; }
#title-block-header { display: none; }
.map-shell {
display: grid;
grid-template-columns: minmax(0, 1fr) 240px;
grid-template-rows: auto minmax(0, 1fr);
grid-template-areas: "header header" "graph detail";
/* Parent (#quarto-content) is locked to viewport-minus-navbar, so
the shell just fills its parent. min-height is a tablet floor.
overflow:hidden + min-height:0 on grid items prevents the
detail panel's min-content from inflating the grid past parent. */
height: 100%;
min-height: 540px;
overflow: hidden;
gap: 0;
background: #fbfbfa;
border: 1px solid #e0e0e0;
}
.map-shell > * { min-height: 0; min-width: 0; }
main.content > .quarto-section-identifier { display: none; }
.quarto-container { max-width: 100% !important; padding: 0 !important; }
@media (max-width: 900px) {
.map-shell { grid-template-columns: 1fr; grid-template-areas: "header" "graph" "detail"; height: auto; }
#cy-wrap { height: 540px; } #cy { height: 100%; }
#detail { max-height: 480px; overflow-y: auto; }
}
.map-header {
grid-area: header;
padding: 0.7rem 1.2rem;
display: flex; align-items: center; justify-content: space-between; gap: 0.7rem;
border-bottom: 1px solid #e0e0e0; background: #fff;
}
.map-header h1 { margin: 0; font-size: 1.15rem; font-weight: 600; letter-spacing: 0.01em; }
.map-header .summary { font-size: 0.86rem; color: #666; }
.map-header .summary strong { color: #222; }
.map-controls { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; justify-content: flex-end; }
.lang-toggle { font-size: 0.85rem; }
.lang-toggle button {
border: 1px solid #ccc; background: white; padding: 0.2rem 0.6rem;
cursor: pointer; font-family: inherit; font-size: 0.85rem;
}
.lang-toggle button.active { background: #222; color: white; border-color: #222; }
.region-picker {
font-family: inherit; font-size: 0.88rem;
padding: 0.25rem 0.5rem; border: 1px solid #bbb; border-radius: 3px;
background: white; min-width: 220px; cursor: pointer;
}
.region-picker:focus { outline: 2px solid #2c3e50; outline-offset: -1px; }
#cy-wrap { grid-area: graph; position: relative; height: 100%; background: #fbfbfa; }
#cy { width: 100%; height: 100%; }
.zoom-controls {
position: absolute;
top: 12px; left: 12px;
display: flex; flex-direction: column; gap: 4px;
/* cytoscape-expand-collapse paints a cue canvas at z-index: 999
inside #cy-wrap. The zoom buttons must sit above it or clicks
get swallowed by the canvas. */
z-index: 1000;
}
.zoom-controls button {
width: 32px; height: 32px;
border: 1px solid #d0d0d0;
background: rgba(255, 255, 255, 0.94);
border-radius: 4px;
font-size: 1.05rem; line-height: 1;
cursor: pointer; padding: 0;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
display: flex; align-items: center; justify-content: center;
font-family: inherit; color: #333;
transition: background 0.12s;
}
.zoom-controls button:hover { background: #f4f4f4; }
.zoom-controls button:active { background: #e8e8e8; }
.zoom-controls button:focus { outline: 2px solid #2c3e50; outline-offset: 1px; }
#detail {
grid-area: detail; padding: 1.2rem; overflow-y: auto;
border-left: 1px solid #e0e0e0; background: #fff; font-size: 0.92rem;
}
#detail .hint { color: #aaa; font-style: italic; }
#detail .term-name { font-size: 1.25rem; font-weight: 600; }
#detail .term-other { color: #888; font-size: 0.95rem; margin-left: 0.4rem; font-style: italic; }
#detail .term-desc { margin-top: 0.5rem; line-height: 1.55; }
#detail .term-other-desc { margin-top: 0.4rem; color: #777; line-height: 1.5; font-style: italic; }
#detail .term-stats {
margin-top: 0.9rem; padding-top: 0.7rem; border-top: 1px dashed #ddd;
font-family: ui-monospace, monospace; font-size: 0.84rem;
}
#detail .term-stats span { display: inline-block; margin-right: 0.6rem; padding: 0.1rem 0.45rem; background: #f4f4f4; border-radius: 3px; }
#detail .term-status { margin-top: 0.55rem; display: flex; gap: 0.4rem; flex-wrap: wrap; }
#detail .status-chip { display: inline-block; padding: 0.2rem 0.55rem; border-radius: 11px; font-size: 0.8rem; font-weight: 500; }
#detail .status-chip.status-todo { background: #e8f5ee; color: #1e7a3c; }
#detail .status-chip.status-blocked { background: #fdecec; color: #c0392b; }
#detail .status-chip.status-done { background: #eef2f5; color: #6b7c8c; }
#detail .term-deps { margin-top: 0.7rem; font-size: 0.86rem; color: #555; }
#detail .term-deps strong { display: block; margin-bottom: 0.2rem; }
#detail .term-deps a {
display: block;
padding: 0.15rem 0 0.15rem 1.2rem;
color: #2c3e50;
cursor: pointer;
text-decoration: underline dotted;
position: relative;
line-height: 1.35;
}
#detail .term-deps a::before {
content: "·";
position: absolute;
left: 0.45rem;
color: #bbb;
font-weight: 600;
}
#detail .term-deps a:hover { color: #c0392b; }
#detail .term-issues { margin-top: 0.8rem; font-size: 0.82rem; color: #555; }
#detail .term-issues strong { display: block; margin-bottom: 0.35rem; color: #444; }
#detail .iss-list { display: flex; flex-direction: column; gap: 0.25rem; }
#detail .iss-chip {
display: flex;
flex-direction: column;
gap: 0.2rem;
padding: 0.3rem 0.5rem;
border-radius: 4px;
background: #fafafa;
border-left: 3px solid #ccc;
text-decoration: none;
color: #333;
line-height: 1.3;
transition: background 0.12s;
}
#detail .iss-row { display: grid; grid-template-columns: auto 1fr auto; gap: 0.4rem; align-items: center; }
#detail .iss-blocked { font-size: 0.74rem; color: #c0392b; padding-left: 0.2rem; }
#detail .iss-blocked a { color: #c0392b; text-decoration: underline; margin-right: 0.25rem; }
#detail .iss-blockref-internal { font-weight: 600; }
#detail .iss-blockref-external { font-style: italic; }
#detail .iss-chip:hover { background: #f0f0f0; text-decoration: none; }
#detail .iss-chip.iss-open { border-left-color: #3498db; }
#detail .iss-chip.iss-closed { border-left-color: #27ae60; opacity: 0.55; }
#detail .iss-num { font-family: ui-monospace, SFMono-Regular, monospace; color: #888; font-size: 0.78rem; align-self: center; }
#detail .iss-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#detail .iss-assignee { font-size: 0.72rem; color: #2c3e50; background: #eef2f5; padding: 0.05rem 0.35rem; border-radius: 8px; align-self: center; }
#detail .iss-unassigned { font-size: 0.72rem; color: #c0392b; background: #fdecec; padding: 0.05rem 0.35rem; border-radius: 8px; align-self: center; font-style: italic; }
#detail .term-blocked { color: #c0392b; }
#detail .term-blocked strong { color: #c0392b; }
#detail .term-blocked a { color: #c0392b; text-decoration: underline; }
#detail .term-builton { color: #27ae60; opacity: 0.85; }
#detail .term-builton strong { color: #27ae60; }
#detail .term-blocking { color: #c0392b; }
#detail .term-blocking strong { color: #c0392b; }
#detail .term-blocking a { color: #c0392b; text-decoration: underline; }
#detail .term-shipped-on-top { color: #7f8c8d; opacity: 0.75; }
#detail .term-shipped-on-top strong { color: #7f8c8d; }
#detail .region-ref { color: #2c3e50; text-decoration: underline dotted; cursor: pointer; }
#detail .region-ref:hover { color: #c0392b; }
#detail .term-namecerts {
margin-top: 0.9rem; padding-top: 0.7rem; border-top: 1px dashed #ddd;
font-size: 0.83rem;
}
#detail .term-namecerts-header {
font-weight: 600; color: #444; margin-bottom: 0.35rem; font-size: 0.85rem;
}
#detail .nc-row {
padding: 0.15rem 0; line-height: 1.4;
word-break: break-all;
}
#detail .nc-row code {
font-size: 0.78rem; color: #2c3e50; background: transparent;
}
#detail .term-timeline {
margin-top: 0.7rem; font-size: 0.84rem; color: #555;
padding: 0.35rem 0.55rem; background: #f7f9fb; border-radius: 3px;
border-left: 3px solid #2980b9; line-height: 1.5;
}
#detail .legend { margin-top: 1.5rem; padding-top: 0.9rem; border-top: 1px solid #eee; font-size: 0.82rem; color: #666; }
#detail .legend .swatch {
display: inline-block; width: 14px; height: 14px; vertical-align: middle;
margin-right: 0.3rem;
background: #999;
}
#detail .legend .swatch.circle,
#detail .legend .swatch.ellipse {
border-radius: 50%; border: 1px solid rgba(0,0,0,0.2);
}
#detail .legend .swatch.hexagon,
#detail .legend .swatch.hex {
/* Cytoscape's hexagon shape, mirrored as a CSS clip-path so the legend
matches the on-graph node silhouette exactly. */
clip-path: polygon(25% 6%, 75% 6%, 100% 50%, 75% 94%, 25% 94%, 0% 50%);
}
#detail .legend .swatch.triangle {
clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}
#detail .legend .swatch.star {
clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
#detail .legend > div { padding: 0.12rem 0; }
#detail .legend-subhead {
font-size: 0.78rem; font-weight: 600; color: #555;
margin-top: 0.5rem; margin-bottom: 0.3rem;
}
#detail .legend-subhead.legend-subhead-tight { margin-top: 0.65rem; }
</style>
<div class="map-shell">
<div class="map-header">
<h1 data-i18n="title">Chrono AI Region Map</h1>
<div class="summary" id="summary"></div>
<select id="region-picker" class="region-picker" onchange="onPickerChange(this.value)">
<option value="" data-i18n="picker_default">-- jump to region --</option>
</select>
<div class="map-controls">
<div class="lang-toggle">
<span data-i18n="lang_label" style="margin-right:0.4rem;">Language:</span>
<button id="btn-en" class="active" onclick="setLang('en')">EN</button>
<button id="btn-zh" onclick="setLang('zh')">中文</button>
</div>
</div>
</div>
<div id="cy-wrap">
<div id="cy"></div>
<div class="zoom-controls" id="zoom-controls">
<button type="button" id="zoom-in" data-i18n-title="zoom_in" title="Zoom in" aria-label="Zoom in">+</button>
<button type="button" id="zoom-out" data-i18n-title="zoom_out" title="Zoom out" aria-label="Zoom out">−</button>
<button type="button" id="zoom-reset" data-i18n-title="zoom_reset" title="Fit to view" aria-label="Fit to view"><svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 5V2h3M9 2h3v3M12 9v3H9M5 12H2V9"/></svg></button>
</div>
</div>
<div id="detail">
<div id="detail-content">
<div class="hint" data-i18n="hint">Click a node to see its bilingual entry, stats, and dependencies.</div>
</div>
<div class="legend">
<div data-i18n="legend_title" style="font-weight:600; color:#444; margin-bottom:0.4rem;">Legend</div>
<div class="legend-subhead" data-i18n="legend_color_head">Color = closure stage</div>
<div id="legend-color-list"></div>
<div class="legend-subhead legend-subhead-tight" data-i18n="legend_shape_head">Shape = automation level</div>
<div id="legend-shape-list"></div>
</div>
</div>
</div>
<script src="https://unpkg.com/cytoscape@3.30.2/dist/cytoscape.min.js"></script>
<script src="https://unpkg.com/dagre@0.8.5/dist/dagre.min.js"></script>
<script src="https://unpkg.com/cytoscape-dagre@2.5.0/cytoscape-dagre.js"></script>
<script src="https://unpkg.com/cytoscape-expand-collapse@4.1.1/cytoscape-expand-collapse.js"></script>
<script>
const I18N = {
en: {
title: "Chrono AI Region Map",
lang_label: "Language:",
hint: "Click a node to see its bilingual entry, stats, and dependencies.",
legend_title: "Legend",
legend_color_head: "Color = closure stage",
legend_shape_head: "Shape = automation level",
sum_regions: "regions",
detail_timeline: "Timeline:",
detail_upstream: "Upstream:",
detail_downstream: "Downstream:",
picker_default: "-- jump to region --",
zoom_in: "Zoom in",
zoom_out: "Zoom out",
zoom_reset: "Fit to view",
},
zh: {
title: "Chrono AI 攻坚地图",
lang_label: "语言:",
hint: "点击节点查看双语词条, 统计和依赖关系.",
legend_title: "图例",
legend_color_head: "颜色 = 闭合阶段",
legend_shape_head: "形状 = 自动化等级",
sum_regions: "领域",
detail_timeline: "时间线:",
detail_upstream: "上游:",
detail_downstream: "下游:",
picker_default: "-- 跳到领域 --",
zoom_in: "放大",
zoom_out: "缩小",
zoom_reset: "适应窗口",
},
};
let LANG = "en"; // overridden in loadData() from config.ui.default_lang
let CONFIG = null, REGIONS_DOC = null, CY = null;
let ORNN_ISSUES = null; // { synced_at, regions: { <region_key>: { milestone, issues: { <num>: {...} } } } }
let EC_API = null; // cytoscape-expand-collapse handle
let FOCUS_SET = new Set();
let CLOSURE_BY_KEY = {}; // built from config.closure_tiers
let FORMAL_BY_KEY = {}; // built from config.formal_levels
let PRODUCT_BY_KEY = {}; // built from config.products
async function loadData() {
const v = "?v=" + Date.now();
const [cfg, regionsDoc, issuesDoc] = await Promise.all([
fetch("config.json" + v, { cache: "no-store" }).then(r => r.json()),
fetch("regions.json" + v, { cache: "no-store" }).then(r => r.json()),
// ornn-issues.json may not exist on first build; tolerate missing
fetch("ornn-issues.json" + v, { cache: "no-store" })
.then(r => r.ok ? r.json() : null)
.catch(() => null),
]);
CONFIG = cfg;
REGIONS_DOC = regionsDoc;
ORNN_ISSUES = issuesDoc;
LANG = cfg.ui.default_lang || "en";
// Index lookups for O(1) access
CONFIG.closure_tiers.forEach(t => { CLOSURE_BY_KEY[t.key] = t; });
CONFIG.formal_levels.forEach(f => { FORMAL_BY_KEY[f.key] = f; });
CONFIG.products.forEach(p => { PRODUCT_BY_KEY[p.key] = p; });
// Focus set drives red border
FOCUS_SET = new Set(
Object.entries(REGIONS_DOC.regions)
.filter(([_, r]) => r.focus === true)
.map(([id]) => id)
);
}
function buildCytoscapeElements() {
const nodes = [];
const edges = [];
const regions = REGIONS_DOC.regions;
const issuesByRegion = (ORNN_ISSUES && ORNN_ISSUES.regions) || {};
for (const [id, r] of Object.entries(regions)) {
nodes.push({
data: {
id,
label_en: r.label.en,
label_zh: r.label.zh,
closure: r.closure,
formal: r.formal,
product: r.product,
milestone: r.milestone,
owner: r.owner,
issue_count: r.issue_count || 0,
focus: r.focus === true,
archived: r.archived === true,
is_region: true,
}
});
for (const dep of (r.deps || [])) {
const depKey = typeof dep === "string" ? dep : dep.key;
const weight = (typeof dep === "object" && dep.weight) ? dep.weight : 1;
edges.push({
data: { source: depKey, target: id, weight }
});
}
// Add issue child nodes for regions with a milestone_ref → ornn-issues.json entry.
// Only OPEN issues become visual children — closed issues live in the side-panel
// history list to keep M4 (112 issues, 106 closed) from becoming a giant bubble.
const regionIssueData = issuesByRegion[id];
if (regionIssueData && regionIssueData.issues) {
for (const [num, issue] of Object.entries(regionIssueData.issues)) {
if (issue.state !== "OPEN") continue;
const childId = `issue:${id}:${num}`;
nodes.push({
data: {
id: childId,
parent: id,
issue_number: parseInt(num, 10),
issue_title: issue.title,
issue_state: issue.state,
issue_url: issue.url,
issue_labels: issue.labels || [],
region_key: id,
label: `#${num}`,
is_issue: true,
}
});
}
// Add issue→issue edges within this region (only when both endpoints exist as OPEN children)
const openSet = new Set(
Object.entries(regionIssueData.issues)
.filter(([_, i]) => i.state === "OPEN")
.map(([n]) => parseInt(n, 10))
);
for (const [num, issue] of Object.entries(regionIssueData.issues)) {
if (issue.state !== "OPEN") continue;
const srcNum = parseInt(num, 10);
const srcId = `issue:${id}:${srcNum}`;
// blocked_by N → edge from N to this (N must block-by-completion finish first)
for (const blocker of (issue.deps?.blocked_by || [])) {
if (openSet.has(blocker)) {
edges.push({
data: { source: `issue:${id}:${blocker}`, target: srcId, edge_type: "blocks" }
});
}
}
// blocks N → edge from this to N
for (const blocked of (issue.deps?.blocks || [])) {
if (openSet.has(blocked)) {
edges.push({
data: { source: srcId, target: `issue:${id}:${blocked}`, edge_type: "blocks" }
});
}
}
// tracks N → edge from this (umbrella) to N (child)
for (const tracked of (issue.deps?.tracks || [])) {
if (openSet.has(tracked)) {
edges.push({
data: { source: srcId, target: `issue:${id}:${tracked}`, edge_type: "tracks" }
});
}
}
}
}
}
return { nodes, edges };
}
function t(key) { return I18N[LANG][key] || key; }
function applyStaticI18n() {
// Build dynamic I18N from config (title + legend + tier/formal labels),
// merged with the static I18N table for everything not yet in config.
const dyn = { en: {}, zh: {} };
if (CONFIG && CONFIG.ui) {
dyn.en.title = CONFIG.ui.title.en;
dyn.zh.title = CONFIG.ui.title.zh;
for (const [key, label] of Object.entries(CONFIG.ui.legend || {})) {
dyn.en["legend_" + key] = label.en;
dyn.zh["legend_" + key] = label.zh;
}
}
if (CONFIG && CONFIG.closure_tiers) {
CONFIG.closure_tiers.forEach(tier => {
dyn.en["closure_" + tier.key] = tier.label.en;
dyn.zh["closure_" + tier.key] = tier.label.zh;
});
}
if (CONFIG && CONFIG.formal_levels) {
CONFIG.formal_levels.forEach(f => {
dyn.en["formal_" + f.key] = f.label.en;
dyn.zh["formal_" + f.key] = f.label.zh;
});
}
const lookup = key =>
(dyn[LANG] && dyn[LANG][key] !== undefined) ? dyn[LANG][key] :
(I18N[LANG][key] !== undefined ? I18N[LANG][key] : undefined);
document.title = lookup("title") || "Region Map";
document.querySelectorAll("[data-i18n]").forEach(el => {
const key = el.getAttribute("data-i18n");
const v = lookup(key);
if (v !== undefined) el.innerHTML = v;
});
document.querySelectorAll("[data-i18n-title]").forEach(el => {
const key = el.getAttribute("data-i18n-title");
const v = lookup(key);
if (v !== undefined) {
el.setAttribute("title", v);
el.setAttribute("aria-label", v);
}
});
const btnEn = document.getElementById("btn-en");
const btnZh = document.getElementById("btn-zh");
if (btnEn) btnEn.classList.toggle("active", LANG === "en");
if (btnZh) btnZh.classList.toggle("active", LANG === "zh");
const summary = document.getElementById("summary");
if (summary && REGIONS_DOC) {
const total = Object.keys(REGIONS_DOC.regions).length;
summary.innerHTML = `<strong>${total}</strong> ${t("sum_regions")}`;
}
populatePicker();
renderLegend();
}
// pickerOptionLabel + REGION_GROUPS removed in Task 7;
// populatePicker now reads labels directly from REGIONS_DOC.
function populatePicker() {
const sel = document.getElementById("region-picker");
if (!sel || !REGIONS_DOC || !CONFIG) return;
const regions = REGIONS_DOC.regions;
const groups = CONFIG.products.map(p => ({
key: p.key,
label: p.label[LANG] || p.label.en,
items: Object.keys(regions).filter(rid => regions[rid].product === p.key)
})).filter(g => g.items.length > 0);
let html = `<option value="">${t("picker_default")}</option>`;
for (const g of groups) {
html += `<optgroup label="${g.label}">`;
for (const id of g.items.sort()) {
const r = regions[id];
const lbl = (r.label && r.label[LANG]) || (r.label && r.label.en) || id;
html += `<option value="${id}">${lbl}</option>`;
}
html += `</optgroup>`;
}
sel.innerHTML = html;
}
function onPickerChange(id) {
if (!id) return;
showNodeDetail(id);
// showNodeDetail zooms into the connected subgraph; tapping an empty
// area restores the global fit.
}
// Two visual channels driven entirely by config.json:
// color = closure tier (config.closure_tiers[*].color, keyed by region.closure)
// shape = formal automation level (config.formal_levels[*].shape, keyed by region.formal)
// size = region.issue_count
// border = focus emphasis (CONFIG.focus_quarter.border_color/border_width when focus=true)
// Closure tier colors come from CONFIG.closure_tiers — built once after loadData.
function getClosureColor(closureKey) {
return (CLOSURE_BY_KEY[closureKey] && CLOSURE_BY_KEY[closureKey].color) || "#bdc3c7";
}
function nodeShape(node) {
const f = FORMAL_BY_KEY[node.formal];
return (f && f.shape) || "ellipse";
}
function nodeBorder(node) {
if (FOCUS_SET.has(node.id)) {
return {
stroke: CONFIG.focus_quarter.border_color || "#c0392b",
borderWidth: CONFIG.focus_quarter.border_width || 3,
};
}
return { stroke: "#ffffff", borderWidth: 2 };
}
function nodeVisual(node) {
const fill = getClosureColor(node.closure);
const shape = nodeShape(node);
const border = nodeBorder(node);
return { fill, shape, ...border };
}
function nodeSizeMetric(node) {
return Math.max(1, node.issue_count || 1);
}
function nodeLabel(node) {
if (!node) return "";
return node["label_" + LANG] || node["label_en"] || node.id || "";
}
function refreshNodeVisuals() {
if (!CY) return;
const regions = REGIONS_DOC ? REGIONS_DOC.regions : {};
CY.nodes().forEach(n => {
const r = regions[n.id()];
if (!r) return;
const visual = nodeVisual({
id: n.id(),
closure: r.closure,
formal: r.formal,
});
n.data("color", visual.fill);
n.data("shape", visual.shape);
n.data("stroke", visual.stroke);
n.data("borderWidth", visual.borderWidth);
n.data("size", nodeSizeMetric({ issue_count: r.issue_count }));
n.data("label", nodeLabel({
label_en: r.label.en,
label_zh: r.label.zh,
id: n.id(),
}));
// archived also kept on the data object so the node[?archived] selector
// matches; we set it during buildCytoscapeElements but refresh here in
// case regions.json was reloaded.
n.data("archived", r.archived === true);
});
CY.style().update();
}
function escapeHtml(value) {
return String(value ?? "")
.replaceAll("&", "&")
.replaceAll("<", "<")
.replaceAll(">", ">")
.replaceAll('"', """)
.replaceAll("'", "'");
}
function renderCy() {
CY = cytoscape({
container: document.getElementById("cy"),
// Use the flat-array form: cytoscape's {nodes,edges} object form has a
// bug where compound children (issue nodes with `parent:` set) are
// silently dropped at construction time. Flattening to [...nodes,
// ...edges] preserves them. Confirmed locally 2026-05-18.
elements: (() => { const e = buildCytoscapeElements(); return [...e.nodes, ...e.edges]; })(),
style: [
{
selector: "node",
style: {
"shape": "data(shape)",
"background-color": "data(color)",
"label": "data(label)",
"font-size": "13px",
"font-weight": 600,
"color": "#1a1a1a",
"text-valign": "bottom",
"text-halign": "center",
"text-margin-y": 6,
"text-outline-color": "#fbfbfa",
"text-outline-width": 2,
"text-background-color": "#fbfbfa",
"text-background-opacity": 0.85,
"text-background-padding": "3px",
"text-background-shape": "roundrectangle",
"text-wrap": "wrap",
"text-max-width": "140px",
"width": "mapData(size, 0, 30, 36, 72)",
"height": "mapData(size, 0, 30, 36, 72)",
"border-width": "data(borderWidth)",
"border-color": "data(stroke)",
"overlay-padding": 4,
},
},
{
selector: "node:selected",
style: {
"border-width": 8,
"border-color": "#f39c12",
"border-opacity": 1,
"overlay-color": "#f39c12",
"overlay-opacity": 0.18,
"overlay-padding": 12,
"z-index": 999,
}
},
{
selector: "edge",
style: {
"width": 1.5, "line-color": "#7a8a99",
"target-arrow-color": "#7a8a99", "target-arrow-shape": "triangle",
"curve-style": "bezier", "arrow-scale": 0.95,
"opacity": 0.55,
},
},
{ selector: "edge.highlight", style: { "line-color": "#c0392b", "target-arrow-color": "#c0392b", "width": 3, "opacity": 1 } },
{ selector: "edge.faded", style: { "opacity": 0.06 } },
{ selector: "node.faded", style: { "opacity": 0.15 } },
// Archived regions render dim (opacity sourced from CONFIG.archive_rule.opacity, built dynamically).
// Using a Cytoscape selector keeps this declarative; refreshNodeVisuals
// writes the boolean `archived` data field that this selector tests.
{ selector: "node[?archived]", style: { "opacity": CONFIG.archive_rule.opacity ?? 0.35 } },
// === Compound issue children (Ornn only) ===
// Issue nodes live inside their milestone region as cytoscape compound children.
// Only OPEN issues become visual nodes — closed issues stay in the side-panel history.
{
selector: "node[?is_issue]",
style: {
"shape": "ellipse",
"background-color": "#3498db",
"background-opacity": 0.92,
"border-width": 1.5,
"border-color": "#1f5377",
"width": 24,
"height": 24,
"label": "data(label)",
"font-size": "10px",
"font-weight": 700,
"color": "#fff",
"text-valign": "center",
"text-halign": "center",
"text-outline-color": "transparent",
"text-outline-width": 0,
"text-background-opacity": 0,
"text-margin-y": 0,
}
},
// Compound parent rendering when expanded (issues visible inside)
{
selector: "node:parent",
style: {
"background-opacity": 0.06,
"background-color": "data(color)",
"border-style": "dashed",
"border-width": 2,
"padding": 18,
"text-valign": "top",
"text-halign": "center",
"text-margin-y": -4,
}
},
// Issue→issue "blocks" edge: red, solid arrow (this issue blocks completion of target)
{
selector: "edge[edge_type = 'blocks']",
style: {
"line-color": "#e74c3c",
"target-arrow-color": "#e74c3c",
"target-arrow-shape": "triangle",
"width": 1.5,
"curve-style": "bezier",
"arrow-scale": 0.85,
"opacity": 0.85,
}
},
// Issue→issue "tracks" edge: dashed grey (umbrella → child checklist item)
{
selector: "edge[edge_type = 'tracks']",
style: {
"line-color": "#95a5a6",
"line-style": "dashed",
"target-arrow-color": "#95a5a6",
"target-arrow-shape": "tee",
"width": 1,
"curve-style": "bezier",
"arrow-scale": 0.7,
"opacity": 0.7,
}
},
],
layout: {
// No initial layout — dagre would put issue children in one column
// because they have no inter-compound edges. We collapse all
// compounds first (below), then run dagre on the outer structure.
name: "preset",
},
// Disable wheel/pinch zoom (per request); pan-drag remains for nudging
// so the dropdown's centered jump can be fine-tuned without the user
// ever needing to scroll-zoom. The +/-/fit buttons drive zoom
// programmatically — bounds keep them sane.
userZoomingEnabled: false,
userPanningEnabled: true,
boxSelectionEnabled: false,
wheelSensitivity: 0,
autoungrabify: true,
minZoom: 0.05,
maxZoom: 4,
});
setupZoomControls();
// Initialize cytoscape-expand-collapse for Ornn milestone regions that
// contain issue children. Default state: all compounds collapsed (looks
// like the previous flat map). User clicks the +/- cue on a parent to
// expand and see issues + their dep edges.
try {
EC_API = CY.expandCollapse({
// No auto-layout on expand/collapse — re-running dagre across the
// whole graph causes everything to jump. We position children
// manually with a grid layout right after each expand (see tap
// handler below).
layoutBy: null,
fisheye: false,
animate: true,
animationDuration: 200,
undoable: false,
cueEnabled: true,
expandCollapseCuePosition: "top-left",
expandCollapseCueSize: 14,
expandCollapseCueLineSize: 9,
});
// Collapse every compound on init so the default view matches the old
// milestone-only layout. Users expand on demand.
const compoundNodes = CY.nodes().filter(n => n.isParent());
if (compoundNodes.length > 0 && EC_API.collapse) {
EC_API.collapse(compoundNodes);
}
} catch (e) {
console.warn("expand-collapse init failed (compound rendering disabled):", e);
}
// Now run the real dagre layout. Compounds are collapsed → dagre only
// sees the outer 57-node structure, not 153 (which would stack issue
// children in a useless column because they have no inter-edges).
CY.layout({
name: "dagre",
rankDir: "LR",
nodeSep: 50,
rankSep: 180,
edgeSep: 14,
ranker: "network-simplex",
padding: 24,
fit: true,
animate: false,
}).run();
// Helper: arrange a compound's children in a grid around the parent's
// current position. Called after EC_API.expand() so the children don't
// pile up at one point.
window.__layoutCompoundChildren = function (parent) {
const children = parent.children();
if (children.length === 0) return;
const cols = Math.ceil(Math.sqrt(children.length * 1.6)); // wider than tall
const cellW = 50;
const cellH = 50;
const center = parent.position();
// Start from top-left of the grid centered on the parent's original spot
const rows = Math.ceil(children.length / cols);
const startX = center.x - (cols - 1) * cellW / 2;
const startY = center.y - (rows - 1) * cellH / 2;
children.forEach((c, i) => {
const row = Math.floor(i / cols);
const col = i % cols;
c.position({ x: startX + col * cellW, y: startY + row * cellH });
});
};
CY.on("tap", "node", evt => {
const node = evt.target;
if (node.data("is_issue")) {
showIssueDetail(node);
return;
}
// Region node: show detail panel as before.
showNodeDetail(node.id());
// If this region has issue children (collapsed or expanded), also
// toggle compound state on the same tap. The +/- hover cue from
// expand-collapse is easy to miss; click-to-toggle makes it discoverable.
if (EC_API && (EC_API.isExpandable(node) || EC_API.isCollapsible(node))) {
try {
if (EC_API.isExpandable(node)) {
EC_API.expand(node);
// Position the now-visible children in a grid so they don't pile up
if (window.__layoutCompoundChildren) {
window.__layoutCompoundChildren(node);
}
} else if (EC_API.isCollapsible(node)) {
EC_API.collapse(node);
}
} catch (e) { /* ignore */ }
}
});
CY.on("tap", evt => {
if (evt.target === CY) {
renderDefaultPanel();
CY.nodes().unselect();
// Restore focus filter (not full visibility) — empty-tap returns to the
// "what we're attacking now" view, matching the side panel.
applyFocusFilter();
}
});
// Global view: fit all nodes in the viewport. With the bigger font and
// outline below, labels stay legible even when fit-zoomed. The dropdown
// is the primary nav for jumping between specific regions.
CY.fit(CY.elements(":visible"), 16);
}
// Show issue detail in the side panel
function showIssueDetail(node) {
const el = document.getElementById("detail-content");
if (!el) return;
const num = node.data("issue_number");
const title = node.data("issue_title");
const state = node.data("issue_state");
const url = node.data("issue_url");
const labels = node.data("issue_labels") || [];
const regionKey = node.data("region_key");
const region = REGIONS_DOC && REGIONS_DOC.regions[regionKey];
// Pull deps from the underlying issue data (not the cytoscape edges,
// because those are filtered to only-OPEN endpoints — we want to also
// mention closed-issue refs in the panel).
const issueData = ORNN_ISSUES && ORNN_ISSUES.regions[regionKey] &&
ORNN_ISSUES.regions[regionKey].issues[String(num)];
const deps = (issueData && issueData.deps) || {};
const stateBadge = state === "OPEN"
? '<span style="background:#27ae60;color:#fff;padding:1px 8px;border-radius:3px;font-size:0.75rem;font-weight:600">OPEN</span>'
: '<span style="background:#95a5a6;color:#fff;padding:1px 8px;border-radius:3px;font-size:0.75rem;font-weight:600">CLOSED</span>';
const labelChips = labels.length
? labels.map(l => `<span style="background:#ecf0f1;color:#34495e;padding:1px 6px;border-radius:3px;font-size:0.72rem;margin-right:3px">${escapeHtml(l)}</span>`).join("")
: '<span style="color:#aaa;font-style:italic">no labels</span>';
const renderDepList = (nums) =>
nums && nums.length
? nums.map(n => `<a href="#" onclick="event.preventDefault();jumpToIssue('${regionKey}',${n})">#${n}</a>`).join(", ")
: '<span style="color:#aaa">none</span>';
const regionLabel = region
? (LANG === "zh" ? region.label.zh : region.label.en)
: regionKey;
el.innerHTML = `
<div class="term-name">#${num}</div>
<div class="term-other">${stateBadge}</div>
<div class="term-desc" style="margin-top:0.7rem;font-size:0.95rem">${escapeHtml(title)}</div>
<div style="margin-top:0.7rem;font-size:0.82rem">
<strong>${LANG === "zh" ? "所属 milestone" : "Milestone"}:</strong>
<a href="#" onclick="event.preventDefault();showNodeDetail('${regionKey}')">${escapeHtml(regionLabel)}</a>
</div>
<div style="margin-top:0.4rem;font-size:0.82rem">
<strong>${LANG === "zh" ? "标签" : "Labels"}:</strong> ${labelChips}
</div>
<div class="term-deps" style="margin-top:0.7rem">
${deps.tracks && deps.tracks.length ? `<div><strong>${LANG === "zh" ? "包含 (tracks)" : "Tracks"}:</strong> ${renderDepList(deps.tracks)}</div>` : ""}
${deps.tracked_by && deps.tracked_by.length ? `<div><strong>${LANG === "zh" ? "被包含 (tracked by)" : "Tracked by"}:</strong> ${renderDepList(deps.tracked_by)}</div>` : ""}
${deps.blocks && deps.blocks.length ? `<div><strong>${LANG === "zh" ? "阻塞 (blocks)" : "Blocks"}:</strong> ${renderDepList(deps.blocks)}</div>` : ""}
${deps.blocked_by && deps.blocked_by.length ? `<div><strong>${LANG === "zh" ? "被阻塞 (blocked by)" : "Blocked by"}:</strong> ${renderDepList(deps.blocked_by)}</div>` : ""}
</div>
<div style="margin-top:0.9rem;font-size:0.82rem">
<a href="${escapeHtml(url)}" target="_blank" rel="noopener" style="color:#2c3e50">${LANG === "zh" ? "→ 在 GitHub 打开" : "→ Open on GitHub"}</a>
</div>
`;
}
// Jump to another issue (used by dep links in the panel)
function jumpToIssue(regionKey, issueNum) {
if (!CY) return;
const childId = `issue:${regionKey}:${issueNum}`;
const node = CY.getElementById(childId);
if (node && node.length) {
// Make sure parent is expanded
const parent = node.parent();
if (parent.length && parent.data("is_region") && EC_API) {
try { EC_API.expand(parent); } catch (e) { /* ignore */ }
}
showIssueDetail(node);
CY.animate({ center: { eles: node }, zoom: Math.max(CY.zoom(), 1.0) }, { duration: 250 });
} else {
// Issue might be closed (not in graph) — open GitHub directly
const data = ORNN_ISSUES && ORNN_ISSUES.regions[regionKey] &&
ORNN_ISSUES.regions[regionKey].issues[String(issueNum)];
if (data && data.url) {
window.open(data.url, "_blank");
}
}
}
function setupZoomControls() {
if (!CY) return;
const stepZoom = factor => {
const w = CY.width(), h = CY.height();
const next = CY.zoom() * factor;
CY.zoom({ level: next, renderedPosition: { x: w / 2, y: h / 2 } });
};
const bind = (id, fn) => {
const el = document.getElementById(id);
if (el) el.onclick = fn;
};
bind("zoom-in", () => stepZoom(1.25));
bind("zoom-out", () => stepZoom(0.8));
bind("zoom-reset", () => {
const visible = CY.elements(":visible");
const eles = visible.length ? visible : CY.elements();
CY.animate({ fit: { eles, padding: 16 } }, { duration: 300, easing: "ease-out" });
});
}
// Initial-load filter: keep only focus=true regions and the edges between them.
// Cuts the map's 82-region density down to just the "currently attacking"
// subgraph (matching the side panel). Re-runs dagre on the visible subset so
// nodes don't sit scattered across the original full-graph layout coordinates.
// Restored on empty-area tap so the view doesn't get permanently "unfocused"
// after exploring.
function applyFocusFilter() {
if (!CY || !REGIONS_DOC) return;
CY.elements().removeClass("highlight").removeClass("faded");
const keep = new Set();
for (const [rid, r] of Object.entries(REGIONS_DOC.regions)) {
if (r.focus === true) keep.add(rid);
}
// Safety: if no focus defined, don't fade anything
if (keep.size === 0) return;
CY.nodes().forEach(n => { if (!keep.has(n.id())) n.addClass("faded"); });