Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a heatmap printer #487

Merged
merged 20 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7a39e7e
feat(heatmap): add a heatmap printer
floaust Apr 7, 2023
94a24d9
example(heatmap): add heatmap printer example
floaust Apr 7, 2023
fd08ce3
Merge branch '491-proposal-rgbstyle' into 472-heatmap-printer
floaust Apr 16, 2023
bbbc2ab
feat(heatmap): added RGBStyle and complementary colors
floaust Apr 16, 2023
2e98087
refactor(heatmap): improved performance
floaust Apr 16, 2023
ee1218c
feat(heatmap): add basic tests
KarolosLykos Apr 9, 2023
83131fd
feat(heatmap): add more tests
KarolosLykos Apr 9, 2023
8fd4eb0
feat(heatmap): added legend for heatmap
floaust Apr 16, 2023
0b9b5a7
feat(heatmap): added legend for heatmap
floaust Apr 16, 2023
beee324
Merge remote-tracking branch 'origin/472-heatmap-printer' into 472-he…
floaust Apr 16, 2023
6d2eb31
Merge branch 'master' into 472-heatmap-printer
MarvinJWendt Apr 28, 2023
b689409
Merge branch 'master' into 472-heatmap-printer
MarvinJWendt Jun 3, 2023
0a68a7f
Merge branch 'master' into 472-heatmap-printer
floaust Oct 7, 2023
ba9f1ce
refactor(heatmap): refactored code and fixed bugs
floaust Oct 8, 2023
fa1a954
Merge remote-tracking branch 'origin/472-heatmap-printer' into 472-he…
floaust Oct 8, 2023
e36f26b
feat(heatmap): disable legend when raw output true
floaust Oct 8, 2023
55b99d7
feat(heatmap): change and add demos
floaust Oct 8, 2023
edde6cc
feat(heatmap): change and add demos and comment behaviour of With funcs
floaust Oct 15, 2023
daa51bf
refactor(heatmap): refactor variable naming
floaust Oct 15, 2023
2b198de
Merge branch 'master' into 472-heatmap-printer
MarvinJWendt Oct 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -15,7 +15,7 @@
vendor/

# This is where we test stuff
/experimenting/
/experimenting/*

/.history
/.vscode
Expand Down
25 changes: 25 additions & 0 deletions _examples/heatmap/custom_colors/main.go
@@ -0,0 +1,25 @@
package main

import (
"github.com/pterm/pterm"
)

func main() {
data := [][]float32{
{0.9, 0.2, -0.7, 0.4, -0.5, 0.6, -0.3, 0.8, -0.1, -1.0, 0.1, -0.8, 0.3},
{0.2, -0.7, -0.5, -0.3, -0.1, 0.1, 0.3, 0.5, 0.9, -0.9, -0.7, -0.5, -0.3},
{0.4, 0.4, -0.3, -1.0, 0.3, -0.2, -0.9, 0.5, -0.3, -1.0, 0.6, -0.2, -0.9},
{0.9, -0.5, -0.1, 0.3, 1, -0.7, -0.3, 0.1, 0.7, -0.9, -0.5, 0.2, 0.6},
{0.5, 0.6, 0.1, -0.2, -0.7, 0.8, 0.6, 0.1, -0.5, -0.7, 0.7, 0.3, 0.0},
}

headerData := pterm.HeatmapAxis{
XAxis: []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"},
YAxis: []string{"1", "2", "3", "4", "5"},
}

pterm.Println("The following table has no rgb (supported by every terminal), no axis data and a legend.\n")
MarvinJWendt marked this conversation as resolved.
Show resolved Hide resolved

table := pterm.DefaultHeatmap.WithData(data).WithBoxed(false).WithAxisData(headerData).WithLegend(false).WithColors(pterm.BgBlue, pterm.BgRed, pterm.BgGreen, pterm.BgYellow).WithLegend()
table.Render()
}
25 changes: 25 additions & 0 deletions _examples/heatmap/custom_legend/main.go
@@ -0,0 +1,25 @@
package main

import (
"github.com/pterm/pterm"
)

func main() {
data := [][]float32{
{0.9, 0.2, -0.7, 0.4, -0.5, 0.6, -0.3, 0.8, -0.1, -1.0, 0.1, -0.8, 0.3},
{0.2, -0.7, -0.5, -0.3, -0.1, 0.1, 0.3, 0.5, 0.9, -0.9, -0.7, -0.5, -0.3},
{0.4, 0.4, -0.3, -1.0, 0.3, -0.2, -0.9, 0.5, -0.3, -1.0, 0.6, -0.2, -0.9},
{0.9, -0.5, -0.1, 0.3, 1, -0.7, -0.3, 0.1, 0.7, -0.9, -0.5, 0.2, 0.6},
{0.5, 0.6, 0.1, -0.2, -0.7, 0.8, 0.6, 0.1, -0.5, -0.7, 0.7, 0.3, 0.0},
}

headerData := pterm.HeatmapAxis{
XAxis: []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"},
YAxis: []string{"1", "2", "3", "4", "5"},
}

pterm.Println("The following table has rgb (not supported by every terminal), axis data and a custom legend.\n")
MarvinJWendt marked this conversation as resolved.
Show resolved Hide resolved

table := pterm.DefaultHeatmap.WithData(data).WithBoxed(false).WithAxisData(headerData).WithEnableRGB().WithLegendTag("custom").WithLegendOnlyColoredCells()
table.Render()
}
25 changes: 25 additions & 0 deletions _examples/heatmap/custom_rgb/main.go
@@ -0,0 +1,25 @@
package main

import (
"github.com/pterm/pterm"
)

func main() {
data := [][]float32{
{0.9, 0.2, -0.7, 0.4, -0.5, 0.6, -0.3, 0.8, -0.1, -1.0, 0.1, -0.8, 0.3},
{0.2, -0.7, -0.5, -0.3, -0.1, 0.1, 0.3, 0.5, 0.9, -0.9, -0.7, -0.5, -0.3},
{0.4, 0.4, -0.3, -1.0, 0.3, -0.2, -0.9, 0.5, -0.3, -1.0, 0.6, -0.2, -0.9},
{0.9, -0.5, -0.1, 0.3, 1, -0.7, -0.3, 0.1, 0.7, -0.9, -0.5, 0.2, 0.6},
{0.5, 0.6, 0.1, -0.2, -0.7, 0.8, 0.6, 0.1, -0.5, -0.7, 0.7, 0.3, 0.0},
}

headerData := pterm.HeatmapAxis{
XAxis: []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"},
YAxis: []string{"1", "2", "3", "4", "5"},
}

pterm.Println("The following table has rgb (not supported by every terminal), axis data and a legend.\n")
MarvinJWendt marked this conversation as resolved.
Show resolved Hide resolved

table2 := pterm.DefaultHeatmap.WithData(data).WithBoxed(false).WithAxisData(headerData).WithRGBRange(pterm.NewRGB(0, 0, 255), pterm.NewRGB(255, 0, 0), pterm.NewRGB(0, 255, 0), pterm.NewRGB(255, 255, 0))
table2.Render()
}
23 changes: 23 additions & 0 deletions _examples/heatmap/demo/main.go
@@ -0,0 +1,23 @@
package main

import (
"github.com/pterm/pterm"
)

func main() {
data := [][]float32{
{0.9, 0.2, -0.7, 0.4, -0.5, 0.6, -0.3, 0.8, -0.1, -1.0, 0.1, -0.8, 0.3},
{0.2, -0.7, -0.5, -0.3, -0.1, 0.1, 0.3, 0.5, 0.9, -0.9, -0.7, -0.5, -0.3},
{0.4, 0.4, -0.3, -1.0, 0.3, -0.2, -0.9, 0.5, -0.3, -1.0, 0.6, -0.2, -0.9},
{0.9, -0.5, -0.1, 0.3, 1, -0.7, -0.3, 0.1, 0.7, -0.9, -0.5, 0.2, 0.6},
{0.5, 0.6, 0.1, -0.2, -0.7, 0.8, 0.6, 0.1, -0.5, -0.7, 0.7, 0.3, 0.0},
}

headerData := pterm.HeatmapAxis{
XAxis: []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"},
YAxis: []string{"1", "2", "3", "4", "5"},
}

table := pterm.DefaultHeatmap.WithAxisData(headerData).WithData(data)
MarvinJWendt marked this conversation as resolved.
Show resolved Hide resolved
table.Render()
}
25 changes: 25 additions & 0 deletions _examples/heatmap/no_grid/main.go
@@ -0,0 +1,25 @@
package main

import (
"github.com/pterm/pterm"
)

func main() {
data := [][]float32{
{0.9, 0.2, -0.7, 0.4, -0.5, 0.6, -0.3, 0.8, -0.1, -1.0, 0.1, -0.8, 0.3},
{0.2, -0.7, -0.5, -0.3, -0.1, 0.1, 0.3, 0.5, 0.9, -0.9, -0.7, -0.5, -0.3},
{0.4, 0.4, -0.3, -1.0, 0.3, -0.2, -0.9, 0.5, -0.3, -1.0, 0.6, -0.2, -0.9},
{0.9, -0.5, -0.1, 0.3, 1, -0.7, -0.3, 0.1, 0.7, -0.9, -0.5, 0.2, 0.6},
{0.5, 0.6, 0.1, -0.2, -0.7, 0.8, 0.6, 0.1, -0.5, -0.7, 0.7, 0.3, 0.0},
}

headerData := pterm.HeatmapAxis{
XAxis: []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"},
YAxis: []string{"1", "2", "3", "4", "5"},
}

pterm.Println("The following table has rgb (not supported by every terminal), axis data and a legend.\n")
MarvinJWendt marked this conversation as resolved.
Show resolved Hide resolved

table2 := pterm.DefaultHeatmap.WithData(data).WithBoxed(false).WithAxisData(headerData).WithEnableRGB().WithLegend().WithGrid(false)
table2.Render()
}
23 changes: 23 additions & 0 deletions _examples/heatmap/separated/main.go
@@ -0,0 +1,23 @@
package main

import "github.com/pterm/pterm"

func main() {
data := [][]float32{
{0.9, 0.2, -0.7, 0.4, -0.5, 0.6, -0.3, 0.8, -0.1, -1.0, 0.1, -0.8, 0.3},
{0.2, -0.7, -0.5, -0.3, -0.1, 0.1, 0.3, 0.5, 0.9, -0.9, -0.7, -0.5, -0.3},
{0.4, 0.4, -0.3, -1.0, 0.3, -0.2, -0.9, 0.5, -0.3, -1.0, 0.6, -0.2, -0.9},
{0.9, -0.5, -0.1, 0.3, 1, -0.7, -0.3, 0.1, 0.7, -0.9, -0.5, 0.2, 0.6},
{0.5, 0.6, 0.1, -0.2, -0.7, 0.8, 0.6, 0.1, -0.5, -0.7, 0.7, 0.3, 0.0},
}

headerData := pterm.HeatmapAxis{
XAxis: []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"},
YAxis: []string{"1", "2", "3", "4", "5"},
}

pterm.Println("The following table has no rgb (supported by every terminal), no axis data and no legend.\n")
MarvinJWendt marked this conversation as resolved.
Show resolved Hide resolved

table := pterm.DefaultHeatmap.WithData(data).WithBoxed(false).WithAxisData(headerData).WithLegend(false)
table.Render()
}