diff options
| author | Taras Madan <tarasmadan@google.com> | 2024-07-12 11:47:53 +0200 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2024-07-15 20:31:23 +0000 |
| commit | 1e9b4efa8053e3d27be8a5803c91bf37923ffe3b (patch) | |
| tree | c8985c4c1160815d701e6317bb7a3ee96b230b30 /pkg/cover/heatmap.go | |
| parent | 31605b3e1a107ab83d814ec4183cec07bb670655 (diff) | |
pkg/cover/heatmap.go: add blocks count
Diffstat (limited to 'pkg/cover/heatmap.go')
| -rw-r--r-- | pkg/cover/heatmap.go | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/pkg/cover/heatmap.go b/pkg/cover/heatmap.go index e5d2f4476..9cc3286e5 100644 --- a/pkg/cover/heatmap.go +++ b/pkg/cover/heatmap.go @@ -20,11 +20,12 @@ import ( ) type templateHeatmapRow struct { - Items []*templateHeatmapRow - Name string - Coverage []int64 - IsDir bool - Depth int + Items []*templateHeatmapRow + Name string + Coverage []int64 + IsDir bool + Depth int + LastDayInstrumented int64 builder map[string]*templateHeatmapRow instrumented map[civil.Date]int64 @@ -72,6 +73,10 @@ func (thm *templateHeatmapRow) prepareDataFor(dates []civil.Date) { } thm.Coverage = append(thm.Coverage, dateCoverage) } + if len(dates) > 0 { + lastDate := dates[len(dates)-1] + thm.LastDayInstrumented = thm.instrumented[lastDate] + } for _, item := range thm.builder { item.prepareDataFor(dates) } @@ -169,6 +174,18 @@ func DoHeatMap(w io.Writer, ns string, dateFrom, dateTo civil.Date) error { return heatmapTemplate.Execute(w, templateData) } +func approximateInstrumented(points int64) string { + dim := "_" + if points > 10000 { + dim = "K" + points /= 1000 + } + return fmt.Sprintf("%d%s", points, dim) +} + //go:embed templates/heatmap.html var templatesHeatmap string -var heatmapTemplate = template.Must(template.New("").Parse(templatesHeatmap)) +var templateHeatmapFuncs = template.FuncMap{ + "approxInstr": approximateInstrumented, +} +var heatmapTemplate = template.Must(template.New("").Funcs(templateHeatmapFuncs).Parse(templatesHeatmap)) |
