repometry 0.4.2 → 0.6.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 +36 -14
- package/package.json +1 -1
- package/target/main/resources/report/json/comparison-v1.schema.json +6 -6
- package/target/main/resources/report/json/file-metrics-v1.schema.json +7 -6
- package/target/main/resources/report/json/pull-review-v1.schema.json +5 -5
- package/target/main/resources/report/json/report-v2.schema.json +210 -11
- package/target/main/resources/report/json/repository-summary-v1.schema.json +161 -14
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +518 -6
- package/target/main/resources/viewer/styles.css +7 -2
- package/target/main/ts/api/git/changes.d.ts +1 -1
- package/target/main/ts/api/git/changes.js +3 -3
- package/target/main/ts/api/git/commit-metadata.js +6 -4
- package/target/main/ts/api/git/git.d.ts +2 -1
- package/target/main/ts/api/git/git.js +16 -4
- package/target/main/ts/api/git/inspection-source.d.ts +1 -1
- package/target/main/ts/api/git/inspection-source.js +4 -10
- package/target/main/ts/api/git/local.d.ts +1 -1
- package/target/main/ts/api/git/local.js +41 -7
- 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/api/worker/remote-executor.d.ts +1 -1
- package/target/main/ts/api/worker/remote-executor.js +2 -2
- package/target/main/ts/api/worker/worker-protocol.d.ts +2 -2
- package/target/main/ts/api/worker/worker-protocol.js +8 -8
- package/target/main/ts/api/worker/worker.d.ts +1 -1
- package/target/main/ts/api/worker/worker.js +4 -4
- package/target/main/ts/cli/main.js +4 -3
- package/target/main/ts/cli/reporting.d.ts +1 -1
- package/target/main/ts/cli/reporting.js +1 -1
- package/target/main/ts/compose/analysis-files.d.ts +13 -0
- package/target/main/ts/compose/analysis-files.js +95 -0
- package/target/main/ts/compose/analysis-imports.d.ts +7 -0
- package/target/main/ts/compose/analysis-imports.js +34 -0
- package/target/main/ts/compose/analysis-report.d.ts +5 -0
- package/target/main/ts/compose/analysis-report.js +78 -0
- package/target/main/ts/compose/analysis-repository.d.ts +6 -0
- package/target/main/ts/compose/analysis-repository.js +61 -0
- package/target/main/ts/compose/analysis-results.d.ts +38 -0
- package/target/main/ts/compose/analysis-results.js +78 -0
- package/target/main/ts/compose/analysis-sources.d.ts +73 -0
- package/target/main/ts/compose/analysis-sources.js +47 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +3 -2
- package/target/main/ts/compose/analyze-snapshot.js +19 -197
- package/target/main/ts/compose/diff-coverage.d.ts +2 -0
- package/target/main/ts/compose/diff-coverage.js +6 -4
- package/target/main/ts/compose/inspect.d.ts +5 -0
- package/target/main/ts/compose/inspect.js +14 -7
- package/target/main/ts/compose/languages.d.ts +29 -0
- package/target/main/ts/compose/languages.js +87 -0
- package/target/main/ts/compose/sources.js +14 -12
- 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/manifest.d.ts +2 -2
- package/target/main/ts/core/engine/manifest.js +25 -5
- 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 +3 -4
- package/target/main/ts/core/engine/plan.js +28 -11
- package/target/main/ts/core/engine/plugin.d.ts +10 -2
- 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.d.ts +1 -0
- package/target/main/ts/core/model/clone-source.js +2 -1
- package/target/main/ts/core/model/code-structure.d.ts +5 -0
- package/target/main/ts/core/model/code-structure.js +10 -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/language.d.ts +10 -0
- package/target/main/ts/core/model/language.js +6 -0
- 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.d.ts +7 -6
- package/target/main/ts/core/model/measurement.js +18 -7
- package/target/main/ts/core/model/plugin-data.d.ts +5 -0
- package/target/main/ts/core/model/plugin-data.js +15 -1
- package/target/main/ts/core/model/quality-summary.js +6 -5
- package/target/main/ts/core/model/report.d.ts +1 -2
- package/target/main/ts/core/model/report.js +0 -1
- package/target/main/ts/core/model/scanner-import.js +1 -1
- package/target/main/ts/core/model/snapshot.d.ts +1 -2
- package/target/main/ts/core/model/snapshot.js +5 -7
- 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/core/usecases/compare.js +61 -17
- package/target/main/ts/core/usecases/inspect.js +2 -2
- package/target/main/ts/plugin.d.ts +10 -3
- package/target/main/ts/plugin.js +4 -2
- 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/duplication/duplication.js +10 -4
- package/target/main/ts/plugins/language-js/babel-provider.js +8 -2
- package/target/main/ts/plugins/language-js/extensions.d.ts +3 -0
- package/target/main/ts/plugins/language-js/extensions.js +4 -0
- 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/plugins/language-js/js-security.js +3 -2
- 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-data.d.ts +1 -1
- package/target/main/ts/report/html/app/viewer-data.js +2 -29
- 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 +7 -84
- 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 +118 -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 +54 -0
- package/target/main/ts/report/html/app/viewer-trend-data.js +109 -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/html/site/export-site.d.ts +3 -4
- package/target/main/ts/report/html/site/export-site.js +24 -41
- package/target/main/ts/report/html/site/exported-server.js +2 -1
- package/target/main/ts/report/html/site/local-server.d.ts +1 -1
- package/target/main/ts/report/html/site/local-server.js +13 -19
- package/target/main/ts/report/html/site/projects.js +8 -17
- package/target/main/ts/report/json/projections/commit-summary.d.ts +2 -2
- package/target/main/ts/report/json/projections/commit-summary.js +18 -19
- package/target/main/ts/report/json/projections/file-metrics.js +31 -24
- package/target/main/ts/report/json/projections/inspection-context.js +10 -1
- package/target/main/ts/report/json/projections/inspection-details.d.ts +1 -1
- package/target/main/ts/report/json/projections/inspection-details.js +2 -2
- package/target/main/ts/report/json/projections/metric-values.d.ts +1 -0
- package/target/main/ts/report/json/projections/metric-values.js +15 -5
- 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/pull-review-store.js +1 -2
- 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/json/validation/report.d.ts +1 -1
- package/target/main/ts/report/json/validation/report.js +10 -8
- package/target/main/ts/report/json/validation/summary-validation.js +1 -3
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +2 -0
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +0 -5
- package/target/main/ts/report/json/wire/public-history-model.d.ts +0 -6
- package/target/main/ts/report/json/wire/public-history-model.js +0 -1
- package/target/main/ts/report.d.ts +3 -3
- package/target/main/ts/report.js +2 -2
- package/target/main/resources/report/json/inspection-context-v1.schema.json +0 -172
- package/target/main/resources/report/json/public-history-v1.schema.json +0 -50
- package/target/main/resources/report/json/quality-history-v1.schema.json +0 -51
- package/target/main/resources/report/json/report-v1.schema.json +0 -65
- package/target/main/resources/report/json/viewer-details-v1.schema.json +0 -346
- package/target/main/ts/report/json/projections/public-history.d.ts +0 -4
- package/target/main/ts/report/json/projections/public-history.js +0 -17
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { element } from './viewer-dom.js';
|
|
2
|
+
import { bandLabels as pluginBandLabels, bandOf, bandScale } from './viewer-metric-format.js';
|
|
3
|
+
import { labelOf, pluginSpec } from './viewer-metrics.js';
|
|
4
|
+
import { ancestors } from './viewer-totals.js';
|
|
5
|
+
const bandMeaning = {
|
|
6
|
+
complexity: 'Colour shows the most complex function.',
|
|
7
|
+
cognitive: 'Colour shows cognitive complexity relative to the highest file, or folder at the same depth.',
|
|
8
|
+
missedLines: 'Colour shows the share of uncovered lines.',
|
|
9
|
+
duplication: 'Colour shows the share of duplicated code lines.',
|
|
10
|
+
churn: 'Colour shows Git changes relative to the busiest file, or folder at the same depth.',
|
|
11
|
+
};
|
|
12
|
+
/** The band limits used when the profile sets none. */
|
|
13
|
+
const defaultLimits = { complexity: [5, 10, 20, 50], missedLines: [.05, .15, .3, .5], duplication: [.03, .1, .25] };
|
|
14
|
+
const scaled = (metric) => metric in defaultLimits;
|
|
15
|
+
const rankTitles = {
|
|
16
|
+
complexity: labelOf('complexity'),
|
|
17
|
+
cognitive: labelOf('cognitive'),
|
|
18
|
+
missedLines: 'Uncovered lines',
|
|
19
|
+
duplication: 'Duplicated lines',
|
|
20
|
+
churn: 'Git changes',
|
|
21
|
+
};
|
|
22
|
+
/** What a metric is called where files are ranked by it. */
|
|
23
|
+
export function rankTitle(metric) {
|
|
24
|
+
return pluginSpec(metric)?.label ?? rankTitles[metric];
|
|
25
|
+
}
|
|
26
|
+
export function scoreLabel(metric) {
|
|
27
|
+
return rankTitle(metric).toLowerCase();
|
|
28
|
+
}
|
|
29
|
+
function ascending(values) {
|
|
30
|
+
return values.every((value, index) => Number.isFinite(value) && (index === 0 || value > values[index - 1]));
|
|
31
|
+
}
|
|
32
|
+
/** The profile's limits for a metric with a meaningful scale, when they are well formed; otherwise the defaults. */
|
|
33
|
+
export function bandLimits(details, metric) {
|
|
34
|
+
if (!scaled(metric))
|
|
35
|
+
return undefined;
|
|
36
|
+
const given = details.bands?.[metric];
|
|
37
|
+
return given?.length === defaultLimits[metric].length && ascending(given) ? given : defaultLimits[metric];
|
|
38
|
+
}
|
|
39
|
+
/** The legend's words for the bands, written from the limits: 1–5, 6–10 … 51+, or <5%, 5–15% … 50%+. */
|
|
40
|
+
function bandLabels(metric, limits) {
|
|
41
|
+
const percent = (value) => `${+(value * 100).toFixed(1)}%`;
|
|
42
|
+
if (metric === 'complexity') {
|
|
43
|
+
return [...limits.map((limit, index) => `${index === 0 ? 1 : limits[index - 1] + 1}–${limit}`), `${limits.at(-1) + 1}+`];
|
|
44
|
+
}
|
|
45
|
+
const ranges = [...limits.map((limit, index) => index === 0 ? `<${percent(limit)}`
|
|
46
|
+
: `${percent(limits[index - 1]).replace('%', '')}–${percent(limit)}`), `${percent(limits.at(-1))}+`];
|
|
47
|
+
return metric === 'duplication' ? ['0%', ...ranges] : ranges;
|
|
48
|
+
}
|
|
49
|
+
/** What the map's colour shows, said to assistive technology. */
|
|
50
|
+
export function meaningOf(metric) {
|
|
51
|
+
const plugin = pluginSpec(metric);
|
|
52
|
+
if (!plugin)
|
|
53
|
+
return bandMeaning[metric];
|
|
54
|
+
return `Colour shows ${plugin.label.toLowerCase()}${plugin.descriptor.bands ? '' : ' relative to the highest file, or folder at the same depth'}.`;
|
|
55
|
+
}
|
|
56
|
+
function step(value, bounds) {
|
|
57
|
+
const index = bounds.findIndex(limit => value <= limit);
|
|
58
|
+
return index < 0 ? bounds.length : index;
|
|
59
|
+
}
|
|
60
|
+
/** The share of a count the score is, or none where the file counts nothing. */
|
|
61
|
+
function share(score, whole) {
|
|
62
|
+
return whole && whole > 0 ? score / whole : null;
|
|
63
|
+
}
|
|
64
|
+
const scales = {
|
|
65
|
+
complexity: (_, score, limits) => step(score, limits),
|
|
66
|
+
missedLines: (entry, score, limits) => {
|
|
67
|
+
const ratio = share(score, entry.lineCoverage?.total);
|
|
68
|
+
return ratio === null ? 0 : step(ratio, limits);
|
|
69
|
+
},
|
|
70
|
+
duplication: (entry, score, limits) => {
|
|
71
|
+
const ratio = share(score, entry.quality?.codeLines);
|
|
72
|
+
return score === 0 || ratio === null ? 0 : 1 + step(ratio, limits);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
/** Maps a score to one of five colour bands: by the profile's limits where the metric has a meaningful scale. */
|
|
76
|
+
export function band(entry, metric, score, highest, limits = scaled(metric) ? defaultLimits[metric] : undefined) {
|
|
77
|
+
const plugin = pluginSpec(metric);
|
|
78
|
+
if (plugin)
|
|
79
|
+
return bandOf(plugin, score, highest);
|
|
80
|
+
const scale = scales[metric];
|
|
81
|
+
return scale ? scale(entry, score, limits) : Math.min(4, Math.floor(score / highest * 5));
|
|
82
|
+
}
|
|
83
|
+
/** Each file's worst level spread to the folders above it. */
|
|
84
|
+
export function spreadLevels(files) {
|
|
85
|
+
const spread = new Map(files);
|
|
86
|
+
for (const [path, level] of files)
|
|
87
|
+
for (const folder of ancestors(path))
|
|
88
|
+
spread.set(folder, Math.max(level, spread.get(folder) ?? 0));
|
|
89
|
+
return spread;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The top of a relative colour scale, per level: files against files, folders against the folders at their depth. One
|
|
93
|
+
* scale for both would let a folder's sum outshine every file in it, and the map would read hot folders over pale files.
|
|
94
|
+
*/
|
|
95
|
+
export function relativePeaks(entries) {
|
|
96
|
+
const level = (path, folder) => folder ? `folder:${path.split('/').length}` : 'file';
|
|
97
|
+
const peaks = new Map();
|
|
98
|
+
for (const { path, folder, score } of entries)
|
|
99
|
+
peaks.set(level(path, folder), Math.max(peaks.get(level(path, folder)) ?? 1, score));
|
|
100
|
+
return (path, folder) => peaks.get(level(path, folder)) ?? 1;
|
|
101
|
+
}
|
|
102
|
+
function swatches() {
|
|
103
|
+
const bar = element('span', 'fx-scale-bar');
|
|
104
|
+
bar.setAttribute('aria-hidden', 'true');
|
|
105
|
+
for (let index = 0; index < 5; index++) {
|
|
106
|
+
const swatch = element('span');
|
|
107
|
+
swatch.dataset.band = String(index);
|
|
108
|
+
bar.append(swatch);
|
|
109
|
+
}
|
|
110
|
+
return bar;
|
|
111
|
+
}
|
|
112
|
+
/** Each word stands under its band. */
|
|
113
|
+
function labelledScale(legend, labels) {
|
|
114
|
+
legend.classList.add('fx-scale-labelled');
|
|
115
|
+
const words = element('span', 'fx-scale-words');
|
|
116
|
+
words.append(...labels.map(label => element('span', '', label)));
|
|
117
|
+
legend.append(swatches(), words);
|
|
118
|
+
return legend;
|
|
119
|
+
}
|
|
120
|
+
export function levelLegend() {
|
|
121
|
+
const legend = element('p', 'fx-scale fx-note');
|
|
122
|
+
legend.dataset.palette = 'grade';
|
|
123
|
+
return labelledScale(legend, ['None', 'Low', 'Medium', 'High', 'Critical']);
|
|
124
|
+
}
|
|
125
|
+
function legendLabels(metric, limits) {
|
|
126
|
+
const plugin = pluginSpec(metric);
|
|
127
|
+
if (plugin)
|
|
128
|
+
return pluginBandLabels(plugin) ?? undefined;
|
|
129
|
+
return scaled(metric) && limits ? bandLabels(metric, limits) : undefined;
|
|
130
|
+
}
|
|
131
|
+
export function sunburstLegend(metric, limits) {
|
|
132
|
+
const legend = element('p', 'fx-scale fx-note');
|
|
133
|
+
const labels = legendLabels(metric, limits);
|
|
134
|
+
if (labels)
|
|
135
|
+
return labelledScale(legend, labels);
|
|
136
|
+
legend.append(element('span', '', 'Lower'), swatches(), element('span', '', 'Higher'));
|
|
137
|
+
return legend;
|
|
138
|
+
}
|
|
139
|
+
/** The map's colours: grade steps for security, grey for nothing measured, heat where higher is worse, else neutral. */
|
|
140
|
+
export function palette(metric, levels, grey) {
|
|
141
|
+
if (levels)
|
|
142
|
+
return 'grade';
|
|
143
|
+
if (grey)
|
|
144
|
+
return 'none';
|
|
145
|
+
const plugin = pluginSpec(metric);
|
|
146
|
+
return (plugin ? bandScale(plugin) === 'heat' : metric !== 'churn') ? 'heat' : 'neutral';
|
|
147
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Metrics } from './viewer-inspection.js';
|
|
2
|
+
/** Rings (a sunburst) or tiles (a treemap); the last choice is remembered for this viewer. */
|
|
3
|
+
export type MapShape = 'rings' | 'tiles';
|
|
4
|
+
/** A file or folder on the map: its area, and the score its colour is read from. */
|
|
5
|
+
export interface Branch {
|
|
6
|
+
readonly entry: Metrics;
|
|
7
|
+
readonly folder: boolean;
|
|
8
|
+
readonly area: number;
|
|
9
|
+
readonly score: number;
|
|
10
|
+
}
|
|
11
|
+
/** What the ring and tile layouts draw with. */
|
|
12
|
+
export interface MapDraw {
|
|
13
|
+
/** The map's tree: each folder's children, by path. */
|
|
14
|
+
readonly byParent: ReadonlyMap<string, readonly Branch[]>;
|
|
15
|
+
/** How many levels the map shows below its root. */
|
|
16
|
+
readonly depth: number;
|
|
17
|
+
/** How many wedges or tiles are drawn so far. */
|
|
18
|
+
readonly drawn: number;
|
|
19
|
+
shade(branch: Branch): number | 'none';
|
|
20
|
+
/** Draws a branch by its outline, shaded, linked and wired to the readout. */
|
|
21
|
+
tile(branch: Branch, outline: string): SVGAElement;
|
|
22
|
+
}
|
|
23
|
+
export declare const chartCenter = 200;
|
|
24
|
+
export declare const innerRadius = 47;
|
|
25
|
+
export declare const outerRadius = 196;
|
|
26
|
+
export declare const fullCircle: number;
|
|
27
|
+
export declare const startAngle: number;
|
|
28
|
+
export declare function mapShape(): MapShape;
|
|
29
|
+
/** The switch between the two shapes, remembering the choice before the map redraws. */
|
|
30
|
+
export declare function shapeSwitch(shape: MapShape, change: (shape: MapShape) => void): HTMLElement;
|
|
31
|
+
/**
|
|
32
|
+
* The compact map's stand-in while the inspection loads: the same frame, switch and canvas size in a flat tone, so the
|
|
33
|
+
* column keeps its shape and the map fades in where it will stand.
|
|
34
|
+
*/
|
|
35
|
+
export declare function mapStub(): HTMLElement;
|
|
36
|
+
/** A ring sector between two angles; the whole circle is drawn as two halves, since one arc cannot close on itself. */
|
|
37
|
+
export declare function sectorPath(inner: number, outer: number, first: number, last: number): string;
|
|
38
|
+
/**
|
|
39
|
+
* The readout under the map, filled on hover or focus: values appear only there, so the map does not repeat the
|
|
40
|
+
* ranking beside it. The pointed place keeps its colour together with its parents and its contents; the rest fades.
|
|
41
|
+
*/
|
|
42
|
+
export declare function readout(canvas: SVGSVGElement, summary: HTMLElement, words: (branch: Branch) => string): (branch: Branch, tile: SVGAElement) => void;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { segmented } from './viewer-controls.js';
|
|
2
|
+
import { element, store, stored, svgElement } from './viewer-dom.js';
|
|
3
|
+
export const chartCenter = 200;
|
|
4
|
+
export const innerRadius = 47;
|
|
5
|
+
export const outerRadius = 196;
|
|
6
|
+
export const fullCircle = 2 * Math.PI;
|
|
7
|
+
export const startAngle = -Math.PI / 2;
|
|
8
|
+
const shapeKey = 'repometry.map';
|
|
9
|
+
export function mapShape() {
|
|
10
|
+
return stored(() => localStorage, shapeKey) === 'tiles' ? 'tiles' : 'rings';
|
|
11
|
+
}
|
|
12
|
+
/** The switch between the two shapes, remembering the choice before the map redraws. */
|
|
13
|
+
export function shapeSwitch(shape, change) {
|
|
14
|
+
return segmented('Map shape', [['rings', 'Sunburst'], ['tiles', 'Treemap']], shape, value => {
|
|
15
|
+
store(() => localStorage, shapeKey, value);
|
|
16
|
+
change(value);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function stubCanvas(shape) {
|
|
20
|
+
const canvas = svgElement('svg');
|
|
21
|
+
canvas.classList.add('fx-sunburst-chart');
|
|
22
|
+
canvas.setAttribute('aria-hidden', 'true');
|
|
23
|
+
if (shape === 'tiles') {
|
|
24
|
+
canvas.classList.add('fx-treemap');
|
|
25
|
+
canvas.setAttribute('viewBox', '0 0 400 320');
|
|
26
|
+
const tile = svgElement('rect');
|
|
27
|
+
tile.setAttribute('width', '400');
|
|
28
|
+
tile.setAttribute('height', '320');
|
|
29
|
+
tile.setAttribute('rx', '3');
|
|
30
|
+
canvas.append(tile);
|
|
31
|
+
return canvas;
|
|
32
|
+
}
|
|
33
|
+
canvas.setAttribute('viewBox', '0 0 400 400');
|
|
34
|
+
const ring = svgElement('circle');
|
|
35
|
+
ring.setAttribute('cx', '200');
|
|
36
|
+
ring.setAttribute('cy', '200');
|
|
37
|
+
ring.setAttribute('r', String((outerRadius + innerRadius) / 2));
|
|
38
|
+
ring.setAttribute('stroke-width', String(outerRadius - innerRadius));
|
|
39
|
+
canvas.append(ring);
|
|
40
|
+
return canvas;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The compact map's stand-in while the inspection loads: the same frame, switch and canvas size in a flat tone, so the
|
|
44
|
+
* column keeps its shape and the map fades in where it will stand.
|
|
45
|
+
*/
|
|
46
|
+
export function mapStub() {
|
|
47
|
+
const shape = mapShape();
|
|
48
|
+
const panel = element('section', 'fx-sunburst fx-sunburst-compact fx-map-stub');
|
|
49
|
+
panel.dataset.shape = shape;
|
|
50
|
+
panel.setAttribute('aria-busy', 'true');
|
|
51
|
+
const heading = element('div', 'fx-map-heading');
|
|
52
|
+
heading.append(shapeSwitch(shape, () => panel.replaceWith(mapStub())));
|
|
53
|
+
panel.append(heading, stubCanvas(shape), element('p', 'fx-map-summary fx-map-hint fx-map-hint-quiet'));
|
|
54
|
+
return panel;
|
|
55
|
+
}
|
|
56
|
+
/** A ring sector between two angles; the whole circle is drawn as two halves, since one arc cannot close on itself. */
|
|
57
|
+
export function sectorPath(inner, outer, first, last) {
|
|
58
|
+
const large = last - first > Math.PI ? 1 : 0;
|
|
59
|
+
const radius = (r, angle) => `${(chartCenter + r * Math.cos(angle)).toFixed(3)},${(chartCenter + r * Math.sin(angle)).toFixed(3)}`;
|
|
60
|
+
if (last - first >= fullCircle - 0.00001) {
|
|
61
|
+
const middle = first + Math.PI;
|
|
62
|
+
return `M${radius(outer, first)} A${outer},${outer} 0 1 1 ${radius(outer, middle)} A${outer},${outer} 0 1 1 ${radius(outer, first)}
|
|
63
|
+
M${radius(inner, first)} A${inner},${inner} 0 1 0 ${radius(inner, middle)} A${inner},${inner} 0 1 0 ${radius(inner, first)} Z`;
|
|
64
|
+
}
|
|
65
|
+
return `M${radius(outer, first)} A${outer},${outer} 0 ${large} 1 ${radius(outer, last)}
|
|
66
|
+
L${radius(inner, last)} A${inner},${inner} 0 ${large} 0 ${radius(inner, first)} Z`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The readout under the map, filled on hover or focus: values appear only there, so the map does not repeat the
|
|
70
|
+
* ranking beside it. The pointed place keeps its colour together with its parents and its contents; the rest fades.
|
|
71
|
+
*/
|
|
72
|
+
export function readout(canvas, summary, words) {
|
|
73
|
+
// One outline drawn above every wedge, so neighbours never paint over it.
|
|
74
|
+
const outline = svgElement('path');
|
|
75
|
+
outline.classList.add('fx-wedge-outline');
|
|
76
|
+
outline.setAttribute('aria-hidden', 'true');
|
|
77
|
+
const reset = () => {
|
|
78
|
+
canvas.removeAttribute('data-inspecting');
|
|
79
|
+
for (const wedge of canvas.querySelectorAll('.fx-wedge[data-related]'))
|
|
80
|
+
wedge.removeAttribute('data-related');
|
|
81
|
+
outline.remove();
|
|
82
|
+
summary.classList.add('fx-map-hint');
|
|
83
|
+
summary.textContent = '';
|
|
84
|
+
};
|
|
85
|
+
canvas.addEventListener('pointerleave', reset);
|
|
86
|
+
canvas.addEventListener('focusout', event => {
|
|
87
|
+
if (!canvas.contains(event.relatedTarget))
|
|
88
|
+
reset();
|
|
89
|
+
});
|
|
90
|
+
return (branch, tile) => {
|
|
91
|
+
const own = branch.entry.path;
|
|
92
|
+
canvas.setAttribute('data-inspecting', '');
|
|
93
|
+
for (const wedge of canvas.querySelectorAll('.fx-wedge')) {
|
|
94
|
+
const other = wedge.dataset.path;
|
|
95
|
+
wedge.toggleAttribute('data-related', other === own || own.startsWith(`${other}/`) || other.startsWith(`${own}/`));
|
|
96
|
+
}
|
|
97
|
+
outline.setAttribute('d', tile.querySelector('path').getAttribute('d'));
|
|
98
|
+
canvas.append(outline);
|
|
99
|
+
summary.classList.remove('fx-map-hint');
|
|
100
|
+
summary.replaceChildren(element('code', 'fx-path', own), element('strong', '', words(branch)));
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Direction, MetricSpec } from './viewer-metric-registry.js';
|
|
2
|
+
/** Remediation time in hours and minutes: 45 min, 2 h, 3 h 20 min. */
|
|
3
|
+
export declare function duration(minutes: number): string;
|
|
4
|
+
export declare function format(spec: MetricSpec, value: number | null): string;
|
|
5
|
+
/** The signed change between two values: percentage points for a ratio, coloured only where the metric has a better. */
|
|
6
|
+
export declare function difference(spec: MetricSpec, value: number, before: number): {
|
|
7
|
+
text: string;
|
|
8
|
+
direction: Direction;
|
|
9
|
+
};
|
|
10
|
+
/** The first click on a column sorts worst first. */
|
|
11
|
+
export declare function firstSortAscending(spec: MetricSpec): boolean;
|
|
12
|
+
/** Missing values sort last in both directions. */
|
|
13
|
+
export declare function compareValues(ascending: boolean): (a: number | null, b: number | null) => number;
|
|
14
|
+
/** The colour scale: heat where the metric has a better, so the worst is always red; neutral greys where it has none. */
|
|
15
|
+
export declare function bandScale(spec: MetricSpec): 'heat' | 'neutral';
|
|
16
|
+
/**
|
|
17
|
+
* One of five bands, 0 best to 4 worst. Fixed by the descriptor's limits where it has them; otherwise relative to the
|
|
18
|
+
* highest value shown. A metric where higher is better turns the scale round. A limit belongs to the better side: at
|
|
19
|
+
* most 5 is the best complexity band, 90% is already the best coverage band.
|
|
20
|
+
*/
|
|
21
|
+
export declare function bandOf(spec: MetricSpec, value: number, highest: number): number;
|
|
22
|
+
/** The legend's words, best band first; null where the bands are relative and the legend reads Lower … Higher. */
|
|
23
|
+
export declare function bandLabels(spec: MetricSpec): string[] | null;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const integers = new Intl.NumberFormat();
|
|
2
|
+
const percent = new Intl.NumberFormat(undefined, { style: 'percent', maximumFractionDigits: 1 });
|
|
3
|
+
const decimal = new Intl.NumberFormat(undefined, { maximumFractionDigits: 1 });
|
|
4
|
+
/** Remediation time in hours and minutes: 45 min, 2 h, 3 h 20 min. */
|
|
5
|
+
export function duration(minutes) {
|
|
6
|
+
const rounded = Math.round(minutes);
|
|
7
|
+
if (rounded < 60)
|
|
8
|
+
return `${integers.format(rounded)} min`;
|
|
9
|
+
const hours = Math.floor(rounded / 60);
|
|
10
|
+
const rest = rounded % 60;
|
|
11
|
+
return rest ? `${integers.format(hours)} h ${integers.format(rest)} min` : `${integers.format(hours)} h`;
|
|
12
|
+
}
|
|
13
|
+
const writers = {
|
|
14
|
+
ratio: value => percent.format(value),
|
|
15
|
+
minutes: duration,
|
|
16
|
+
count: value => integers.format(value),
|
|
17
|
+
};
|
|
18
|
+
export function format(spec, value) {
|
|
19
|
+
return value === null ? '—' : writers[spec.descriptor.unit](value);
|
|
20
|
+
}
|
|
21
|
+
/** How large a change is: percentage points for a ratio, time for minutes, a count otherwise. */
|
|
22
|
+
const magnitudes = {
|
|
23
|
+
ratio: size => `${decimal.format(size)} pp`,
|
|
24
|
+
minutes: duration,
|
|
25
|
+
count: size => integers.format(size),
|
|
26
|
+
};
|
|
27
|
+
/** The signed change between two values: percentage points for a ratio, coloured only where the metric has a better. */
|
|
28
|
+
export function difference(spec, value, before) {
|
|
29
|
+
const { unit, better } = spec.descriptor;
|
|
30
|
+
const raw = unit === 'ratio' ? (value - before) * 100 : value - before;
|
|
31
|
+
const rounded = unit === 'ratio' ? Math.round(raw * 10) / 10 : Math.round(raw);
|
|
32
|
+
if (rounded === 0)
|
|
33
|
+
return { text: 'No change', direction: 'same' };
|
|
34
|
+
const improved = (better === 'lower') === (rounded < 0);
|
|
35
|
+
const direction = better === 'none' ? 'neutral' : improved ? 'better' : 'worse';
|
|
36
|
+
return { text: `${rounded > 0 ? '+' : '−'}${magnitudes[unit](Math.abs(rounded))}`, direction };
|
|
37
|
+
}
|
|
38
|
+
/** The first click on a column sorts worst first. */
|
|
39
|
+
export function firstSortAscending(spec) {
|
|
40
|
+
return spec.descriptor.better === 'higher';
|
|
41
|
+
}
|
|
42
|
+
/** Missing values sort last in both directions. */
|
|
43
|
+
export function compareValues(ascending) {
|
|
44
|
+
return (a, b) => {
|
|
45
|
+
if (a === null || b === null)
|
|
46
|
+
return Number(a === null) - Number(b === null);
|
|
47
|
+
return ascending ? a - b : b - a;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** The colour scale: heat where the metric has a better, so the worst is always red; neutral greys where it has none. */
|
|
51
|
+
export function bandScale(spec) {
|
|
52
|
+
return spec.descriptor.better === 'none' ? 'neutral' : 'heat';
|
|
53
|
+
}
|
|
54
|
+
/** The band of a value against fixed limits; a limit belongs to the better side. */
|
|
55
|
+
function fixedStep(limits, value, higher) {
|
|
56
|
+
const index = limits.findIndex(limit => higher ? value < limit : value <= limit);
|
|
57
|
+
return index < 0 ? limits.length : index;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* One of five bands, 0 best to 4 worst. Fixed by the descriptor's limits where it has them; otherwise relative to the
|
|
61
|
+
* highest value shown. A metric where higher is better turns the scale round. A limit belongs to the better side: at
|
|
62
|
+
* most 5 is the best complexity band, 90% is already the best coverage band.
|
|
63
|
+
*/
|
|
64
|
+
export function bandOf(spec, value, highest) {
|
|
65
|
+
const limits = spec.descriptor.bands;
|
|
66
|
+
const higher = spec.descriptor.better === 'higher';
|
|
67
|
+
const relative = highest > 0 ? Math.min(4, Math.floor(value / highest * 5)) : 0;
|
|
68
|
+
const step = limits ? fixedStep(limits, value, higher) : relative;
|
|
69
|
+
return higher ? 4 - step : step;
|
|
70
|
+
}
|
|
71
|
+
const labels = {
|
|
72
|
+
ratio: value => `${+(value * 100).toFixed(1)}%`,
|
|
73
|
+
minutes: duration,
|
|
74
|
+
count: value => integers.format(value),
|
|
75
|
+
};
|
|
76
|
+
/** Counts step by whole numbers: ≤5, 6–10 … 51+. */
|
|
77
|
+
function countRanges(limits, show) {
|
|
78
|
+
return [`≤${show(limits[0])}`, ...limits.slice(1).map((limit, index) => `${show(limits[index] + 1)}–${show(limit)}`), `${show(limits[3] + 1)}+`];
|
|
79
|
+
}
|
|
80
|
+
/** Ratios and times run from limit to limit: <5%, 5–15% … 50%+; a ratio's range names its unit once. */
|
|
81
|
+
function spanRanges(limits, show, unit) {
|
|
82
|
+
const low = unit === 'ratio' ? (value) => show(value).replace(/%$/, '') : show;
|
|
83
|
+
return [`<${show(limits[0])}`, ...limits.slice(1).map((limit, index) => `${low(limits[index])}–${show(limit)}`), `${show(limits[3])}+`];
|
|
84
|
+
}
|
|
85
|
+
/** The legend's words, best band first; null where the bands are relative and the legend reads Lower … Higher. */
|
|
86
|
+
export function bandLabels(spec) {
|
|
87
|
+
const limits = spec.descriptor.bands;
|
|
88
|
+
if (!limits)
|
|
89
|
+
return null;
|
|
90
|
+
const unit = spec.descriptor.unit;
|
|
91
|
+
const ranges = unit === 'count' ? countRanges(limits, labels[unit]) : spanRanges(limits, labels[unit], unit);
|
|
92
|
+
return spec.descriptor.better === 'higher' ? ranges.reverse() : ranges;
|
|
93
|
+
}
|
|
@@ -48,23 +48,3 @@ export declare function commitValue(index: ReadonlyMap<string, number>, commit:
|
|
|
48
48
|
export declare function entryValue(index: ReadonlyMap<string, number>, entry: Valued, spec: MetricSpec): number | null;
|
|
49
49
|
/** The values of a group of files the viewer gathers itself (a filtered folder, a component), by each metric's roll-up. */
|
|
50
50
|
export declare function rollUp(catalog: readonly MetricDescriptor[] | undefined, entries: readonly Valued[]): MetricValues | undefined;
|
|
51
|
-
export declare function duration(minutes: number): string;
|
|
52
|
-
export declare function format(spec: MetricSpec, value: number | null): string;
|
|
53
|
-
/** The signed change between two values: percentage points for a ratio, coloured only where the metric has a better. */
|
|
54
|
-
export declare function difference(spec: MetricSpec, value: number, before: number): {
|
|
55
|
-
text: string;
|
|
56
|
-
direction: Direction;
|
|
57
|
-
};
|
|
58
|
-
/** The first click on a column sorts worst first. */
|
|
59
|
-
export declare function firstSortAscending(spec: MetricSpec): boolean;
|
|
60
|
-
/** Missing values sort last in both directions. */
|
|
61
|
-
export declare function compareValues(ascending: boolean): (a: number | null, b: number | null) => number;
|
|
62
|
-
/** The colour scale: heat where the metric has a better, so the worst is always red; neutral greys where it has none. */
|
|
63
|
-
export declare function bandScale(spec: MetricSpec): 'heat' | 'neutral';
|
|
64
|
-
/**
|
|
65
|
-
* One of five bands, 0 best to 4 worst. Fixed by the descriptor's limits where it has them; otherwise relative to the
|
|
66
|
-
* highest value shown. A metric where higher is better turns the scale round.
|
|
67
|
-
*/
|
|
68
|
-
export declare function bandOf(spec: MetricSpec, value: number, highest: number): number;
|
|
69
|
-
/** The legend's words, best band first; null where the bands are relative and the legend reads Lower … Higher. */
|
|
70
|
-
export declare function bandLabels(spec: MetricSpec): string[] | null;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/** Repometry's metrics keep short query words; every other key comes from the descriptor's id. */
|
|
2
2
|
const builtinKeys = {
|
|
3
|
-
'repometry.cyclomatic-
|
|
4
|
-
'repometry.cognitive-
|
|
5
|
-
'repometry.code-lines
|
|
3
|
+
'repometry.cyclomatic-complexity/v1': 'complexity',
|
|
4
|
+
'repometry.cognitive-complexity/v1': 'cognitive',
|
|
5
|
+
'repometry.code-lines/v1': 'lines',
|
|
6
6
|
'repometry.functions/v1': 'functions',
|
|
7
7
|
'repometry.lcov-line-coverage/v1': 'coverage',
|
|
8
|
-
'repometry.duplicated-lines
|
|
8
|
+
'repometry.duplicated-lines/v1': 'duplication',
|
|
9
9
|
'repometry.git-change-frequency/v1': 'changes',
|
|
10
10
|
'repometry.lcov-branch-coverage/v1': 'branch-coverage',
|
|
11
11
|
'repometry.lcov-covered-branches/v1': 'covered-branches',
|
|
@@ -16,9 +16,9 @@ const builtinKeys = {
|
|
|
16
16
|
};
|
|
17
17
|
/** The Repometry metrics the viewer draws from typed fields, with their own labels, columns and charts. */
|
|
18
18
|
const handDrawn = new Set([
|
|
19
|
-
'repometry.physical-lines/v1', 'repometry.functions/v1', 'repometry.cyclomatic-
|
|
20
|
-
'repometry.classes
|
|
21
|
-
'repometry.duplicated-lines
|
|
19
|
+
'repometry.physical-lines/v1', 'repometry.functions/v1', 'repometry.cyclomatic-complexity/v1', 'repometry.cognitive-complexity/v1',
|
|
20
|
+
'repometry.classes/v1', 'repometry.code-lines/v1', 'repometry.comment-lines/v1',
|
|
21
|
+
'repometry.duplicated-lines/v1', 'repometry.lcov-line-coverage/v1', 'repometry.lcov-covered-lines/v1',
|
|
22
22
|
'repometry.lcov-coverable-lines/v1', 'repometry.git-change-frequency/v1',
|
|
23
23
|
]);
|
|
24
24
|
/** Words that already mean something: query keys, Trends views and the series the viewer draws by hand. */
|
|
@@ -145,80 +145,3 @@ export function rollUp(catalog, entries) {
|
|
|
145
145
|
});
|
|
146
146
|
return values;
|
|
147
147
|
}
|
|
148
|
-
const integers = new Intl.NumberFormat();
|
|
149
|
-
const percent = new Intl.NumberFormat(undefined, { style: 'percent', maximumFractionDigits: 1 });
|
|
150
|
-
const decimal = new Intl.NumberFormat(undefined, { maximumFractionDigits: 1 });
|
|
151
|
-
export function duration(minutes) {
|
|
152
|
-
const rounded = Math.round(minutes);
|
|
153
|
-
if (rounded < 60)
|
|
154
|
-
return `${integers.format(rounded)} min`;
|
|
155
|
-
const hours = Math.floor(rounded / 60);
|
|
156
|
-
const rest = rounded % 60;
|
|
157
|
-
return rest ? `${integers.format(hours)} h ${integers.format(rest)} min` : `${integers.format(hours)} h`;
|
|
158
|
-
}
|
|
159
|
-
export function format(spec, value) {
|
|
160
|
-
if (value === null)
|
|
161
|
-
return '—';
|
|
162
|
-
switch (spec.descriptor.unit) {
|
|
163
|
-
case 'ratio': return percent.format(value);
|
|
164
|
-
case 'minutes': return duration(value);
|
|
165
|
-
case 'count': return integers.format(value);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/** The signed change between two values: percentage points for a ratio, coloured only where the metric has a better. */
|
|
169
|
-
export function difference(spec, value, before) {
|
|
170
|
-
const { unit, better } = spec.descriptor;
|
|
171
|
-
const raw = unit === 'ratio' ? (value - before) * 100 : value - before;
|
|
172
|
-
const rounded = unit === 'ratio' ? Math.round(raw * 10) / 10 : Math.round(raw);
|
|
173
|
-
if (rounded === 0)
|
|
174
|
-
return { text: 'No change', direction: 'same' };
|
|
175
|
-
const size = Math.abs(rounded);
|
|
176
|
-
const magnitude = unit === 'ratio' ? `${decimal.format(size)} pp` : unit === 'minutes' ? duration(size) : integers.format(size);
|
|
177
|
-
const direction = better === 'none' ? 'neutral' : (better === 'lower') === (rounded < 0) ? 'better' : 'worse';
|
|
178
|
-
return { text: `${rounded > 0 ? '+' : '−'}${magnitude}`, direction };
|
|
179
|
-
}
|
|
180
|
-
/** The first click on a column sorts worst first. */
|
|
181
|
-
export function firstSortAscending(spec) {
|
|
182
|
-
return spec.descriptor.better === 'higher';
|
|
183
|
-
}
|
|
184
|
-
/** Missing values sort last in both directions. */
|
|
185
|
-
export function compareValues(ascending) {
|
|
186
|
-
return (a, b) => a === null ? (b === null ? 0 : 1) : b === null ? -1 : ascending ? a - b : b - a;
|
|
187
|
-
}
|
|
188
|
-
/** The colour scale: heat where the metric has a better, so the worst is always red; neutral greys where it has none. */
|
|
189
|
-
export function bandScale(spec) {
|
|
190
|
-
return spec.descriptor.better === 'none' ? 'neutral' : 'heat';
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* One of five bands, 0 best to 4 worst. Fixed by the descriptor's limits where it has them; otherwise relative to the
|
|
194
|
-
* highest value shown. A metric where higher is better turns the scale round.
|
|
195
|
-
*/
|
|
196
|
-
export function bandOf(spec, value, highest) {
|
|
197
|
-
const limits = spec.descriptor.bands;
|
|
198
|
-
const higher = spec.descriptor.better === 'higher';
|
|
199
|
-
// A limit belongs to the better side: at most 5 is the best complexity band, 90% is already the best coverage band.
|
|
200
|
-
const step = limits ? (() => {
|
|
201
|
-
const index = limits.findIndex(limit => higher ? value < limit : value <= limit);
|
|
202
|
-
return index < 0 ? limits.length : index;
|
|
203
|
-
})() : highest > 0 ? Math.min(4, Math.floor(value / highest * 5)) : 0;
|
|
204
|
-
return higher ? 4 - step : step;
|
|
205
|
-
}
|
|
206
|
-
/** The legend's words, best band first; null where the bands are relative and the legend reads Lower … Higher. */
|
|
207
|
-
export function bandLabels(spec) {
|
|
208
|
-
const limits = spec.descriptor.bands;
|
|
209
|
-
if (!limits)
|
|
210
|
-
return null;
|
|
211
|
-
const unit = spec.descriptor.unit;
|
|
212
|
-
const show = (value) => unit === 'ratio' ? `${+(value * 100).toFixed(1)}%` : unit === 'minutes' ? duration(value) : integers.format(value);
|
|
213
|
-
const bare = (value) => show(value).replace(/%$/, '');
|
|
214
|
-
let ranges;
|
|
215
|
-
if (unit === 'count') {
|
|
216
|
-
ranges = [`≤${show(limits[0])}`, ...limits.slice(1).map((limit, index) => `${show(limits[index] + 1)}–${show(limit)}`),
|
|
217
|
-
`${show(limits[3] + 1)}+`];
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
const join = (low, high) => unit === 'ratio' ? `${bare(low)}–${show(high)}` : `${show(low)}–${show(high)}`;
|
|
221
|
-
ranges = [`<${show(limits[0])}`, ...limits.slice(1).map((limit, index) => join(limits[index], limit)), `${show(limits[3])}+`];
|
|
222
|
-
}
|
|
223
|
-
return spec.descriptor.better === 'higher' ? ranges.reverse() : ranges;
|
|
224
|
-
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
|
|
2
|
+
import type { Metrics, Navigation, Preferences } from './viewer-inspection.js';
|
|
3
|
+
/** The Metrics page: a query, a grouping and columns over the folder's files, their languages, and the totals beside. */
|
|
4
|
+
export declare function metricsView(details: InspectionDetails, navigation: Navigation, settings: Preferences, directory: string, selectedFile?: Metrics): HTMLElement;
|