repometry 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/package.json +1 -1
- package/target/main/resources/report/json/report-v2.schema.json +13 -1
- package/target/main/resources/viewer/styles.css +2 -2
- package/target/main/ts/api/git/git.d.ts +1 -0
- package/target/main/ts/api/git/git.js +12 -0
- package/target/main/ts/api/git/inspection-source.js +2 -8
- package/target/main/ts/api/git/local.d.ts +1 -1
- package/target/main/ts/api/git/local.js +39 -5
- package/target/main/ts/api/process/docker-tool-runner.d.ts +13 -0
- package/target/main/ts/api/process/docker-tool-runner.js +108 -0
- package/target/main/ts/api/process/failure.d.ts +1 -0
- package/target/main/ts/api/process/failure.js +12 -0
- package/target/main/ts/api/process/plugin.d.ts +10 -0
- package/target/main/ts/api/process/plugin.js +96 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +3 -2
- package/target/main/ts/compose/analyze-snapshot.js +82 -29
- package/target/main/ts/compose/inspect.d.ts +5 -0
- package/target/main/ts/compose/inspect.js +10 -6
- package/target/main/ts/core/engine/execute.d.ts +3 -1
- package/target/main/ts/core/engine/execute.js +14 -2
- package/target/main/ts/core/engine/operation-cache.d.ts +14 -0
- package/target/main/ts/core/engine/operation-cache.js +66 -0
- package/target/main/ts/core/engine/plan.d.ts +1 -0
- package/target/main/ts/core/engine/plan.js +22 -3
- package/target/main/ts/core/engine/plugin.d.ts +8 -1
- package/target/main/ts/core/engine/plugin.js +1 -3
- package/target/main/ts/core/engine/report-products.js +2 -13
- package/target/main/ts/core/model/clone-source.js +1 -1
- package/target/main/ts/core/model/code-structure.d.ts +3 -0
- package/target/main/ts/core/model/code-structure.js +4 -1
- package/target/main/ts/core/model/finding-ignore.js +1 -1
- package/target/main/ts/core/model/finding.js +1 -1
- package/target/main/ts/core/model/line-coverage.d.ts +5 -1
- package/target/main/ts/core/model/line-coverage.js +14 -11
- package/target/main/ts/core/model/measurement.js +1 -1
- package/target/main/ts/core/model/plugin-data.d.ts +2 -0
- package/target/main/ts/core/model/plugin-data.js +15 -1
- package/target/main/ts/core/model/quality-summary.js +1 -1
- package/target/main/ts/core/model/scanner-import.js +1 -1
- package/target/main/ts/core/model/snapshot.d.ts +1 -0
- package/target/main/ts/core/model/snapshot.js +5 -1
- package/target/main/ts/core/model/source.d.ts +3 -0
- package/target/main/ts/core/model/source.js +15 -0
- package/target/main/ts/core/ports/tool-runner.d.ts +18 -0
- package/target/main/ts/core/ports/tool-runner.js +2 -0
- package/target/main/ts/plugin.d.ts +7 -1
- package/target/main/ts/plugin.js +3 -1
- package/target/main/ts/plugins/coverage/coverage.d.ts +5 -2
- package/target/main/ts/plugins/coverage/coverage.js +35 -10
- package/target/main/ts/plugins/language-js/function-facts.d.ts +1 -0
- package/target/main/ts/plugins/language-js/function-facts.js +30 -4
- package/target/main/ts/report/html/app/viewer-chart-bars.d.ts +11 -0
- package/target/main/ts/report/html/app/viewer-chart-bars.js +54 -0
- package/target/main/ts/report/html/app/viewer-chart-label.d.ts +15 -0
- package/target/main/ts/report/html/app/viewer-chart-label.js +43 -0
- package/target/main/ts/report/html/app/viewer-chart-line.d.ts +24 -0
- package/target/main/ts/report/html/app/viewer-chart-line.js +89 -0
- package/target/main/ts/report/html/app/viewer-chart-points.d.ts +49 -0
- package/target/main/ts/report/html/app/viewer-chart-points.js +74 -0
- package/target/main/ts/report/html/app/viewer-chart-scale.d.ts +21 -0
- package/target/main/ts/report/html/app/viewer-chart-scale.js +93 -0
- package/target/main/ts/report/html/app/viewer-chart-svg.d.ts +28 -0
- package/target/main/ts/report/html/app/viewer-chart-svg.js +41 -0
- package/target/main/ts/report/html/app/viewer-chart-time.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-chart-time.js +150 -0
- package/target/main/ts/report/html/app/viewer-chart-tip.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-chart-tip.js +210 -0
- package/target/main/ts/report/html/app/viewer-chart-x.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-chart-x.js +50 -0
- package/target/main/ts/report/html/app/viewer-chart.d.ts +4 -98
- package/target/main/ts/report/html/app/viewer-chart.js +16 -677
- package/target/main/ts/report/html/app/viewer-code-map.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-code-map.js +175 -0
- package/target/main/ts/report/html/app/viewer-columns.d.ts +38 -0
- package/target/main/ts/report/html/app/viewer-columns.js +92 -0
- package/target/main/ts/report/html/app/viewer-commit-picker.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-commit-picker.js +229 -0
- package/target/main/ts/report/html/app/viewer-commits.d.ts +5 -9
- package/target/main/ts/report/html/app/viewer-commits.js +17 -216
- package/target/main/ts/report/html/app/viewer-controls.d.ts +43 -0
- package/target/main/ts/report/html/app/viewer-controls.js +141 -0
- package/target/main/ts/report/html/app/viewer-copy.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-copy.js +64 -0
- package/target/main/ts/report/html/app/viewer-diagnostics.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-diagnostics.js +60 -0
- package/target/main/ts/report/html/app/viewer-dom.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-dom.js +99 -0
- package/target/main/ts/report/html/app/viewer-file-aside.d.ts +19 -0
- package/target/main/ts/report/html/app/viewer-file-aside.js +124 -0
- package/target/main/ts/report/html/app/viewer-file-figures.d.ts +15 -0
- package/target/main/ts/report/html/app/viewer-file-figures.js +60 -0
- package/target/main/ts/report/html/app/viewer-file-source.d.ts +7 -0
- package/target/main/ts/report/html/app/viewer-file-source.js +119 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +2 -118
- package/target/main/ts/report/html/app/viewer-files.js +24 -2184
- package/target/main/ts/report/html/app/viewer-filter.d.ts +3 -51
- package/target/main/ts/report/html/app/viewer-filter.js +111 -450
- package/target/main/ts/report/html/app/viewer-hotspots.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-hotspots.js +131 -0
- package/target/main/ts/report/html/app/viewer-inspection.d.ts +69 -0
- package/target/main/ts/report/html/app/viewer-inspection.js +36 -0
- package/target/main/ts/report/html/app/viewer-issue-group.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-issue-group.js +174 -0
- package/target/main/ts/report/html/app/viewer-issues.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-issues.js +173 -0
- package/target/main/ts/report/html/app/viewer-language-bar.d.ts +9 -0
- package/target/main/ts/report/html/app/viewer-language-bar.js +72 -0
- package/target/main/ts/report/html/app/viewer-languages.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-languages.js +93 -0
- package/target/main/ts/report/html/app/viewer-layout.d.ts +14 -0
- package/target/main/ts/report/html/app/viewer-layout.js +134 -0
- package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +47 -0
- package/target/main/ts/report/html/app/viewer-line-coverage.js +121 -0
- package/target/main/ts/report/html/app/viewer-locations.d.ts +16 -0
- package/target/main/ts/report/html/app/viewer-locations.js +31 -0
- package/target/main/ts/report/html/app/viewer-map-scale.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-map-scale.js +147 -0
- package/target/main/ts/report/html/app/viewer-map-shape.d.ts +42 -0
- package/target/main/ts/report/html/app/viewer-map-shape.js +102 -0
- package/target/main/ts/report/html/app/viewer-metric-format.d.ts +23 -0
- package/target/main/ts/report/html/app/viewer-metric-format.js +93 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -20
- package/target/main/ts/report/html/app/viewer-metric-registry.js +0 -77
- package/target/main/ts/report/html/app/viewer-metrics-view.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-metrics-view.js +162 -0
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +6 -1
- package/target/main/ts/report/html/app/viewer-metrics.js +53 -35
- package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-overview-cards.js +112 -0
- package/target/main/ts/report/html/app/viewer-overview-hotspots.d.ts +9 -0
- package/target/main/ts/report/html/app/viewer-overview-hotspots.js +173 -0
- package/target/main/ts/report/html/app/viewer-overview-lead.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-overview-lead.js +116 -0
- package/target/main/ts/report/html/app/viewer-profile-badges.d.ts +11 -0
- package/target/main/ts/report/html/app/viewer-profile-badges.js +119 -0
- package/target/main/ts/report/html/app/viewer-profile-table.d.ts +29 -0
- package/target/main/ts/report/html/app/viewer-profile-table.js +124 -0
- package/target/main/ts/report/html/app/viewer-profile.d.ts +2 -6
- package/target/main/ts/report/html/app/viewer-profile.js +6 -248
- package/target/main/ts/report/html/app/viewer-pull-sections.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-pull-sections.js +118 -0
- package/target/main/ts/report/html/app/viewer-pull-trend.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-pull-trend.js +63 -0
- package/target/main/ts/report/html/app/viewer-pulls.d.ts +0 -1
- package/target/main/ts/report/html/app/viewer-pulls.js +28 -178
- package/target/main/ts/report/html/app/viewer-query-field.d.ts +19 -0
- package/target/main/ts/report/html/app/viewer-query-field.js +203 -0
- package/target/main/ts/report/html/app/viewer-route.d.ts +34 -0
- package/target/main/ts/report/html/app/viewer-route.js +55 -0
- package/target/main/ts/report/html/app/viewer-shell.d.ts +20 -0
- package/target/main/ts/report/html/app/viewer-shell.js +116 -0
- package/target/main/ts/report/html/app/viewer-source-view.d.ts +49 -0
- package/target/main/ts/report/html/app/viewer-source-view.js +150 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +0 -84
- package/target/main/ts/report/html/app/viewer-source.js +7 -365
- package/target/main/ts/report/html/app/viewer-suggest.d.ts +13 -0
- package/target/main/ts/report/html/app/viewer-suggest.js +91 -0
- package/target/main/ts/report/html/app/viewer-sunburst.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-sunburst.js +40 -0
- package/target/main/ts/report/html/app/viewer-table-cells.d.ts +25 -0
- package/target/main/ts/report/html/app/viewer-table-cells.js +129 -0
- package/target/main/ts/report/html/app/viewer-table-rows.d.ts +54 -0
- package/target/main/ts/report/html/app/viewer-table-rows.js +95 -0
- package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +16 -0
- package/target/main/ts/report/html/app/viewer-tokenizer.js +192 -0
- package/target/main/ts/report/html/app/viewer-totals.d.ts +14 -0
- package/target/main/ts/report/html/app/viewer-totals.js +89 -0
- package/target/main/ts/report/html/app/viewer-treemap.d.ts +24 -0
- package/target/main/ts/report/html/app/viewer-treemap.js +112 -0
- package/target/main/ts/report/html/app/viewer-trend-data.d.ts +49 -0
- package/target/main/ts/report/html/app/viewer-trend-data.js +105 -0
- package/target/main/ts/report/html/app/viewer-trend-nav.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-trend-nav.js +85 -0
- package/target/main/ts/report/html/app/viewer-trend-points.d.ts +30 -0
- package/target/main/ts/report/html/app/viewer-trend-points.js +128 -0
- package/target/main/ts/report/html/app/viewer-trend-series.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-trend-series.js +98 -0
- package/target/main/ts/report/html/app/viewer-trends.d.ts +2 -70
- package/target/main/ts/report/html/app/viewer-trends.js +41 -392
- package/target/main/ts/report/html/app/viewer.js +152 -663
- package/target/main/ts/report/json/store/local-store.js +2 -12
- package/target/main/ts/report/json/store/operation-cache.d.ts +8 -0
- package/target/main/ts/report/json/store/operation-cache.js +32 -0
- package/target/main/ts/report/json/store/replace-file.d.ts +1 -0
- package/target/main/ts/report/json/store/replace-file.js +14 -0
- package/target/main/ts/report.d.ts +1 -0
- package/target/main/ts/report.js +1 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { basename, svgElement } from './viewer-dom.js';
|
|
2
|
+
/** The worst aspect ratio of a row of areas laid along a side: the row grows while this improves. */
|
|
3
|
+
function worst(areas, side) {
|
|
4
|
+
const sum = areas.reduce((a, b) => a + b, 0);
|
|
5
|
+
return Math.max(...areas.map(area => Math.max((side * side * area) / (sum * sum), (sum * sum) / (side * side * area))));
|
|
6
|
+
}
|
|
7
|
+
/** Lays a row along the shorter side of the box; returns the boxes and the room left beside them. */
|
|
8
|
+
function layRow(row, scale, box) {
|
|
9
|
+
const sum = row.reduce((acc, item) => acc + item.area * scale, 0);
|
|
10
|
+
const vertical = box.w >= box.h;
|
|
11
|
+
const thickness = sum / (vertical ? box.h : box.w);
|
|
12
|
+
let offset = 0;
|
|
13
|
+
const placed = row.map(item => {
|
|
14
|
+
const length = (item.area * scale) / thickness;
|
|
15
|
+
const at = offset;
|
|
16
|
+
offset += length;
|
|
17
|
+
return { branch: item, box: vertical ? { x: box.x, y: box.y + at, w: thickness, h: length } : { x: box.x + at, y: box.y, w: length, h: thickness } };
|
|
18
|
+
});
|
|
19
|
+
const rest = vertical ? { x: box.x + thickness, y: box.y, w: box.w - thickness, h: box.h }
|
|
20
|
+
: { x: box.x, y: box.y + thickness, w: box.w, h: box.h - thickness };
|
|
21
|
+
return { placed, rest };
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Squarified treemap layout: rows of tiles kept as close to square as the areas allow, largest first, so sizes stay
|
|
25
|
+
* comparable at a glance.
|
|
26
|
+
*/
|
|
27
|
+
export function squarify(children, room) {
|
|
28
|
+
const items = [...children].sort((a, b) => b.area - a.area);
|
|
29
|
+
const total = items.reduce((sum, item) => sum + item.area, 0);
|
|
30
|
+
if (total <= 0 || room.w <= 0 || room.h <= 0)
|
|
31
|
+
return [];
|
|
32
|
+
const scale = (room.w * room.h) / total;
|
|
33
|
+
const areas = (line) => line.map(item => item.area * scale);
|
|
34
|
+
const placed = [];
|
|
35
|
+
let box = room;
|
|
36
|
+
let row = [];
|
|
37
|
+
const lay = () => {
|
|
38
|
+
const laid = layRow(row, scale, box);
|
|
39
|
+
placed.push(...laid.placed);
|
|
40
|
+
box = laid.rest;
|
|
41
|
+
};
|
|
42
|
+
for (const item of items) {
|
|
43
|
+
const side = Math.min(box.w, box.h);
|
|
44
|
+
if (row.length === 0 || worst(areas([...row, item]), side) <= worst(areas(row), side))
|
|
45
|
+
row.push(item);
|
|
46
|
+
else {
|
|
47
|
+
lay();
|
|
48
|
+
row = [item];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (row.length)
|
|
52
|
+
lay();
|
|
53
|
+
return placed;
|
|
54
|
+
}
|
|
55
|
+
/** A label cut to the room it has, at about six pixels a character. */
|
|
56
|
+
export function fit(text, room) {
|
|
57
|
+
const chars = Math.floor(room / 6.2);
|
|
58
|
+
if (text.length <= chars)
|
|
59
|
+
return text;
|
|
60
|
+
return chars > 2 ? `${text.slice(0, chars - 1)}…` : '';
|
|
61
|
+
}
|
|
62
|
+
/** A chain of folders that each hold one folder is one frame: src/main/ts/ rather than three nested ones. */
|
|
63
|
+
export function collapseChain(byParent, branch) {
|
|
64
|
+
let inner = byParent.get(branch.entry.path) ?? [];
|
|
65
|
+
let name = basename(branch.entry.path);
|
|
66
|
+
while (inner.length === 1 && inner[0].folder) {
|
|
67
|
+
name += `/${basename(inner[0].entry.path)}`;
|
|
68
|
+
inner = byParent.get(inner[0].entry.path) ?? [];
|
|
69
|
+
}
|
|
70
|
+
return { name, inner };
|
|
71
|
+
}
|
|
72
|
+
/** The strip a folder's name takes at the top of its frame: a full one where it fits, a hairline where it does not. */
|
|
73
|
+
function stripHeight(open, box) {
|
|
74
|
+
if (!open)
|
|
75
|
+
return 0;
|
|
76
|
+
return box.w > 64 && box.h > 44 ? 15 : 3;
|
|
77
|
+
}
|
|
78
|
+
function labelFits(folder, open, strip, box) {
|
|
79
|
+
if (open && strip <= 3)
|
|
80
|
+
return false;
|
|
81
|
+
return box.w > (folder ? 64 : 44) && box.h > (open ? 0 : 17);
|
|
82
|
+
}
|
|
83
|
+
function tileLabel(text, box, shade) {
|
|
84
|
+
const label = svgElement('text');
|
|
85
|
+
label.classList.add('fx-tile-label');
|
|
86
|
+
if (shade !== 'none' && shade >= 3)
|
|
87
|
+
label.classList.add('fx-tile-label-light');
|
|
88
|
+
label.setAttribute('x', (box.x + 4).toFixed(1));
|
|
89
|
+
label.setAttribute('y', (box.y + 11.5).toFixed(1));
|
|
90
|
+
label.textContent = fit(text, box.w - 8);
|
|
91
|
+
return label;
|
|
92
|
+
}
|
|
93
|
+
function rectangle(box) {
|
|
94
|
+
return `M${box.x.toFixed(1)},${box.y.toFixed(1)}h${box.w.toFixed(1)}v${box.h.toFixed(1)}h${(-box.w).toFixed(1)}z`;
|
|
95
|
+
}
|
|
96
|
+
/** The tree as tiles: folders frame their contents under a name strip, files fill the space by size. */
|
|
97
|
+
export function drawTiles(map, children, room, level) {
|
|
98
|
+
for (const { branch, box } of squarify(children, room)) {
|
|
99
|
+
if (box.w < 2 || box.h < 2 || map.drawn >= 600)
|
|
100
|
+
continue;
|
|
101
|
+
const tile = map.tile(branch, rectangle(box));
|
|
102
|
+
if (branch.folder)
|
|
103
|
+
tile.classList.add('fx-tile-folder');
|
|
104
|
+
const { name, inner } = collapseChain(map.byParent, branch);
|
|
105
|
+
const open = branch.folder && inner.length > 0 && level < map.depth && box.w > 28 && box.h > 28;
|
|
106
|
+
const strip = stripHeight(open, box);
|
|
107
|
+
if (labelFits(branch.folder, open, strip, box))
|
|
108
|
+
tile.append(tileLabel(name + (branch.folder ? '/' : ''), box, map.shade(branch)));
|
|
109
|
+
if (open)
|
|
110
|
+
drawTiles(map, inner, { x: box.x + 3, y: box.y + strip, w: box.w - 6, h: box.h - strip - 3 }, level + 1);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { InspectionContext } from '../../json/wire/inspection-context-model.js';
|
|
2
|
+
import type { QualitySummary } from '../../json/wire/domain-types.js';
|
|
3
|
+
import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
|
|
4
|
+
import type { Metric } from './viewer-metrics.js';
|
|
5
|
+
export type TrendView = Metric | 'debt-changes' | 'diff-coverage';
|
|
6
|
+
export type Period = '30' | '100' | 'all';
|
|
7
|
+
export interface TrendData {
|
|
8
|
+
readonly reports: readonly PublicHistoryEntry[];
|
|
9
|
+
readonly quality: Record<string, QualitySummary>;
|
|
10
|
+
readonly context: Record<string, InspectionContext> | null;
|
|
11
|
+
readonly compact: boolean;
|
|
12
|
+
/** Link to the Trends page for a commit, keeping or replacing the view and period. */
|
|
13
|
+
readonly link: (sha: string, view?: TrendView, period?: Period) => string;
|
|
14
|
+
}
|
|
15
|
+
export declare function viewLabel(view: TrendView): string;
|
|
16
|
+
/** The metric a view reads at a commit; the views drawn by hand read none. */
|
|
17
|
+
export declare function viewMetric(view: TrendView): Metric | null;
|
|
18
|
+
/**
|
|
19
|
+
* The series list: Repometry's own groups, with other plugins' metrics joining a group they name or one of their own.
|
|
20
|
+
* A registry metric the groups already place keeps its place, and is left out where this history has no such metric.
|
|
21
|
+
*/
|
|
22
|
+
export declare function groups(): (readonly [string, readonly TrendView[]])[];
|
|
23
|
+
export declare function isTrendView(value: string | null | undefined): value is TrendView;
|
|
24
|
+
export declare function isPeriod(value: string | null | undefined): value is Period;
|
|
25
|
+
/** A metric's value at a commit, read with the commit's own quality summary and context. */
|
|
26
|
+
export declare function trendValue(data: Pick<TrendData, 'quality' | 'context'>, report: PublicHistoryEntry, metric: Metric): number | null;
|
|
27
|
+
/** Views that have data in this history, in display order; debt changes need remediation times. */
|
|
28
|
+
export declare function availableViews(data: TrendData): TrendView[];
|
|
29
|
+
/** The whole curve by default; only a very long history opens on its last hundred inspections. */
|
|
30
|
+
export declare function defaultPeriod(total: number): Period;
|
|
31
|
+
export interface Window {
|
|
32
|
+
readonly start: number;
|
|
33
|
+
readonly end: number;
|
|
34
|
+
}
|
|
35
|
+
/** The inspections shown for a period, oldest first, always including the selected one. */
|
|
36
|
+
export declare function windowOf(reports: readonly PublicHistoryEntry[], selected: PublicHistoryEntry, period: Period): PublicHistoryEntry[];
|
|
37
|
+
/**
|
|
38
|
+
* The slice of history a chart shows, newest first by index. Picking a commit inside the current slice keeps it, so
|
|
39
|
+
* the axes and scale stay where the eye left them; only a commit outside it moves the slice, which then centres on
|
|
40
|
+
* that commit so its neighbours on both sides are in view. The newest commits are the default slice.
|
|
41
|
+
*/
|
|
42
|
+
export declare function stableWindow(reports: readonly PublicHistoryEntry[], index: number, size: number, key: string): Window;
|
|
43
|
+
/** Commit time of an inspection, or null for exports made before commit times were recorded. */
|
|
44
|
+
export declare function commitTime(report: PublicHistoryEntry): number | null;
|
|
45
|
+
/**
|
|
46
|
+
* The inspections a time chart can place: when the history has commit times, one without (a root commit has no churn
|
|
47
|
+
* window to read it from) cannot be put on the time axis, so it stays out of the chart and in the table.
|
|
48
|
+
*/
|
|
49
|
+
export declare function charted(shown: readonly PublicHistoryEntry[]): PublicHistoryEntry[];
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { isMetric, labelOf, metricLabels, metricValue, pluginMetrics } from './viewer-metrics.js';
|
|
2
|
+
/** The views the viewer draws by hand rather than from one metric's values. */
|
|
3
|
+
const ownViews = new Set(['debt-changes', 'diff-coverage']);
|
|
4
|
+
const ownLabels = {
|
|
5
|
+
debt: 'Technical debt', 'debt-changes': 'Technical debt changes', 'diff-coverage': 'Changed-line coverage',
|
|
6
|
+
};
|
|
7
|
+
export function viewLabel(view) {
|
|
8
|
+
return ownLabels[view] ?? labelOf(view);
|
|
9
|
+
}
|
|
10
|
+
/** The metric a view reads at a commit; the views drawn by hand read none. */
|
|
11
|
+
export function viewMetric(view) {
|
|
12
|
+
return ownViews.has(view) ? null : view;
|
|
13
|
+
}
|
|
14
|
+
const builtinGroups = [
|
|
15
|
+
['Maintainability', ['debt', 'debt-changes', 'duplication', 'cognitive', 'complexity', 'smells']],
|
|
16
|
+
// Branch and function coverage come from the registry, where the coverage report has them.
|
|
17
|
+
['Coverage', ['coverage', 'branch-coverage', 'function-coverage', 'diff-coverage']],
|
|
18
|
+
['Security', ['security']],
|
|
19
|
+
['Size', ['code-lines', 'files', 'functions', 'classes', 'comments']],
|
|
20
|
+
];
|
|
21
|
+
/** A view the registry names, not one the viewer draws by hand. */
|
|
22
|
+
function pluginKey(view) {
|
|
23
|
+
return !ownViews.has(view) && !(view in metricLabels);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The series list: Repometry's own groups, with other plugins' metrics joining a group they name or one of their own.
|
|
27
|
+
* A registry metric the groups already place keeps its place, and is left out where this history has no such metric.
|
|
28
|
+
*/
|
|
29
|
+
export function groups() {
|
|
30
|
+
const placed = new Set(builtinGroups.flatMap(([, views]) => views));
|
|
31
|
+
const trended = pluginMetrics().filter(spec => spec.trend);
|
|
32
|
+
const keys = new Set(trended.map(spec => spec.key));
|
|
33
|
+
const merged = new Map(builtinGroups.map(([group, views]) => [group, views.filter(view => !pluginKey(view) || keys.has(view))]));
|
|
34
|
+
for (const spec of trended.filter(spec => !placed.has(spec.key))) {
|
|
35
|
+
merged.set(spec.group, [...merged.get(spec.group) ?? [], spec.key]);
|
|
36
|
+
}
|
|
37
|
+
return [...merged];
|
|
38
|
+
}
|
|
39
|
+
export function isTrendView(value) {
|
|
40
|
+
if (value === 'debt-changes' || value === 'diff-coverage')
|
|
41
|
+
return true;
|
|
42
|
+
return isMetric(value) && groups().some(([, views]) => views.includes(value));
|
|
43
|
+
}
|
|
44
|
+
export function isPeriod(value) {
|
|
45
|
+
return value === '30' || value === '100' || value === 'all';
|
|
46
|
+
}
|
|
47
|
+
/** A metric's value at a commit, read with the commit's own quality summary and context. */
|
|
48
|
+
export function trendValue(data, report, metric) {
|
|
49
|
+
return metricValue(report, metric, data.quality[report.sha], data.context?.[report.sha]);
|
|
50
|
+
}
|
|
51
|
+
/** Views that have data in this history, in display order; debt changes need remediation times. */
|
|
52
|
+
export function availableViews(data) {
|
|
53
|
+
const has = (metric) => data.reports.some(report => trendValue(data, report, metric) !== null);
|
|
54
|
+
return groups().flatMap(([, views]) => views).filter(view => view === 'diff-coverage' || has(view === 'debt-changes' ? 'effort' : view));
|
|
55
|
+
}
|
|
56
|
+
/** The whole curve by default; only a very long history opens on its last hundred inspections. */
|
|
57
|
+
export function defaultPeriod(total) {
|
|
58
|
+
return total <= 1000 ? 'all' : '100';
|
|
59
|
+
}
|
|
60
|
+
const windows = new Map();
|
|
61
|
+
/** The inspections shown for a period, oldest first, always including the selected one. */
|
|
62
|
+
export function windowOf(reports, selected, period) {
|
|
63
|
+
const limit = period === 'all' ? reports.length : Number(period);
|
|
64
|
+
const { start, end } = stableWindow(reports, reports.indexOf(selected), limit, 'trends');
|
|
65
|
+
return reports.slice(start, end).reverse();
|
|
66
|
+
}
|
|
67
|
+
/** Whether the slice shown last still fits: the same size over the same history, and the commit inside it. */
|
|
68
|
+
function keeps(previous, index, shape) {
|
|
69
|
+
if (!previous || previous.size !== shape.size || previous.total !== shape.total)
|
|
70
|
+
return false;
|
|
71
|
+
return previous.head === shape.head && index >= previous.start && index < previous.end;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The slice of history a chart shows, newest first by index. Picking a commit inside the current slice keeps it, so
|
|
75
|
+
* the axes and scale stay where the eye left them; only a commit outside it moves the slice, which then centres on
|
|
76
|
+
* that commit so its neighbours on both sides are in view. The newest commits are the default slice.
|
|
77
|
+
*/
|
|
78
|
+
export function stableWindow(reports, index, size, key) {
|
|
79
|
+
const shape = { size, total: reports.length, head: reports[0]?.sha };
|
|
80
|
+
const previous = windows.get(key);
|
|
81
|
+
let result;
|
|
82
|
+
if (keeps(previous, index, shape))
|
|
83
|
+
result = { start: previous.start, end: previous.end };
|
|
84
|
+
else if (index < size)
|
|
85
|
+
result = { start: 0, end: Math.min(size, shape.total) };
|
|
86
|
+
else {
|
|
87
|
+
const end = Math.min(shape.total, Math.max(0, index - Math.floor(size / 2)) + size);
|
|
88
|
+
result = { start: Math.max(0, end - size), end };
|
|
89
|
+
}
|
|
90
|
+
windows.set(key, { ...result, ...shape });
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
/** Commit time of an inspection, or null for exports made before commit times were recorded. */
|
|
94
|
+
export function commitTime(report) {
|
|
95
|
+
const time = report.committedAt === undefined ? NaN : Date.parse(report.committedAt);
|
|
96
|
+
return Number.isFinite(time) ? time : null;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The inspections a time chart can place: when the history has commit times, one without (a root commit has no churn
|
|
100
|
+
* window to read it from) cannot be put on the time axis, so it stays out of the chart and in the table.
|
|
101
|
+
*/
|
|
102
|
+
export function charted(shown) {
|
|
103
|
+
const timed = shown.filter(report => commitTime(report) !== null);
|
|
104
|
+
return timed.length ? timed : [...shown];
|
|
105
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
|
|
2
|
+
import type { Period, TrendData, TrendView } from './viewer-trend-data.js';
|
|
3
|
+
/** The series list, and a select with the same series for a narrow screen. */
|
|
4
|
+
export declare function viewNavigation(data: TrendData, views: readonly TrendView[], current: TrendView, selected: PublicHistoryEntry, period: Period): HTMLElement;
|
|
5
|
+
export declare function periodControl(data: TrendData, sha: string, view: TrendView, period: Period): HTMLElement;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { element } from './viewer-dom.js';
|
|
2
|
+
import { coverageGrade, formatMetric } from './viewer-metrics.js';
|
|
3
|
+
import { groups, trendValue, viewLabel, viewMetric } from './viewer-trend-data.js';
|
|
4
|
+
function gradeLabel(text, grade) {
|
|
5
|
+
const label = element('span', 'trend-reading trend-reading-grade', text);
|
|
6
|
+
label.dataset.grade = grade;
|
|
7
|
+
return label;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* What a quality group comes to at the selected commit, as the badges show it: the maintainability grade, and line
|
|
11
|
+
* coverage in its grade's colour, from green at 90% to red below 60%. Other groups carry no total: it would repeat a row.
|
|
12
|
+
*/
|
|
13
|
+
const groupReadings = {
|
|
14
|
+
Maintainability: (data, selected) => {
|
|
15
|
+
const grade = data.quality[selected.sha]?.maintainability?.grade;
|
|
16
|
+
return grade ? gradeLabel(grade, grade) : null;
|
|
17
|
+
},
|
|
18
|
+
Coverage: (data, selected) => {
|
|
19
|
+
const ratio = trendValue(data, selected, 'coverage');
|
|
20
|
+
return ratio === null ? null : gradeLabel(formatMetric(ratio, 'coverage'), coverageGrade(ratio));
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
/** A series in the list, with its value at the selected commit, in the tabs' counter. */
|
|
24
|
+
function seriesLink(data, selected, view, current, period) {
|
|
25
|
+
const item = element('li');
|
|
26
|
+
const link = element('a', '', viewLabel(view));
|
|
27
|
+
link.href = data.link(selected.sha, view, period);
|
|
28
|
+
// The group's own label carries the signal (the grade, the coverage); a row reads like a summary table.
|
|
29
|
+
const metric = viewMetric(view);
|
|
30
|
+
const reading = metric === null ? null : trendValue(data, selected, metric);
|
|
31
|
+
if (metric !== null && reading !== null)
|
|
32
|
+
link.append(element('span', 'trend-value', formatMetric(reading, metric)));
|
|
33
|
+
if (current)
|
|
34
|
+
link.setAttribute('aria-current', 'page');
|
|
35
|
+
item.append(link);
|
|
36
|
+
return item;
|
|
37
|
+
}
|
|
38
|
+
function groupBlock({ data, selected, current, period }, group, present) {
|
|
39
|
+
const block = element('div', 'trend-group');
|
|
40
|
+
const title = element('h3', '', group);
|
|
41
|
+
const reading = groupReadings[group]?.(data, selected);
|
|
42
|
+
if (reading)
|
|
43
|
+
title.append(reading);
|
|
44
|
+
const list = element('ul');
|
|
45
|
+
list.append(...present.map(view => seriesLink(data, selected, view, view === current, period)));
|
|
46
|
+
block.append(title, list);
|
|
47
|
+
return block;
|
|
48
|
+
}
|
|
49
|
+
/** The series list, and a select with the same series for a narrow screen. */
|
|
50
|
+
export function viewNavigation(data, views, current, selected, period) {
|
|
51
|
+
const wrapper = element('aside', 'trend-picker fx-aside');
|
|
52
|
+
const navigation = element('nav', 'trend-nav');
|
|
53
|
+
navigation.setAttribute('aria-label', 'Trend series');
|
|
54
|
+
const select = document.createElement('select');
|
|
55
|
+
for (const [group, members] of groups()) {
|
|
56
|
+
const present = members.filter(view => views.includes(view));
|
|
57
|
+
if (!present.length)
|
|
58
|
+
continue;
|
|
59
|
+
navigation.append(groupBlock({ data, selected, current, period }, group, present));
|
|
60
|
+
const options = document.createElement('optgroup');
|
|
61
|
+
options.label = group;
|
|
62
|
+
options.append(...present.map(view => new Option(viewLabel(view), view, false, view === current)));
|
|
63
|
+
select.append(options);
|
|
64
|
+
}
|
|
65
|
+
select.addEventListener('change', () => { location.hash = data.link(selected.sha, select.value, period); });
|
|
66
|
+
const label = element('label', 'trend-select', 'Series');
|
|
67
|
+
label.append(select);
|
|
68
|
+
wrapper.append(navigation, label);
|
|
69
|
+
return wrapper;
|
|
70
|
+
}
|
|
71
|
+
export function periodControl(data, sha, view, period) {
|
|
72
|
+
// The choices say what they are ("Last 100 inspections"), so the label is for screen readers only.
|
|
73
|
+
const label = element('label', 'trend-period');
|
|
74
|
+
label.append(element('span', 'visually-hidden', 'Period'));
|
|
75
|
+
const select = document.createElement('select');
|
|
76
|
+
const total = data.reports.length;
|
|
77
|
+
for (const option of ['30', '100']) {
|
|
78
|
+
if (Number(option) < total)
|
|
79
|
+
select.append(new Option(`Last ${option} inspections`, option, false, option === period));
|
|
80
|
+
}
|
|
81
|
+
select.append(new Option(`All ${total} inspections`, 'all', false, period === 'all' || Number(period) >= total));
|
|
82
|
+
select.addEventListener('change', () => { location.hash = data.link(sha, view, select.value); });
|
|
83
|
+
label.append(select);
|
|
84
|
+
return label;
|
|
85
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
|
|
2
|
+
import type { ChartPoint } from './viewer-chart.js';
|
|
3
|
+
import type { Metric } from './viewer-metrics.js';
|
|
4
|
+
import type { TrendData } from './viewer-trend-data.js';
|
|
5
|
+
/** The inspection just before this one in the whole history, which the change is measured from. */
|
|
6
|
+
export declare function previousOf(data: TrendData, report: PublicHistoryEntry): PublicHistoryEntry | undefined;
|
|
7
|
+
export declare function seriesPoints(data: TrendData, shown: readonly PublicHistoryEntry[], metric: Metric, selected: string, link: (sha: string) => string): ChartPoint[];
|
|
8
|
+
/**
|
|
9
|
+
* Where the green and the red flag stand: the best and the worst value of the series, each at the inspection that
|
|
10
|
+
* first reached it, the way a flag is planted where a summit was reached. Neutral metrics get no flags, and neither
|
|
11
|
+
* does a series with fewer than three measurements or one that reads as unchanged from its best to its worst.
|
|
12
|
+
*
|
|
13
|
+
* The extremes are the raw minimum and maximum, as the line draws them: a tolerant "beats" is not transitive, and a
|
|
14
|
+
* first value within rounding of both ends used to hide them. A value reaches an extreme when it equals it up to
|
|
15
|
+
* floating-point noise, so a flag never stands beside a point the line shows lower or higher.
|
|
16
|
+
*/
|
|
17
|
+
export declare function plantFlags(values: readonly (number | null)[], metric: Metric): {
|
|
18
|
+
best: number | null;
|
|
19
|
+
worst: number | null;
|
|
20
|
+
};
|
|
21
|
+
/** Only what the chart cannot say by itself; empty when there is nothing to add. */
|
|
22
|
+
export declare function trendLegend(points: readonly ChartPoint[]): string;
|
|
23
|
+
/** Remediation time ticks in whole hours once the series reaches two hours. */
|
|
24
|
+
export declare function tickUnit(values: readonly (number | null)[], metric: Metric): number;
|
|
25
|
+
export declare function signedDuration(minutes: number): string;
|
|
26
|
+
/**
|
|
27
|
+
* Remediation time as changes, one bar per inspection. The first shown inspection compares with the one just before
|
|
28
|
+
* the window, when there is one. Flags mark the best and worst total; the bars show changes, so they carry none.
|
|
29
|
+
*/
|
|
30
|
+
export declare function debtChanges(data: TrendData, shown: readonly PublicHistoryEntry[], selected: string, link: (sha: string) => string): ChartPoint[];
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { betterOf, difference, formatMetric, pluginSpec } from './viewer-metrics.js';
|
|
2
|
+
import { commitTime, trendValue } from './viewer-trend-data.js';
|
|
3
|
+
const dateTime = new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' });
|
|
4
|
+
const shortDate = new Intl.DateTimeFormat(undefined, { month: 'short', day: 'numeric' });
|
|
5
|
+
/** When the commit was made, or else when it was inspected. */
|
|
6
|
+
function whenOf(report) {
|
|
7
|
+
const time = commitTime(report);
|
|
8
|
+
if (time !== null)
|
|
9
|
+
return dateTime.format(time);
|
|
10
|
+
const inspectedAt = Date.parse(report.generatedAt);
|
|
11
|
+
return Number.isFinite(inspectedAt) ? `Inspected ${dateTime.format(inspectedAt)}` : 'Date unavailable';
|
|
12
|
+
}
|
|
13
|
+
function pointNotes(report, boundary) {
|
|
14
|
+
const notes = report.status === 'partial' ? ['Partial inspection'] : [];
|
|
15
|
+
if (boundary)
|
|
16
|
+
notes.push(boundary === 'changed' ? 'Inspection profile changed' : 'Profile comparison unavailable');
|
|
17
|
+
return notes;
|
|
18
|
+
}
|
|
19
|
+
function point(report, reading, selected, link) {
|
|
20
|
+
const { value, shown, change, boundary } = reading;
|
|
21
|
+
const time = commitTime(report);
|
|
22
|
+
const at = time ?? Date.parse(report.generatedAt);
|
|
23
|
+
const when = whenOf(report);
|
|
24
|
+
const moved = change && change.direction !== 'same' ? `, ${change.text}` : '';
|
|
25
|
+
return {
|
|
26
|
+
value, time, boundary,
|
|
27
|
+
label: Number.isFinite(at) ? shortDate.format(at) : report.sha.slice(0, 7),
|
|
28
|
+
title: `${report.sha.slice(0, 7)}, ${when}: ${shown}${moved}`,
|
|
29
|
+
tip: { heading: when, commit: report.sha.slice(0, 7), ...(report.subject ? { subject: report.subject } : {}), value: shown, change,
|
|
30
|
+
notes: pointNotes(report, boundary) },
|
|
31
|
+
href: link(report.sha),
|
|
32
|
+
current: report.sha === selected,
|
|
33
|
+
partial: report.status === 'partial',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** The inspection just before this one in the whole history, which the change is measured from. */
|
|
37
|
+
export function previousOf(data, report) {
|
|
38
|
+
return data.reports[data.reports.indexOf(report) + 1];
|
|
39
|
+
}
|
|
40
|
+
/** A value's change from the inspection before; none across a profile change or a missing measurement. */
|
|
41
|
+
function readingOf(data, report, metric) {
|
|
42
|
+
const value = trendValue(data, report, metric);
|
|
43
|
+
const previous = previousOf(data, report);
|
|
44
|
+
const before = previous ? trendValue(data, previous, metric) : null;
|
|
45
|
+
const boundary = data.context?.[report.sha]?.boundary ?? null;
|
|
46
|
+
const comparable = boundary !== 'changed' && value !== null && before !== null;
|
|
47
|
+
return { value, boundary, shown: value === null ? 'No measurement' : formatMetric(value, metric),
|
|
48
|
+
change: comparable ? difference(value, before, metric) : null };
|
|
49
|
+
}
|
|
50
|
+
export function seriesPoints(data, shown, metric, selected, link) {
|
|
51
|
+
const points = shown.map(report => point(report, readingOf(data, report, metric), selected, link));
|
|
52
|
+
const { best, worst } = plantFlags(points.map(entry => entry.value), metric);
|
|
53
|
+
return points.map((entry, index) => {
|
|
54
|
+
if (index === best)
|
|
55
|
+
return { ...entry, flag: 'best' };
|
|
56
|
+
return index === worst ? { ...entry, flag: 'worst' } : entry;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Where the green and the red flag stand: the best and the worst value of the series, each at the inspection that
|
|
61
|
+
* first reached it, the way a flag is planted where a summit was reached. Neutral metrics get no flags, and neither
|
|
62
|
+
* does a series with fewer than three measurements or one that reads as unchanged from its best to its worst.
|
|
63
|
+
*
|
|
64
|
+
* The extremes are the raw minimum and maximum, as the line draws them: a tolerant "beats" is not transitive, and a
|
|
65
|
+
* first value within rounding of both ends used to hide them. A value reaches an extreme when it equals it up to
|
|
66
|
+
* floating-point noise, so a flag never stands beside a point the line shows lower or higher.
|
|
67
|
+
*/
|
|
68
|
+
export function plantFlags(values, metric) {
|
|
69
|
+
const none = { best: null, worst: null };
|
|
70
|
+
const better = betterOf(metric);
|
|
71
|
+
if (better === 'none')
|
|
72
|
+
return none;
|
|
73
|
+
const measured = values.flatMap((entry, index) => entry === null ? [] : [index]);
|
|
74
|
+
if (measured.length < 3)
|
|
75
|
+
return none;
|
|
76
|
+
const raw = measured.map(index => values[index]);
|
|
77
|
+
const lowest = Math.min(...raw);
|
|
78
|
+
const highest = Math.max(...raw);
|
|
79
|
+
const [bestValue, worstValue] = better === 'lower' ? [lowest, highest] : [highest, lowest];
|
|
80
|
+
if (difference(bestValue, worstValue, metric).direction === 'same')
|
|
81
|
+
return none;
|
|
82
|
+
const reached = (target) => measured.find(index => Math.abs(values[index] - target) <= 1e-9 * Math.max(1, Math.abs(target)));
|
|
83
|
+
const best = reached(bestValue);
|
|
84
|
+
const worst = reached(worstValue);
|
|
85
|
+
return best === worst ? none : { best, worst };
|
|
86
|
+
}
|
|
87
|
+
/** Only what the chart cannot say by itself; empty when there is nothing to add. */
|
|
88
|
+
export function trendLegend(points) {
|
|
89
|
+
const parts = [
|
|
90
|
+
points.some(entry => entry.partial && entry.value !== null) ? 'Dashed dots mark partial inspections' : '',
|
|
91
|
+
points.some(entry => entry.boundary === 'changed') ? 'Dashed lines mark profile changes' : '',
|
|
92
|
+
points.some(entry => entry.boundary === 'unavailable') ? 'Dotted lines mark missing profile information' : '',
|
|
93
|
+
].filter(Boolean);
|
|
94
|
+
return parts.length ? `${parts.join('. ')}.` : '';
|
|
95
|
+
}
|
|
96
|
+
/** Remediation time ticks in whole hours once the series reaches two hours. */
|
|
97
|
+
export function tickUnit(values, metric) {
|
|
98
|
+
const minutes = metric === 'effort' || pluginSpec(metric)?.descriptor.unit === 'minutes';
|
|
99
|
+
return minutes && values.some(value => Math.abs(value ?? 0) >= 120) ? 60 : 1;
|
|
100
|
+
}
|
|
101
|
+
export function signedDuration(minutes) {
|
|
102
|
+
if (Math.round(minutes) === 0)
|
|
103
|
+
return '0 min';
|
|
104
|
+
return `${minutes > 0 ? '+' : '−'}${formatMetric(Math.abs(minutes), 'effort')}`;
|
|
105
|
+
}
|
|
106
|
+
/** Why an inspection has no change to show: it is the first, the profile changed, or the one before was not measured. */
|
|
107
|
+
function noChange(previous, boundary) {
|
|
108
|
+
if (!previous)
|
|
109
|
+
return 'First inspection';
|
|
110
|
+
return boundary === 'changed' ? 'Profile changed' : 'Not measured before';
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Remediation time as changes, one bar per inspection. The first shown inspection compares with the one just before
|
|
114
|
+
* the window, when there is one. Flags mark the best and worst total; the bars show changes, so they carry none.
|
|
115
|
+
*/
|
|
116
|
+
export function debtChanges(data, shown, selected, link) {
|
|
117
|
+
return seriesPoints(data, shown, 'effort', selected, link).map((entry, index) => {
|
|
118
|
+
const report = shown[index];
|
|
119
|
+
const previous = previousOf(data, report);
|
|
120
|
+
const before = previous ? trendValue(data, previous, 'effort') : null;
|
|
121
|
+
const change = entry.boundary !== 'changed' && entry.value !== null && before !== null ? entry.value - before : null;
|
|
122
|
+
const total = entry.value === null ? 'No measurement' : `${formatMetric(entry.value, 'effort')} in total`;
|
|
123
|
+
const shownChange = change === null ? noChange(previous, entry.boundary) : signedDuration(change);
|
|
124
|
+
return { ...entry, value: change, flag: undefined,
|
|
125
|
+
title: `${report.sha.slice(0, 7)}, ${entry.tip.heading}: ${shownChange}`,
|
|
126
|
+
tip: { ...entry.tip, value: shownChange, change: null, notes: [total, ...entry.tip.notes] } };
|
|
127
|
+
});
|
|
128
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
|
|
2
|
+
import type { Metric } from './viewer-metrics.js';
|
|
3
|
+
import type { TrendData } from './viewer-trend-data.js';
|
|
4
|
+
/** The measure drawn beside a series as a grey line on its own scale: the time behind the ratio, the lines behind the share. */
|
|
5
|
+
export declare const companions: Readonly<Partial<Record<Metric, Metric>>>;
|
|
6
|
+
export interface SeriesOptions {
|
|
7
|
+
readonly compact: boolean;
|
|
8
|
+
readonly height?: number | undefined;
|
|
9
|
+
readonly labelCurrent?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** Where a series is drawn and what it draws: the chart and its key, the inspections shown, and the selected commit. */
|
|
12
|
+
export interface SeriesView {
|
|
13
|
+
readonly chart: HTMLElement;
|
|
14
|
+
readonly key: HTMLElement;
|
|
15
|
+
readonly data: TrendData;
|
|
16
|
+
readonly shown: readonly PublicHistoryEntry[];
|
|
17
|
+
readonly metric: Metric;
|
|
18
|
+
readonly selected: string;
|
|
19
|
+
readonly link: (sha: string) => string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A series with its companion, as the Overview draws it: the series in ink on the left scale, the companion in grey on
|
|
23
|
+
* the right, and a key whose entries switch each line on and off. The last line shown cannot be switched off; with one
|
|
24
|
+
* left it takes the left scale. The choice is remembered for this viewer. Returns whether anything was drawn.
|
|
25
|
+
*/
|
|
26
|
+
export declare function renderSeries(view: SeriesView, options: SeriesOptions): boolean;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { renderLineChart } from './viewer-chart.js';
|
|
2
|
+
import { element, store, stored } from './viewer-dom.js';
|
|
3
|
+
import { formatMetric, isPercent, labelOf } from './viewer-metrics.js';
|
|
4
|
+
import { trendValue } from './viewer-trend-data.js';
|
|
5
|
+
import { seriesPoints, tickUnit } from './viewer-trend-points.js';
|
|
6
|
+
/** The measure drawn beside a series as a grey line on its own scale: the time behind the ratio, the lines behind the share. */
|
|
7
|
+
export const companions = { debt: 'effort', coverage: 'uncovered-lines' };
|
|
8
|
+
const hiddenKey = 'repometry.hidden-series';
|
|
9
|
+
let hiddenSeries;
|
|
10
|
+
/** The lines switched off in the key, remembered for this viewer. */
|
|
11
|
+
function hidden() {
|
|
12
|
+
if (hiddenSeries)
|
|
13
|
+
return hiddenSeries;
|
|
14
|
+
try {
|
|
15
|
+
hiddenSeries = new Set(JSON.parse(stored(() => localStorage, hiddenKey) ?? '[]'));
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
hiddenSeries = new Set();
|
|
19
|
+
}
|
|
20
|
+
return hiddenSeries;
|
|
21
|
+
}
|
|
22
|
+
function remember() {
|
|
23
|
+
store(() => localStorage, hiddenKey, JSON.stringify([...hidden()]));
|
|
24
|
+
}
|
|
25
|
+
/** The card under the pointer names the grey series too. */
|
|
26
|
+
function withCompanion(points, second, pair) {
|
|
27
|
+
return points.map((entry, index) => {
|
|
28
|
+
const value = second[index];
|
|
29
|
+
if (value == null)
|
|
30
|
+
return entry;
|
|
31
|
+
return { ...entry, tip: { ...entry.tip, notes: [`${labelOf(pair)}: ${formatMetric(value, pair)}`, ...entry.tip.notes] } };
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** One entry of the key: pressed while its line shows; the one line left stays, since a chart of nothing says nothing. */
|
|
35
|
+
function keyItem(series, kind, on, alone, toggle) {
|
|
36
|
+
const item = document.createElement('button');
|
|
37
|
+
item.type = 'button';
|
|
38
|
+
item.className = `trend-key-item trend-key-${kind}`;
|
|
39
|
+
item.textContent = labelOf(series);
|
|
40
|
+
item.setAttribute('aria-pressed', String(on));
|
|
41
|
+
item.disabled = on && alone;
|
|
42
|
+
item.addEventListener('click', toggle);
|
|
43
|
+
return item;
|
|
44
|
+
}
|
|
45
|
+
function emptySeries(chart) {
|
|
46
|
+
chart.replaceChildren(element('p', 'detail empty', 'No measurements for this series in the shown inspections.'));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A series with its companion, as the Overview draws it: the series in ink on the left scale, the companion in grey on
|
|
50
|
+
* the right, and a key whose entries switch each line on and off. The last line shown cannot be switched off; with one
|
|
51
|
+
* left it takes the left scale. The choice is remembered for this viewer. Returns whether anything was drawn.
|
|
52
|
+
*/
|
|
53
|
+
export function renderSeries(view, options) {
|
|
54
|
+
const { chart, key, data, shown, metric, selected, link } = view;
|
|
55
|
+
const pair = companions[metric];
|
|
56
|
+
const second = pair ? shown.map(report => trendValue(data, report, pair)) : [];
|
|
57
|
+
// A companion earns its line only once it can draw one, that is, from two measurements on.
|
|
58
|
+
const paired = pair !== undefined && second.filter(item => item !== null).length >= 2;
|
|
59
|
+
const main = seriesPoints(data, shown, metric, selected, link);
|
|
60
|
+
const hasData = main.some(entry => entry.value !== null) || (paired && second.some(item => item !== null));
|
|
61
|
+
function draw() {
|
|
62
|
+
const showMain = !paired || !hidden().has(metric);
|
|
63
|
+
const showSecond = paired && !hidden().has(pair);
|
|
64
|
+
const both = showMain && showSecond;
|
|
65
|
+
const lead = showMain ? metric : pair;
|
|
66
|
+
const base = showMain ? main : seriesPoints(data, shown, pair, selected, link);
|
|
67
|
+
const points = both ? withCompanion(base, second, pair) : base;
|
|
68
|
+
chart.classList.toggle('chart-companion-only', !showMain);
|
|
69
|
+
if (points.some(entry => entry.value !== null)) {
|
|
70
|
+
renderLineChart(chart, points, { format: number => formatMetric(number, lead), ratio: isPercent(lead), compact: options.compact,
|
|
71
|
+
height: options.height, tickUnit: tickUnit(points.map(entry => entry.value), lead), labelCurrent: options.labelCurrent ?? true,
|
|
72
|
+
secondary: both ? { values: second, format: number => formatMetric(number, pair), tickUnit: tickUnit(second, pair) } : undefined });
|
|
73
|
+
}
|
|
74
|
+
else
|
|
75
|
+
emptySeries(chart);
|
|
76
|
+
key.hidden = !paired;
|
|
77
|
+
if (!paired) {
|
|
78
|
+
key.replaceChildren();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
key.replaceChildren(...[[metric, 'main', showMain], [pair, 'second', showSecond]].map(([series, kind, on]) => keyItem(series, kind, on, !both, () => {
|
|
82
|
+
if (on)
|
|
83
|
+
hidden().add(series);
|
|
84
|
+
else
|
|
85
|
+
hidden().delete(series);
|
|
86
|
+
remember();
|
|
87
|
+
draw();
|
|
88
|
+
key.querySelector(`.trend-key-${kind}`)?.focus();
|
|
89
|
+
})));
|
|
90
|
+
}
|
|
91
|
+
if (hasData)
|
|
92
|
+
draw();
|
|
93
|
+
else {
|
|
94
|
+
chart.replaceChildren();
|
|
95
|
+
key.hidden = true;
|
|
96
|
+
}
|
|
97
|
+
return hasData;
|
|
98
|
+
}
|