Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add heatmap render method, optimize virtual-terminal (testing and some output), and more docs/testing
- Loading branch information
Showing
17 changed files
with
572 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"rare/cmd/helpers" | ||
"rare/pkg/aggregation" | ||
"rare/pkg/color" | ||
"rare/pkg/expressions" | ||
"rare/pkg/multiterm" | ||
"rare/pkg/multiterm/termrenderers" | ||
|
||
"github.com/urfave/cli" | ||
) | ||
|
||
func heatmapFunction(c *cli.Context) error { | ||
var ( | ||
delim = c.String("delim") | ||
numRows = c.Int("num") | ||
numCols = c.Int("cols") | ||
minFixed = c.IsSet("min") | ||
minVal = c.Int64("min") | ||
maxFixed = c.IsSet("max") | ||
maxVal = c.Int64("max") | ||
) | ||
|
||
counter := aggregation.NewTable(delim) | ||
|
||
batcher := helpers.BuildBatcherFromArguments(c) | ||
ext := helpers.BuildExtractorFromArguments(c, batcher) | ||
|
||
writer := termrenderers.NewHeatmap(multiterm.New(), numRows, numCols) | ||
|
||
writer.FixedMin = minFixed | ||
writer.FixedMax = maxFixed | ||
if minFixed || maxFixed { | ||
writer.UpdateMinMax(minVal, maxVal) | ||
} | ||
|
||
helpers.RunAggregationLoop(ext, counter, func() { | ||
writer.WriteTable(counter) | ||
writer.WriteFooter(0, helpers.FWriteExtractorSummary(ext, counter.ParseErrors(), | ||
fmt.Sprintf("(R: %v; C: %v)", color.Wrapi(color.Yellow, counter.RowCount()), color.Wrapi(color.BrightBlue, counter.ColumnCount())))) | ||
writer.WriteFooter(1, batcher.StatusString()) | ||
}) | ||
|
||
return helpers.DetermineErrorState(batcher, ext, counter) | ||
} | ||
|
||
func heatmapCommand() *cli.Command { | ||
return helpers.AdaptCommandForExtractor(cli.Command{ | ||
Name: "heatmap", | ||
Aliases: []string{"heat"}, | ||
ShortName: "hm", | ||
Usage: "Create a 2D heatmap of extracted data", | ||
Description: `Creates a dense 2D visual of extracted data. Each character | ||
represents a single data-point, and can create an alternative visualization to | ||
a table. Unicode and color support required for effective display`, | ||
Action: heatmapFunction, | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "delim", | ||
Usage: "Character to tabulate on. Use {$} helper by default", | ||
Value: expressions.ArraySeparatorString, | ||
}, | ||
cli.IntFlag{ | ||
Name: "num,n,rows", | ||
Usage: "Number of elements (rows) to display", | ||
Value: 20, | ||
}, | ||
cli.IntFlag{ | ||
Name: "cols", | ||
Usage: "Number of columns to display", | ||
Value: multiterm.TermCols() - 15, | ||
}, | ||
cli.Int64Flag{ | ||
Name: "min", | ||
Usage: "Sets the lower bounds of the heatmap (default: auto)", | ||
}, | ||
cli.Int64Flag{ | ||
Name: "max", | ||
Usage: "Sets the upper bounds of the heatmap (default: auto)", | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package cmd | ||
|
||
import "testing" | ||
|
||
func TestHeatmap(t *testing.T) { | ||
testCommandSet(t, heatmapCommand(), | ||
`-m "(.+) (\d+)" -e "{$ {1} {2}}" testdata/graph.txt`, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.