-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtemplate.html
More file actions
906 lines (847 loc) · 40.8 KB
/
template.html
File metadata and controls
906 lines (847 loc) · 40.8 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Git Code Ownership — {{.Repo}}</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><rect width='32' height='32' rx='6' fill='%230f172a'/><rect x='4' y='22' width='6' height='6' rx='1' fill='%233b82f6'/><rect x='13' y='14' width='6' height='14' rx='1' fill='%2360a5fa'/><rect x='22' y='8' width='6' height='20' rx='1' fill='%2393c5fd'/></svg>">
<script>{{.ChartJS}}</script>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace;
background: #0f172a; color: #e2e8f0;
height: 100vh; overflow: hidden; display: flex; flex-direction: column;
padding: 1.5rem 2rem; gap: 1rem;
}
header { display: flex; flex-direction: column; gap: .4rem; }
h1 { font-size: 1.25rem; font-weight: 700; color: #f8fafc; }
h1 em { color: #60a5fa; font-style: normal; font-weight: 400; }
.meta { display: flex; flex-wrap: wrap; gap: 1.5rem; font-size: .8rem; color: #94a3b8; }
.meta span { color: #cbd5e1; }
/* main layout: chart + optional side panel */
.body-row { display: flex; gap: 1rem; flex: 1; min-height: 0; }
.card {
background: #1e293b; border: 1px solid #334155; border-radius: .75rem;
padding: 1.25rem; flex: 1; min-width: 0;
display: flex; flex-direction: column; gap: .75rem;
}
.card-toolbar {
display: flex; align-items: center; gap: .6rem; flex-shrink: 0;
}
.chart-wrap { position: relative; flex: 1; min-height: 300px; }
/* mode toggle */
.toggle-group { display: flex; background: #0f172a; border-radius: .4rem; overflow: hidden; border: 1px solid #334155; }
.toggle-btn {
padding: .3rem .85rem; font-size: .8rem; font-family: inherit;
background: transparent; color: #94a3b8; border: none; cursor: pointer;
transition: background .15s, color .15s;
}
.toggle-btn.active { background: #3b82f6; color: #fff; }
.toggle-btn:hover:not(.active) { background: #1e3a5f; color: #e2e8f0; }
/* bands control */
.bands-control { display: flex; align-items: center; gap: .4rem; flex-shrink: 0; }
.bands-label { font-size: .75rem; color: #64748b; }
.bands-slider { width: 72px; accent-color: #3b82f6; cursor: pointer; }
.bands-input {
width: 46px; background: #0f172a; border: 1px solid #475569; border-radius: .4rem;
color: #e2e8f0; font-size: .8rem; padding: .25rem .4rem; font-family: inherit;
outline: none; text-align: center; transition: border-color .15s;
}
.bands-input:focus { border-color: #3b82f6; }
.bands-input::-webkit-outer-spin-button,
.bands-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.bands-input { -moz-appearance: textfield; }
/* toolbar zones */
.toolbar-left { display: flex; align-items: center; gap: .6rem; flex: 1; }
.toolbar-center{ display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.toolbar-right { display: flex; align-items: center; justify-content: flex-end; flex: 1; }
/* folder dropdown button */
.folder-btn {
background: #0f172a; border: 1px solid #475569; border-radius: .4rem;
color: #e2e8f0; font-size: .8rem; padding: .3rem .75rem;
font-family: inherit; cursor: pointer; outline: none; white-space: nowrap;
display: flex; align-items: center; gap: .4rem;
transition: border-color .15s;
}
.folder-btn:hover, .folder-btn.open { border-color: #3b82f6; }
.folder-dropdown-wrap { position: relative; }
/* folder tree menu */
.folder-menu {
position: absolute; top: calc(100% + 4px); left: 50%; transform: translateX(-50%);
z-index: 200; background: #1e293b; border: 1px solid #334155; border-radius: .5rem;
min-width: 220px; max-height: 360px; overflow-y: auto;
box-shadow: 0 8px 24px rgba(0,0,0,.5); padding: .25rem 0;
}
.folder-menu.hidden { display: none; }
.folder-item {
display: flex; align-items: baseline; padding: .35rem .75rem; cursor: pointer;
font-size: .8rem; color: #cbd5e1; white-space: pre; font-family: monospace;
}
.folder-item:hover { background: #334155; }
.folder-item.active { color: #60a5fa; font-weight: 600; }
.folder-item.active:hover { background: #1e3a5f; }
.folder-item.ancestor { color: #64748b; cursor: default; }
.folder-item.ancestor:hover { background: transparent; }
.tree-pfx { color: #475569; }
/* author info panel */
.author-panel {
width: 420px; flex-shrink: 0;
background: #1e293b; border: 1px solid #334155; border-radius: .75rem;
padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem;
min-height: 0; /* let the flex parent cap our height */
overflow: hidden; /* we don't scroll — inner sections do */
}
.author-panel.hidden { display: none; }
.panel-close {
align-self: flex-end; flex-shrink: 0;
background: none; border: none; color: #64748b;
cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0;
}
.panel-close:hover { color: #e2e8f0; }
.panel-author-header { display: flex; flex-direction: column; gap: .3rem; flex-shrink: 0; }
.panel-color-bar { height: 3px; border-radius: 2px; margin-bottom: .25rem; }
.panel-name { font-size: 1rem; font-weight: 600; color: #f1f5f9; word-break: break-all; }
.panel-email { font-size: .75rem; color: #94a3b8; word-break: break-all; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; flex-shrink: 0; }
.stat {
background: #0f172a; border-radius: .5rem; padding: .6rem .7rem;
display: flex; flex-direction: column; gap: .15rem;
}
.stat.full { grid-column: 1 / -1; }
.stat-value { font-size: .95rem; font-weight: 700; color: #f1f5f9; }
.stat-label { font-size: .68rem; color: #64748b; text-transform: uppercase; letter-spacing: .04em; }
.sparkline-wrap { flex: 1; min-height: 0; }
.panel-hint { font-size: .72rem; color: #64748b; text-align: center; flex-shrink: 0; }
/* others breakdown */
.members-list {
display: flex; flex-direction: column; gap: .3rem;
overflow-y: auto; flex: 1; min-height: 0; /* scroll, don't expand */
}
.member-row {
display: flex; justify-content: space-between; align-items: baseline;
padding: .3rem .6rem; background: #0f172a; border-radius: .4rem; font-size: .8rem;
gap: .5rem; flex-shrink: 0; cursor: pointer;
}
.member-row:hover { background: #1e3a5f; }
.member-row.highlighted { background: #1e3a5f; outline: 1px solid #3b82f6; }
.member-name { color: #cbd5e1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-lines { color: #94a3b8; font-variant-numeric: tabular-nums; flex-shrink: 0; }
/* author search */
.search-wrap { position: relative; }
.search-input {
background: #0f172a; border: 1px solid #475569; border-radius: .4rem;
color: #e2e8f0; font-size: .8rem; padding: .3rem .7rem; width: 200px;
font-family: inherit; outline: none;
transition: border-color .15s;
}
.search-input:focus { border-color: #3b82f6; }
.search-input::placeholder { color: #64748b; }
.search-dropdown {
position: absolute; top: calc(100% + 4px); right: 0; z-index: 100;
background: #1e293b; border: 1px solid #334155; border-radius: .5rem;
min-width: 260px; max-height: 260px; overflow-y: auto;
box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.search-dropdown.hidden { display: none; }
.search-result {
display: flex; justify-content: space-between; align-items: baseline;
padding: .45rem .75rem; cursor: pointer; font-size: .8rem; gap: .75rem;
}
.search-result:hover { background: #334155; }
.search-result-name { color: #e2e8f0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-meta { color: #94a3b8; font-size: .72rem; flex-shrink: 0; }
</style>
</head>
<body>
<header>
<h1>Git Code Ownership <em>— surviving lines per author over time</em></h1>
<div class="meta">
<div>repo: <span>{{.Repo}}</span></div>
<div>branch: <span>{{.Branch}}</span></div>
<div>hash: <span>{{.LastCommit}}</span></div>
<div>commits: <span>{{.TotalCommits}}</span></div>
<div>snapshots: <span>{{.Samples}}</span></div>
<div>authors: <span id="author-count">{{.Authors}}</span></div>
<div>generated: <span>{{.Generated}}</span></div>
</div>
</header>
<div class="body-row">
<div class="card">
<div class="card-toolbar">
<div class="toolbar-left">
<div class="toggle-group">
<button class="toggle-btn active" id="btn-abs" onclick="setMode('abs')">Line Count</button>
<button class="toggle-btn" id="btn-pct" onclick="setMode('pct')">% Share</button>
</div>
<div class="toggle-group">
<button class="toggle-btn active" id="btn-x-commits" onclick="setXMode('commits')">Commits</button>
<button class="toggle-btn" id="btn-x-time" onclick="setXMode('time')">Time</button>
</div>
</div>
<div class="toolbar-center">
<div class="folder-dropdown-wrap" id="folder-dropdown-wrap" style="display:none">
<button class="folder-btn" id="folder-btn" onclick="toggleFolderMenu()">
<span id="folder-btn-label">whole repo</span>
<span style="color:#64748b;font-size:.7rem">▾</span>
</button>
<div class="folder-menu hidden" id="folder-menu"></div>
</div>
</div>
<div class="toolbar-right">
<div class="bands-control">
<span class="bands-label">bands</span>
<input type="range" class="bands-slider" id="bands-slider" min="1" oninput="setBands(+this.value)">
<input type="number" class="bands-input" id="bands-input" min="1" oninput="setBands(+this.value)">
</div>
<div class="search-wrap">
<input class="search-input" id="author-search" type="text"
placeholder="Search author…" autocomplete="off" oninput="onSearch(event)">
<div class="search-dropdown hidden" id="search-dropdown"></div>
</div>
</div>
</div>
<div class="chart-wrap"><canvas id="chart"></canvas></div>
</div>
<div class="author-panel hidden" id="author-panel">
<button class="panel-close" onclick="closePanel()" title="Close">✕</button>
<div class="panel-author-header">
<div class="panel-color-bar" id="panel-color-bar"></div>
<div class="panel-name" id="panel-name"></div>
<div class="panel-email" id="panel-email"></div>
</div>
<div class="stats-grid" id="panel-stats"></div>
<div id="panel-sparkline-wrap" class="sparkline-wrap"><canvas id="sparkline"></canvas></div>
<div id="panel-members-wrap" class="members-list" style="display:none"></div>
<div class="panel-hint" id="panel-hint">own line count over time</div>
</div>
</div>
<script>
const FOLDERS = {{.FoldersJSON}};
let DATA = FOLDERS[0].chart;
let mode = 'abs';
let xMode = 'commits'; // 'commits' (even spacing) | 'time' (linear calendar)
let sparkChart = null;
let hoveredDatasetIdx = -1;
let currentFolderIdx = 0;
let currentBands = Math.min(20, DATA.datasets.length);
// ── displayDatasets ───────────────────────────────────────────────────────
// Returns the top-currentBands individual datasets plus a synthetic Others
// band aggregating the rest. JS owns the Others grouping; Go only stores
// individual author datasets (up to --max-graph).
function displayDatasets() {
const all = DATA.datasets;
const n = Math.min(currentBands, all.length);
const major = all.slice(0, n);
const minor = all.slice(n);
// Compute how many lines/pct belong to authors excluded from the data
// entirely (beyond --max-graph). These must be added to Others so that
// the % share view always sums to 100%.
const len = all[0].absData.length;
const othersAbs = new Array(len).fill(0);
const othersPct = new Array(len).fill(0);
for (const ds of minor) {
for (let i = 0; i < len; i++) {
othersAbs[i] += ds.absData[i] || 0;
othersPct[i] += ds.pctData[i] || 0;
}
}
// Add the excluded-author remainder using the stored per-snapshot totals.
if (DATA.totalAbs) {
for (let i = 0; i < len; i++) {
const includedAbs = all.reduce((s, ds) => s + (ds.absData[i] || 0), 0);
const excluded = (DATA.totalAbs[i] || 0) - includedAbs;
if (excluded > 0) {
othersAbs[i] += excluded;
othersPct[i] += DATA.totalAbs[i] > 0 ? excluded / DATA.totalAbs[i] * 100 : 0;
}
}
}
const hasOthers = othersAbs.some(v => v > 0);
if (!hasOthers) return major;
const hasExcluded = DATA.totalAbs && DATA.totalAbs.some(
(t, i) => t > all.reduce((s, ds) => s + (ds.absData[i] || 0), 0)
);
const othersLabel = minor.length > 0
? 'Others (' + minor.length + (hasExcluded ? '+' : '') + ' authors)'
: 'Others';
return [...major, {
label: othersLabel,
email: '',
absData: othersAbs,
pctData: othersPct,
fill: true,
backgroundColor: 'rgba(148,163,184,0.45)',
borderColor: '#94a3b8',
borderWidth: 1,
tension: 0.3,
isOthers: true,
minorStart: n,
}];
}
// Unix-ms timestamp for each snapshot, parsed from the "YYYY-MM-DD hash" label.
const timestamps = DATA.labels.map(l => new Date(l.slice(0, 10)).getTime());
// Indices for time mode: one entry per unique snapshot day, mapped to the
// highest topological index seen UP TO that day (running maximum).
//
// Why: topological order ≠ chronological order. Feature-branch commits
// carry timestamps from when they were written (e.g. 2019) but are applied
// late in topological history (high index). Picking "the snapshot for that
// day" naively can go backward in state (a later date shows an earlier repo
// state), causing the ugly vertical jump.
//
// Using the running max guarantees the displayed state never goes backward:
// each day shows the most advanced snapshot seen so far. Days with no new
// snapshots are simply absent from the map (chart shows the previous state).
const timeOrder = (() => {
const pairs = timestamps
.map((t, i) => ({ t, i }))
.sort((a, b) => a.t - b.t || a.i - b.i);
let maxIdx = -1;
const dayMap = new Map();
for (const { t, i } of pairs) {
if (i > maxIdx) maxIdx = i;
dayMap.set(t, maxIdx);
}
return [...dayMap.entries()]
.sort((a, b) => a[0] - b[0])
.map(([, i]) => i);
})();
// ── helpers ────────────────────────────────────────────────────────────────
function fmtLines(n) {
if (n >= 1e6) return (n/1e6).toFixed(2) + 'M';
if (n >= 1e3) return (n/1e3).toFixed(1) + 'k';
return n.toLocaleString();
}
function fmtPct(v) { return v.toFixed(1) + '%'; }
function currentData(ds) {
return mode === 'pct' ? ds.pctData : ds.absData;
}
// ── search index ──────────────────────────────────────────────────────────
// Covers both chart datasets (full panel) and excluded members (stats only).
function buildSearchIdx() {
const idx = DATA.datasets.map((ds, rawIdx) => ({
name: ds.label, email: ds.email,
lines: ds.absData[ds.absData.length - 1],
rawIdx, member: null,
}));
if (DATA.members) {
DATA.members.forEach(m => idx.push({
name: m.name, email: m.email, lines: m.finalLines,
rawIdx: -1, member: m,
}));
}
return idx;
}
let searchIdx = buildSearchIdx();
function onSearch(e) {
const q = e.target.value.trim().toLowerCase();
const dd = document.getElementById('search-dropdown');
if (!q) { dd.classList.add('hidden'); return; }
const hits = searchIdx
.filter(r => r.name.toLowerCase().includes(q) || r.email.toLowerCase().includes(q))
.sort((a, b) => b.lines - a.lines)
.slice(0, 12);
if (!hits.length) { dd.classList.add('hidden'); return; }
dd.innerHTML = hits.map((r, i) => {
const tag = (!r.member && r.rawIdx >= currentBands) ? ' · Others' : '';
const dim = r.member ? ' style="opacity:0.5"' : '';
return '<div class="search-result" data-hit="' + i + '"' + dim + '>' +
'<span class="search-result-name">' + r.name + '</span>' +
'<span class="search-result-meta">' + fmtLines(r.lines) + tag + '</span>' +
'</div>';
}).join('');
dd.querySelectorAll('.search-result').forEach((el, i) => {
el.addEventListener('click', () => pickSearch(hits[i]));
});
dd.classList.remove('hidden');
}
function pickSearch(hit) {
if (hit.member) showMemberPanel(hit.member);
else showRawPanel(hit.rawIdx);
document.getElementById('author-search').value = '';
document.getElementById('search-dropdown').classList.add('hidden');
}
document.addEventListener('click', e => {
if (!e.target.closest('.search-wrap'))
document.getElementById('search-dropdown').classList.add('hidden');
});
// ── build Chart.js datasets from displayDatasets ───────────────────────────
// Both modes pre-compute cumulative sums and use fill:'-1' so each band's
// fill covers only its own region (no overlap). This keeps colors identical
// between commit and time modes (overlapping fills would wash colours out).
function makeChartDatasets() {
const dds = displayDatasets();
const order = xMode === 'time' ? timeOrder : dds[0].absData.map((_, i) => i);
const n = order.length;
const cumulative = new Float64Array(n);
return dds.map((ds, dsIdx) => {
const vals = currentData(ds);
const rawData = order.map(i => vals[i]);
const data = rawData.map((v, j) => {
cumulative[j] += v;
return xMode === 'time'
? { x: timestamps[order[j]], y: cumulative[j] }
: cumulative[j];
});
return {
label: ds.label,
data,
rawData,
fill: dsIdx === 0 ? 'origin' : '-1',
backgroundColor: ds.backgroundColor,
borderColor: ds.borderColor,
borderWidth: ds.borderWidth,
tension: ds.tension,
};
});
}
// Return the display value (non-cumulative) for a dataset at a point index.
function displayValue(dsIdx, pointIdx) {
const ds = chart.data.datasets[dsIdx];
return ds.rawData ? ds.rawData[pointIdx] : 0;
}
// ── custom tooltip positioner: follows cursor on the side, never below ────
Chart.Tooltip.positioners.cursor = function(items, pos) {
if (!items.length) return false;
const offset = 16;
const tipWidth = this.width || 200;
const rightEdge = this.chart.chartArea.right;
if (pos.x + offset + tipWidth > rightEdge) {
// Not enough room on the right — flip to the left.
return { x: pos.x - offset, y: pos.y, xAlign: 'right', yAlign: 'center' };
}
return { x: pos.x + offset, y: pos.y, xAlign: 'left', yAlign: 'center' };
};
// ── initial chart ─────────────────────────────────────────────────────────
const chart = new Chart(document.getElementById('chart'), {
type: 'line',
data: { labels: DATA.labels, datasets: makeChartDatasets() },
options: chartOptions(),
});
// Initialise bands controls and author count
(() => {
const max = FOLDERS[0].chart.datasets.length;
const slider = document.getElementById('bands-slider');
slider.max = max; slider.value = currentBands;
document.getElementById('bands-input').value = currentBands;
document.getElementById('author-count').textContent = DATA.datasets.length;
})();
function applyXMode() {
// In time mode data points carry their own x value; labels array is unused.
chart.data.labels = xMode === 'time' ? [] : DATA.labels;
chart.data.datasets = makeChartDatasets();
chart.options = chartOptions();
chart.update();
}
function setBands(n) {
currentBands = Math.max(1, n);
document.getElementById('bands-slider').value = currentBands;
document.getElementById('bands-input').value = currentBands;
applyXMode();
}
function chartOptions() {
const isPct = mode === 'pct';
return {
responsive: true,
maintainAspectRatio: false,
animation: false,
interaction: { mode: 'index', intersect: false },
onHover(evt) {
// Determine which stacked band the cursor is physically inside.
// 'nearest' picks the closest point, not the visual area — instead we
// accumulate stacked values at the hovered x index and find the band
// whose pixel range brackets the cursor's y coordinate.
if (!evt.native) return;
const pos = Chart.helpers.getRelativePosition(evt.native, chart);
const xEls = chart.getElementsAtEventForMode(
evt.native, 'index', { intersect: false }, true
);
if (!xEls.length) { hoveredDatasetIdx = -1; return; }
const xIdx = xEls[0].index;
const yScale = chart.scales.y;
const datasets = chart.data.datasets;
hoveredDatasetIdx = -1;
// Data is pre-stacked in both modes: dataset[i].data[xIdx] is the
// cumulative top of band i (a {x,y} object in time mode, a number in
// commits mode). Walk bands from bottom (0) upward.
let prevPixel = yScale.getPixelForValue(0);
for (let i = 0; i < datasets.length; i++) {
const pt = datasets[i].data[xIdx];
const cumY = pt != null ? (typeof pt === 'object' ? pt.y : pt) : 0;
const topPixel = yScale.getPixelForValue(cumY);
if (pos.y >= topPixel && pos.y <= prevPixel) {
hoveredDatasetIdx = i; break;
}
prevPixel = topPixel;
}
},
onClick() {
if (hoveredDatasetIdx >= 0) showPanel(hoveredDatasetIdx);
},
scales: {
x: xMode === 'time' ? {
type: 'linear',
ticks: {
color: '#94a3b8', maxTicksLimit: 20, maxRotation: 45, font: { size: 10 },
// Format millisecond tick values as YYYY-MM
callback: v => {
const d = new Date(v);
return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0');
},
},
grid: { color: '#1e293b' },
} : {
ticks: { color: '#94a3b8', maxTicksLimit: 20, maxRotation: 45, font: { size: 10 } },
grid: { color: '#1e293b' },
},
y: {
min: 0,
max: isPct ? 100 : undefined,
ticks: {
color: '#94a3b8',
font: { size: 11 },
callback: isPct ? (v => v + '%') : (v => fmtLines(v)),
},
grid: { color: '#334155' },
},
},
plugins: {
// In time mode, LTTB runs per-dataset independently and may keep
// different point subsets across datasets. Since our y values are
// pre-stacked cumulatives, a missing point in dataset N but present
// in dataset N-1 forces Chart.js to interpolate the fill boundary,
// producing a mismatch (visual "hiccup"). Safe to skip: the data is
// already capped at --max-points so there's rarely much to decimate.
decimation: { enabled: false },
tooltip: {
position: 'cursor',
backgroundColor: '#0f172a',
borderColor: '#475569', borderWidth: 1,
titleColor: '#94a3b8', bodyColor: '#cbd5e1',
filter: item => displayValue(item.datasetIndex, item.dataIndex) > 0,
itemSort: (a, b) =>
displayValue(b.datasetIndex, b.dataIndex) -
displayValue(a.datasetIndex, a.dataIndex),
callbacks: {
title: ctx => {
if (!ctx.length) return '';
if (xMode === 'time') {
return new Date(ctx[0].parsed.x).toISOString().slice(0, 10);
}
return DATA.labels[ctx[0].dataIndex] || '';
},
label: ctx => {
const v = displayValue(ctx.datasetIndex, ctx.dataIndex);
const isHovered = ctx.datasetIndex === hoveredDatasetIdx;
const prefix = isHovered ? '▶ ' : ' ';
return prefix + ctx.dataset.label + ': ' + (isPct ? fmtPct(v) : fmtLines(v) + ' lines');
},
labelTextColor: ctx => {
return ctx.datasetIndex === hoveredDatasetIdx ? '#f1f5f9' : '#94a3b8';
},
},
},
legend: {
position: 'bottom',
labels: { color: '#cbd5e1', padding: 16, boxWidth: 12, font: { size: 11 } },
onClick(evt, item) { showPanel(item.datasetIndex); },
},
},
elements: { point: { radius: 0, hoverRadius: 3 } },
};
}
// ── mode toggles ───────────────────────────────────────────────────────────
function setMode(newMode) {
mode = newMode;
document.getElementById('btn-pct').classList.toggle('active', mode === 'pct');
document.getElementById('btn-abs').classList.toggle('active', mode === 'abs');
applyXMode();
const panel = document.getElementById('author-panel');
if (!panel.classList.contains('hidden')) {
const idx = panel.dataset.authorIdx;
if (idx !== undefined && idx !== '') drawSparkline(+idx);
}
}
function setXMode(m) {
xMode = m;
document.getElementById('btn-x-commits').classList.toggle('active', m === 'commits');
document.getElementById('btn-x-time').classList.toggle('active', m === 'time');
applyXMode();
}
// ── folder selector ───────────────────────────────────────────────────────
function selectFolder(idx) {
currentFolderIdx = idx;
DATA = FOLDERS[idx].chart;
searchIdx = buildSearchIdx();
document.getElementById('author-count').textContent = DATA.datasets.length;
document.getElementById('author-panel').classList.add('hidden');
if (sparkChart) { sparkChart.destroy(); sparkChart = null; }
updateFolderBtn();
applyXMode();
}
function updateFolderBtn() {
const path = FOLDERS[currentFolderIdx].path;
document.getElementById('folder-btn-label').textContent =
path === '/' ? 'whole repo' : path.split('/').pop() + '/';
}
function toggleFolderMenu() {
const menu = document.getElementById('folder-menu');
const btn = document.getElementById('folder-btn');
const opening = menu.classList.toggle('hidden'); // true = now hidden = was open
btn.classList.toggle('open', !opening); // open class when visible
if (!opening) renderFolderMenu(); // rebuild on open
}
function buildMenuNodes() {
// Build a flat sorted list of all tree nodes (FOLDERS paths + ancestor dirs).
const nodeMap = new Map();
// "/" is always index 0 in FOLDERS; handle it specially (depth = -1 sentinel)
nodeMap.set('/', { path: '/', folderIdx: 0, depth: -1 });
FOLDERS.slice(1).forEach((f, fi) => {
const parts = f.path.split('/');
for (let d = 0; d < parts.length; d++) {
const path = parts.slice(0, d + 1).join('/');
if (!nodeMap.has(path)) nodeMap.set(path, { path, folderIdx: -1, depth: d });
}
nodeMap.get(f.path).folderIdx = fi + 1; // fi+1 because we skipped index 0 ("/")
});
return [...nodeMap.values()].sort((a, b) => {
if (a.path === '/') return -1;
if (b.path === '/') return 1;
return a.path.localeCompare(b.path);
});
}
function renderFolderMenu() {
const allNodes = buildMenuNodes();
const treeNodes = allNodes.filter(n => n.path !== '/'); // exclude "/" from tree calcs
function hasLaterSiblingAt(ti, level) {
const parts = treeNodes[ti].path.split('/');
if (level >= parts.length) return false;
const myAncestor = parts.slice(0, level + 1).join('/');
const parentPath = parts.slice(0, level).join('/');
for (let j = ti + 1; j < treeNodes.length; j++) {
const op = treeNodes[j].path.split('/');
if (op.length > level &&
op.slice(0, level).join('/') === parentPath &&
op.slice(0, level + 1).join('/') !== myAncestor) return true;
}
return false;
}
function isLastSibling(ti) {
const n = treeNodes[ti];
const myParent = n.path.split('/').slice(0, n.depth).join('/');
for (let j = ti + 1; j < treeNodes.length; j++) {
const o = treeNodes[j];
if (o.depth === n.depth &&
o.path.split('/').slice(0, o.depth).join('/') === myParent) return false;
}
return true;
}
let html = '';
// "/" entry — always at the top, no tree connectors
html += `<div class="folder-item${currentFolderIdx === 0 ? ' active' : ''}" data-idx="0">/ <span style="color:#64748b;font-size:.72rem">whole repo</span></div>`;
treeNodes.forEach((n, ti) => {
const name = n.path.split('/').pop();
let prefix = '';
for (let level = 0; level < n.depth; level++)
prefix += hasLaterSiblingAt(ti, level) ? '│ ' : ' ';
const connector = isLastSibling(ti) ? '└── ' : '├── ';
const isActive = n.folderIdx === currentFolderIdx;
const isAncestor = n.folderIdx < 0;
const cls = 'folder-item' + (isActive ? ' active' : '') + (isAncestor ? ' ancestor' : '');
const idx = n.folderIdx >= 0 ? `data-idx="${n.folderIdx}"` : '';
html += `<div class="${cls}" ${idx}><span class="tree-pfx">${prefix}${connector}</span>${name}/</div>`;
});
const menu = document.getElementById('folder-menu');
menu.innerHTML = html;
menu.querySelectorAll('.folder-item[data-idx]').forEach(el => {
el.addEventListener('click', () => {
selectFolder(+el.dataset.idx);
document.getElementById('folder-menu').classList.add('hidden');
document.getElementById('folder-btn').classList.remove('open');
});
});
}
// Initialise folder dropdown (hidden when only one folder).
(() => {
if (FOLDERS.length <= 1) return;
document.getElementById('folder-dropdown-wrap').style.display = '';
document.addEventListener('click', e => {
if (!e.target.closest('#folder-dropdown-wrap')) {
document.getElementById('folder-menu').classList.add('hidden');
document.getElementById('folder-btn').classList.remove('open');
}
});
})();
// ── author panel ───────────────────────────────────────────────────────────
// showMemberPanel: for excluded authors (beyond --max-graph) — stats only, no sparkline.
function showMemberPanel(m) {
const last = DATA.totalAbs ? DATA.totalAbs.length - 1 : DATA.datasets[0].absData.length - 1;
const totalNow = DATA.totalAbs ? DATA.totalAbs[last] :
DATA.datasets.reduce((s, d) => s + (d.absData[last] || 0), 0);
const finalPct = totalNow > 0 ? m.finalLines / totalNow * 100 : 0;
const peakPct = m.peakTotal > 0 ? m.peakLines / m.peakTotal * 100 : 0;
document.getElementById('panel-color-bar').style.background = '#64748b';
document.getElementById('panel-name').textContent = m.name;
document.getElementById('panel-email').textContent = m.email;
document.getElementById('panel-stats').innerHTML =
stat(fmtLines(m.finalLines), 'current lines') +
stat(fmtPct(finalPct), 'current share') +
stat(fmtLines(m.peakLines), 'peak lines') +
stat(fmtPct(peakPct), 'peak share') +
stat(m.firstDate || '—', 'first commit', true) +
stat(m.lastDate || '—', 'last commit', true);
document.getElementById('panel-sparkline-wrap').style.display = 'none';
document.getElementById('panel-members-wrap').style.display = 'none';
document.getElementById('panel-hint').textContent = 'not graphed — increase --max-graph to show';
if (sparkChart) { sparkChart.destroy(); sparkChart = null; }
const panel = document.getElementById('author-panel');
panel.dataset.authorIdx = '';
panel.classList.remove('hidden');
}
// showPanel: display index into displayDatasets() — used by chart click / legend.
function showPanel(displayIdx, highlightMember) {
const dd = displayDatasets();
const ds = dd[displayIdx];
if (ds.isOthers) {
// Others band — show aggregated stats + scrollable member list.
const abs = ds.absData;
const last = abs.length - 1;
const finalLines = abs[last];
const totalNow = dd.reduce((s, d) => s + (d.absData[last] || 0), 0);
const finalPct = totalNow > 0 ? finalLines / totalNow * 100 : 0;
document.getElementById('panel-color-bar').style.background = '#94a3b8';
document.getElementById('panel-name').textContent = ds.label;
document.getElementById('panel-email').textContent = '';
document.getElementById('panel-stats').innerHTML =
stat(fmtLines(finalLines), 'current lines') +
stat(fmtPct(finalPct), 'current share');
document.getElementById('panel-sparkline-wrap').style.display = 'none';
const membersWrap = document.getElementById('panel-members-wrap');
membersWrap.style.display = 'flex';
document.getElementById('panel-hint').textContent = 'sorted by current line count — click for details';
if (sparkChart) { sparkChart.destroy(); sparkChart = null; }
const minor = DATA.datasets.slice(ds.minorStart)
.map((m, i) => ({ name: m.label, email: m.email, rawIdx: ds.minorStart + i, lines: m.absData[last], excluded: false }))
.concat((DATA.members || []).map(m => ({ name: m.name, email: m.email, rawIdx: -1, lines: m.finalLines, excluded: true, member: m })))
.sort((a, b) => b.lines - a.lines);
membersWrap.innerHTML = minor.map(({ name, email, rawIdx, lines, excluded }, rowIdx) => {
const hi = !excluded && highlightMember === name ? ' highlighted' : '';
const dim = excluded ? ' style="opacity:0.5"' : '';
const dataAttr = excluded ? ' data-member-row="' + rowIdx + '"' : ' data-raw-idx="' + rawIdx + '"';
return '<div class="member-row' + hi + '"' + dim + dataAttr + '>' +
'<span class="member-name" title="' + email + '">' + name + '</span>' +
'<span class="member-lines">' + fmtLines(lines) + '</span>' +
'</div>';
}).join('');
membersWrap.querySelectorAll('.member-row[data-raw-idx]').forEach(el => {
el.addEventListener('click', () => showRawPanel(+el.dataset.rawIdx));
});
membersWrap.querySelectorAll('.member-row[data-member-row]').forEach(el => {
const row = minor[+el.dataset.memberRow];
el.addEventListener('click', () => showMemberPanel(row.member));
});
if (highlightMember) {
const row = membersWrap.querySelector('.highlighted');
if (row) row.scrollIntoView({ block: 'nearest' });
}
const panel = document.getElementById('author-panel');
panel.dataset.authorIdx = '';
panel.classList.remove('hidden');
} else {
// Individual author band — displayIdx === rawIdx for the major slice.
showRawPanel(displayIdx);
}
}
// showRawPanel: raw index into DATA.datasets — shows full stats + sparkline.
// Used for individual bands, Others members, and search results.
function showRawPanel(rawIdx) {
const ds = DATA.datasets[rawIdx];
const abs = ds.absData;
const last = abs.length - 1;
let peak = 0, peakIdx = 0, firstIdx = -1;
for (let i = 0; i <= last; i++) {
if (abs[i] > peak) { peak = abs[i]; peakIdx = i; }
if (firstIdx < 0 && abs[i] > 0) firstIdx = i;
}
const finalLines = abs[last];
const totalNow = DATA.datasets.reduce((s, d) => s + (d.absData[last] || 0), 0);
const finalPct = totalNow > 0 ? finalLines / totalNow * 100 : 0;
let totalAtPeak = 0;
DATA.datasets.forEach(d => totalAtPeak += d.absData[peakIdx] || 0);
const peakPct = totalAtPeak > 0 ? peak / totalAtPeak * 100 : 0;
const firstDate = firstIdx >= 0 ? DATA.labels[firstIdx].split(' ')[0] : '—';
const lastDate = DATA.labels[last].split(' ')[0];
document.getElementById('panel-color-bar').style.background = ds.borderColor;
document.getElementById('panel-name').textContent = ds.label;
document.getElementById('panel-email').textContent = ds.email;
document.getElementById('panel-stats').innerHTML =
stat(fmtLines(finalLines), 'current lines') +
stat(fmtPct(finalPct), 'current share') +
stat(fmtLines(peak), 'peak lines') +
stat(fmtPct(peakPct), 'peak share') +
stat(firstDate, 'first commit', true) +
stat(lastDate, 'last commit', true);
document.getElementById('panel-sparkline-wrap').style.display = '';
document.getElementById('panel-members-wrap').style.display = 'none';
const inOthers = rawIdx >= currentBands;
document.getElementById('panel-hint').textContent =
inOthers ? 'part of Others — increase bands to show individually' : 'own line count over time';
drawSparkline(rawIdx);
const panel = document.getElementById('author-panel');
panel.dataset.authorIdx = rawIdx;
panel.classList.remove('hidden');
document.getElementById('author-search').value = '';
document.getElementById('search-dropdown').classList.add('hidden');
}
function stat(value, label, full) {
return '<div class="stat' + (full ? ' full' : '') + '">' +
'<div class="stat-value">' + value + '</div>' +
'<div class="stat-label">' + label + '</div>' +
'</div>';
}
function drawSparkline(idx) {
const ds = DATA.datasets[idx];
const data = mode === 'pct' ? ds.pctData : ds.absData;
const isPct = mode === 'pct';
if (sparkChart) { sparkChart.destroy(); sparkChart = null; }
sparkChart = new Chart(document.getElementById('sparkline'), {
type: 'line',
data: {
labels: DATA.labels,
datasets: [{
data: data,
fill: true,
backgroundColor: ds.backgroundColor,
borderColor: ds.borderColor,
borderWidth: 1.5,
tension: 0.3,
}],
},
options: {
responsive: true,
maintainAspectRatio: false,
animation: false,
plugins: { legend: { display: false }, tooltip: { enabled: false },
decimation: { enabled: true, algorithm: 'lttb', samples: 100 } },
scales: {
x: { display: false, stacked: false },
y: {
display: true, stacked: false, min: 0,
ticks: { color: '#64748b', font: { size: 9 },
callback: isPct ? (v => v.toFixed(0)+'%') : (v => fmtLines(v)),
maxTicksLimit: 4 },
grid: { color: '#1a2744' },
},
},
elements: { point: { radius: 0 } },
},
});
}
function closePanel() {
document.getElementById('author-panel').classList.add('hidden');
if (sparkChart) { sparkChart.destroy(); sparkChart = null; }
}
</script>
</body>
</html>