Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/nikolaydubina/go-cover-treemap

πŸŽ„ Go code coverage to SVG treemap
https://github.com/nikolaydubina/go-cover-treemap

code-coverage command-line-tool heatmap treemap

Last synced: 11 days ago
JSON representation

πŸŽ„ Go code coverage to SVG treemap

Lists

README

        

# πŸŽ„ [Go cover to Treemap](https://nikolaydubina.github.io/go-cover-treemap/)

[![go-recipes](https://raw.githubusercontent.com/nikolaydubina/go-recipes/main/badge.svg?raw=true)](https://github.com/nikolaydubina/go-recipes)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/nikolaydubina/go-cover-treemap/badge)](https://securityscorecards.dev/viewer/?uri=github.com/nikolaydubina/go-cover-treemap)

_Useful when you have large project with lots of files and packages_

```
$ go install github.com/nikolaydubina/go-cover-treemap@latest
$ go test -coverprofile cover.out ./...
$ go-cover-treemap -coverprofile cover.out > out.svg
```

_

github.com/gohugoio/hugo

_
![example-hugo](docs/hugo.svg)

_

..also available in 1080x360

_
![example-hugo-small](docs/hugo-1080x360.svg)

_

..and even 1080x180

_
![example-hugo-small](docs/hugo-1080x180.svg)

_

github.com/gin-gonic/gin

_
![example-gin](docs/gin.svg)

_

github.com/go-chi/chi

_
![example-chi](docs/chi.svg)

_

github.com/nikolaydubina/treemap

_
![example-treemap](docs/go-cover-treemap.svg)

_

github.com/nikolaydubina/go-featureprocessing

_
![example-go-featureprocessing](docs/go-featureprocessing.svg)

## Disclaimer

In all examples above I run `go test -coverprofile ./...`.
I did not do any special setup.
Some projects may require additional steps to properly run test and generate full coverprofile.
What you see is "lower bound" of coverage for those projects.
All profiles generated on `main` branch of each project in GitHub on 2021-12-07.

## Contributions

Welcomed! Add pretty color palettes! Add interesting examples!

## Reference

* Official Go tool to make HTML from cover profile: https://github.com/golang/go/blob/master/src/cmd/cover/html.go#L97
* Official Go parser of cover profile `golang.org/x/tools/cover`: https://github.com/golang/tools/tree/master/cover
* Go SVG Treemap renderer with treemap: https://github.com/nikolaydubina/treemap

## Appendix A: Statements vs File for Size

You can see that structure and heat changes for `github.com/gohugoio/hugo`.
Subtrees that look bad for files no longer look as bad for statements.
Lots of red boxes for files become very small and unnoticeable.
This can be because they contain non-testable constructs like constants.
It is more accurate to use statments, since heat is percentage of covered statements, and we compute heat by weighting sum by sizes of children.
In short, you are more likely want to use statements for size.

files
![example-hugo-files](docs/hugo-files.svg)

statements
![example-hugo](docs/hugo.svg)

## Appendix B: Long Roots

It is common to have root and first few children to have only one child.
Each takes margin and wastes space.
We can collapse these into longer name, and use that space for visualizing higher depth of boxes.
This is particularly useful for narrow dimensions, which makes feasible useful narrow dimension.

1080x360 with root collapsing
![example-long-root-med-collapsed](docs/hugo-1080x360.svg)

1080x360 without root collapse
![example-long-root-med-no-collapse](docs/hugo-long-root-1080x360.svg)

1080x180 with root collapsing
![example-long-root-med-collapsed](docs/hugo-1080x180.svg)

1080x180 without root collapse
![example-long-root-med-no-collapse](docs/hugo-long-root-1080x180.svg)

## Appendix C: Web UI

Web UI is maintained in dedicated repository: https://github.com/nikolaydubina/go-cover-treemap-web

This is to isolate web (WASM/JS/HTML) needed dependencies, like `syscall/js` from minimal CLI package.

It turns out interactive UI is very helpful. Brower can be utilized as effective input source for:
- changing dimensions of window -> changing dimensions of SVG
- drag and drop file
- slider to increase granularity of treemap

## Appendix D: Only Folders

Projects that have lots of files may benefit from not displaying files
but only folders.
This is also useful when you want to see impact of immediate files in folder to overall folder heat.
Hierarchical properties of size (sum of sizes of children) and heat (weighted heat of children) are preserved.
Immediate children `.go` files in folder are aggregated into single child `*`.
If there is only one `*` child, then it is skipped
β€” suggested by [herlon214](https://github.com/herlon214)

files
![example-hugo](docs/hugo.svg)

only folders
![example-hugo-files](docs/hugo-only-folders.svg)

only folders without aggregation (heat and size property not preserved)
![example-hugo-files](docs/hugo-only-folders-no-aggregation.svg)

## Appendix E: Accessibility

Is is important that everyone can use this tool.
Such we are providing color-blind option Red-Blue alternative.
β€” suggested by [Br3nda](https://github.com/Br3nda)

normal
![example-hugo](docs/hugo.svg)

color-blind
![example-hugo-color-blind](docs/hugo-color-blind.svg)

### Docs

```bash
$ cat testdata/treemap.cover | ./go-cover-treemap > docs/go-cover-treemap-stdin.svg
$ ./go-cover-treemap -coverprofile testdata/treemap.cover > docs/go-cover-treemap.svg
$ ./go-cover-treemap -coverprofile testdata/go-featureprocessing.cover > docs/go-featureprocessing.svg
$ ./go-cover-treemap -coverprofile testdata/gin.cover > docs/gin.svg
$ ./go-cover-treemap -coverprofile testdata/chi.cover > docs/chi.svg
$ ./go-cover-treemap -coverprofile testdata/hugo.cover > docs/hugo.svg
$ ./go-cover-treemap -coverprofile testdata/hugo.cover -w 1080 -h 360 > docs/hugo-1080x360.svg
$ ./go-cover-treemap -coverprofile testdata/hugo.cover -w 1080 -h 180 > docs/hugo-1080x180.svg
$ ./go-cover-treemap -coverprofile testdata/hugo.cover -statements=false > docs/hugo-files.svg
$ ./go-cover-treemap -coverprofile testdata/hugo.cover -collapse-root=false > docs/hugo-long-root.svg
$ ./go-cover-treemap -coverprofile testdata/hugo.cover -collapse-root=false -w 1080 -h 360 > docs/hugo-long-root-1080x360.svg
$ ./go-cover-treemap -coverprofile testdata/hugo.cover -collapse-root=false -w 1080 -h 180 > docs/hugo-long-root-1080x180.svg
$ ./go-cover-treemap -coverprofile testdata/hugo.cover -only-folders > docs/hugo-only-folders.svg
$ ./go-cover-treemap -coverprofile testdata/hugo.cover --color-blind > docs/hugo-color-blind.svg
```