🍬 Pretty Treemaps

🍬 Pretty Treemaps

Go Reference codecov Go Report Card

$ go install github.com/nikolaydubina/treemap/cmd/treemap@latest 
$ echo '
Africa/Algeria,33333216,72
Africa/Angola,12420476,42
Africa/Benin,8078314,56
...
' | treemap > out.svg

example

Adjusting size

$ ... | treemap -w 1080 -h 360 > out.svg

example-narrow

$ ... | treemap -w 1080 -h 1080 > out.svg

example-square

Tree-Hue coloring when there is no heat

$ ... | treemap -color balanced > out.svg

example-balanced

Without color

$ ... | treemap -color none > out.svg

example-no-color

Format

Size and heat is optional.

</ delimitered path>,<size>,<heat>

Algorithms

  • Squarified algorithm for treemap layout problem. This is very common algorithm used in Plotly and most of visualization packages. "Squarified Treemaps", Mark Bruls, Kees Huizing, and Jarke J. van Wijk, 2000
  • Tree-Hue Color algorithm for generating colors for nodes in treemap. The idea is to represent hierarchical structure by recursively painting similar hue to subtrees. Nikolay Dubina, 2021

Contributions

Welcomed!

References

Appendix A: Less Illustrative Examples

Large dimensions and large tree (e.g. github.com/golang/go)

$ ... | treemap -w 4096 -h 4096 > out.svg

example-large

Comments
  • Can't use slash or comma in names

    Can't use slash or comma in names

    Slashes and commas are reserved as path and column delimiters, respectively. This prevents their use in names (path parts). Or rather, it leads to unexpected results.

    My particular use case is in dirstat again, where I would like to use a trailing slash to denote directories.

    I see two options to solve this:

    • Configurable column and path delimiters
    • Using HTLM entities, like &sol; for these characters
      • Comes with some problems:
        • Would not work well with string length calculations for box titles
          • Could use regex or a dedicated XML/HTML encoding/decoding library to fix this
        • & is currently replaced by &amp; to form valid XML/SVG
          • Would require to take care of HTML entities in & replacement
  • Escale illegal XML characters

    Escale illegal XML characters

    Escapes illegal XML characters.

    Decided to do it in svg.go rather than in the UIText construction, as the issue is specific for SVG rendering.

    Not sure how to add useful unit tests for this.

    Fixes #20

  • Slashes through entities

    Slashes through entities

    A suggestion to solve #25.

    Names can show up with slashes by the use of the &sol; HTML entity.

    Internally, the entity is replaced by slash when assigning names, and the contrary when constructing paths from names. String length calculations are performed on names (not paths), so they don't encounter the (potentially compromising) entity.

    TODO

    • [x] Add tests

    Screenshot showing it in action:

    test

    The related CSV looks like this:

    ..&sol; (147 GB | 867 k),147934207228.000000,5.938393
    ..&sol; (147 GB | 867 k)/CPP&sol; (30 GB | 361 k),30802642261.000000,5.558565
    ..&sol; (147 GB | 867 k)/CPP&sol; (30 GB | 361 k)/Cataclysm-DDA&sol; (16 GB | 53 k),16554995652.000000,4.731307
    ..&sol; (147 GB | 867 k)/CPP&sol; (30 GB | 361 k)/Cataclysm-DDA&sol; (16 GB | 53 k)/.md (1.6 MB | 101),1588724.000000,2.004321
    ..&sol; (147 GB | 867 k)/CPP&sol; (30 GB | 361 k)/Cataclysm-DDA&sol; (16 GB | 53 k)/.sample (23 kB | 13),23442.000000,1.113943
    ...
    

    Fixes #25

  • No RGBA

    No RGBA

    This PR changes SVG generation to use rbg(...) instead of rgba(...), which is not supported by Inkscape.

    Alpha is scaled to range [0, 1] and used in the ...-opacity properties.

    Alpha can't currently appear when used via the CLI, as it is not supported by the colorful.Hex() function that is used for palettes. Decided to still leave alpha in for use as a library.

    Not 100% sure about the bitshift, but it looks like alpha is treated the same as color channels.

    Fixes #21

    Screenshot Inkscape before:

    grafik

    After:

    grafik

    Screen to verify that using fill-opacity and leaving opacity at 1 works:

    grafik

  • Escape illegal XML characters

    Escape illegal XML characters

    Some characters that are illegal in XML strings break SVG rendering. These characters should be escaped.

    Encountered the issue in my little Go learning project dirstat, which uses treemap to visualize disk usage. File and directory names may contain such characters.

    Looks like the relevant characters are only those:

    • " &quot;
    • ' &apos;
    • < &lt;
    • > &gt;
    • & &amp;
  • RGBA colors not supported by Inkscape

    RGBA colors not supported by Inkscape

    It seems like Inkscape does not support rgba(...) colors. (see https://gitlab.com/inkscape/inbox/-/issues/1195).
    This causes Inkscape to render all boxes and borders in black.

    Would it be an option to use rgb(...), and handle the alpha component via opacity (should probably be a / 255.0)?

    Happy to make a PR for this minor change, if this workaround is acceptable.

  • Default heat colors counterintuitive

    Default heat colors counterintuitive

    Currently, the default heat coloring ranges from red to blue for low to high heat values.

    Given the term "heat", I would expect the opposite.

    Here is an example from dirstat, which uses log(#files) for coloring:

    grafik

  • Continuous integration to build binaries

    Continuous integration to build binaries

    Would you accept a PR to do a CI build of native binaries in order to distribute it to those who don't have or want the go toolchain?

    ( Super cool tool ! )

💻 PTerm | Pretty Terminal Printer A golang module to print pretty text
💻 PTerm | Pretty Terminal Printer A golang module to print pretty text

✨ PTerm is a modern go module to beautify console output. Featuring charts, progressbars, tables, trees, and many more ?? It's completely configurable and 100% cross-platform compatible.

Jan 1, 2023
Implements a deep pretty printer for Go data structures to aid in debugging

go-spew Go-spew implements a deep pretty printer for Go data structures to aid in debugging. A comprehensive suite of tests with 100% test coverage is

Dec 31, 2022
Package httpretty prints the HTTP requests you make with Go pretty on your terminal.

httpretty Package httpretty prints the HTTP requests of your Go programs pretty on your terminal screen. It is mostly inspired in curl's --verbose mod

Jan 8, 2023
Implements a deep pretty printer for Go data structures to aid in debugging

go-spew Go-spew implements a deep pretty printer for Go data structures to aid in debugging. A comprehensive suite of tests with 100% test coverage is

Jan 9, 2023
Pretty Slug.

go-slugify Make Pretty Slug. Installation go get -u github.com/mozillazg/go-slugify Install CLI tool: go get -u github.com/mozillazg/go-slugify/slugi

Dec 17, 2022
Gotabulate - Easily pretty-print your tabular data with Go

Gotabulate - Easily pretty-print tabular data Summary Go-Tabulate - Generic Go Library for easy pretty-printing of tabular data. Installation go get g

Dec 27, 2022
Package httpretty prints the HTTP requests you make with Go pretty on your terminal.

httpretty Package httpretty prints the HTTP requests of your Go programs pretty on your terminal screen. It is mostly inspired in curl's --verbose mod

Jan 8, 2023
Colored pretty printer for Go language
Colored pretty printer for Go language

pp Colored pretty printer for Go language Usage Just call pp.Print(). import "github.com/k0kubun/pp" m := map[string]string{"foo": "bar", "hello": "w

Dec 29, 2022
Litter is a pretty printer library for Go data structures to aid in debugging and testing.

Litter Litter is a pretty printer library for Go data structures to aid in debugging and testing. Litter is provided by Sanity: The Headless CMS Const

Dec 28, 2022
Fast Color JSON Marshaller + Pretty Printer for Golang
Fast Color JSON Marshaller + Pretty Printer for Golang

ColorJSON: The Fast Color JSON Marshaller for Go What is this? This package is based heavily on hokaccha/go-prettyjson but has some noticible differen

Dec 19, 2022
Slice graph uses graphviz in order to pretty print slices for you.

slicegraph Slice graph uses graphviz in order to make you understand what happens underneath your slices.

Sep 22, 2022
🪵 A dead simple, pretty, and feature-rich logger for golang
🪵 A dead simple, pretty, and feature-rich logger for golang

?? lumber ?? A dead simple, pretty, and feature-rich logger for golang ?? Install ?? Logging Functions lumber.Success() lumber.Info() lumber.Debug() l

Jul 20, 2022
code is pretty self explanatory and decently commented
code is pretty self explanatory and decently commented

square_approximation code is pretty self explanatory and decently commented when limit set to 10^9 or more ram usage goes to >42 gigs of ram which is

Apr 7, 2022
Gofetch is a pretty command-line "Go and System information" tool written in Go
Gofetch is a pretty command-line

GoFetch Show off your Go information with this cool command-line tool! Report Bug || Request Feature Table of Contents About the Project Built With Ge

Nov 1, 2022
A command-line tool to pretty print your system's PATH environment variable.
A command-line tool to pretty print your system's PATH environment variable.

Description A command-line tool to pretty print your system's PATH environment variable. The output paths are colorized if they have special associati

Nov 9, 2022
Pretty wrapper for sending email using go net/smtp

Emailer A pretty wrapper around go net/smtp send multiple email using single client func main() { var client *emailer.Client var clientX sync.Mute

Mar 23, 2022
✨ Pretty TOTP manager in your terminal
✨ Pretty TOTP manager in your terminal

asunder Asunder, Sweet and Other Distress asunder is a small pretty command-line TOTP manager. Installation Binaries Download a binary from the releas

Dec 26, 2022
Implements a deep pretty printer for Go data structures to aid in debugging

spew Spew implements a deep pretty printer for Go data structures to aid in debugging. A comprehensive suite of tests with 100% test coverage is provi

Dec 25, 2022