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 | |
| parent | 31605b3e1a107ab83d814ec4183cec07bb670655 (diff) | |
pkg/cover/heatmap.go: add blocks count
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/cover/heatmap.go | 29 | ||||
| -rw-r--r-- | pkg/cover/heatmap_test.go | 56 | ||||
| -rw-r--r-- | pkg/cover/templates/heatmap.html | 13 |
3 files changed, 66 insertions, 32 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)) diff --git a/pkg/cover/heatmap_test.go b/pkg/cover/heatmap_test.go index c40d14ccc..d450a5243 100644 --- a/pkg/cover/heatmap_test.go +++ b/pkg/cover/heatmap_test.go @@ -40,17 +40,19 @@ func TestFilesCoverageToTemplateData(t *testing.T) { Root: &templateHeatmapRow{ Items: []*templateHeatmapRow{ { - Items: []*templateHeatmapRow{}, - Name: "file1", - Coverage: []int64{100}, - IsDir: false, - Depth: 0, + Items: []*templateHeatmapRow{}, + Name: "file1", + Coverage: []int64{100}, + IsDir: false, + Depth: 0, + LastDayInstrumented: 1, }, }, - Name: "", - Coverage: []int64{100}, - IsDir: false, - Depth: 0, + Name: "", + Coverage: []int64{100}, + IsDir: false, + Depth: 0, + LastDayInstrumented: 1, }, Dates: []string{"2024-07-01"}, }, @@ -77,28 +79,32 @@ func TestFilesCoverageToTemplateData(t *testing.T) { { Items: []*templateHeatmapRow{ { - Items: []*templateHeatmapRow{}, - Name: "file1", - Coverage: []int64{100, 0}, - IsDir: false, - Depth: 1, + Items: []*templateHeatmapRow{}, + Name: "file1", + Coverage: []int64{100, 0}, + IsDir: false, + Depth: 1, + LastDayInstrumented: 0, }, { - Items: []*templateHeatmapRow{}, - Name: "file2", - Coverage: []int64{0, 0}, - IsDir: false, - Depth: 1, + Items: []*templateHeatmapRow{}, + Name: "file2", + Coverage: []int64{0, 0}, + IsDir: false, + Depth: 1, + LastDayInstrumented: 1, }, }, - Name: "dir", - Coverage: []int64{100, 0}, - IsDir: true, - Depth: 0, + Name: "dir", + Coverage: []int64{100, 0}, + IsDir: true, + Depth: 0, + LastDayInstrumented: 1, }, }, - Name: "", - Coverage: []int64{100, 0}, + Name: "", + Coverage: []int64{100, 0}, + LastDayInstrumented: 1, }, Dates: []string{"2024-07-01", "2024-07-02"}, }, diff --git a/pkg/cover/templates/heatmap.html b/pkg/cover/templates/heatmap.html index 9f5d1da2c..4d3e159b2 100644 --- a/pkg/cover/templates/heatmap.html +++ b/pkg/cover/templates/heatmap.html @@ -15,6 +15,11 @@ display: inline-block; width: 50px; } + .instrumented_column { + display: inline-block; + width: 70px; + text-align: right; + } .tree_depth_0 {width: 0px;} .tree_depth_1 {width: 20px;} .tree_depth_2 {width: 40px;} @@ -64,13 +69,16 @@ </li> <li> <div class="first_column bold"> - total + total covered </div> {{ range $cov := .Root.Coverage }} <div class="date_column"> {{ $cov }}% </div> {{ end }} + <div class="instrumented_column"> + of {{ approxInstr .Root.LastDayInstrumented }} blocks + </div> </li> <br> {{template "dir" .Root}} @@ -105,6 +113,9 @@ {{ $cov }}% </div> {{ end }} + <div class="instrumented_column"> + {{ approxInstr $child.LastDayInstrumented }} + </div> </div> {{ if $child.IsDir }} <ul class="nested"> |
