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

release candidate of v1.0.0 #2

Merged
merged 9 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: go
go:
- 1.12
env:
global:
- GO111MODULE=on
- secure: jsI88hoE5j+ffbxf6hvbA7mtkizkHrmd/RmqFncATUAgE7ny8W0P1pN9wXqncMD/9YaG7cic1H/+NuYuH+cU/GHKkAR2AY8Rbf+4uGiATMfG7tuySVYDdwdYEQKcKXJ6rHSU8oNLBVckZJNv1bqk+LEHhzEXUI7sFEwxvcmTb/zH8TXf5TyTpquW9CWwzsudbl6RRYuzU2DIFBh99/4umY/94FHOHnxm/AENMnsiIjRCZtdqpVdvtaY43rQphotmzR+5IwvMaT/7jxwtksR5HAuEZ2eFQd1+mpOeqddZJ3eigx/DvTkH6N22NmAZL3b2oJKzBDAJCjz/f6rBiEpZBlO8fSHKKMR3XZySbJgNEL7TYr6jEKwNsFo5Bkcj2qKtrPwswxTCihPVBb2QhimN7zvCFi1KgZRcUr4d+FP6YGXsFoBRggDpeNt1x2EXjusfHEnuJY/uoypwJSi2vlGqXuNb45nBVUXS5CIz/kTr2KwYT9sPn/V59TiEuqefX3D3PASzQY/NVd4gcPSZCAXUMs0IA50qfo3/sBW/tFABdhcMhzjEOHc0fJeUAFn+w8O2xmigifUdqh6nPh/4TODSWwlFk+icwDDNdInAOCxThGHamuB1Jlr4P7UvG1itUnQT8hnAcRe8/VjD8b9QGIR9mLbCVFYpAc7PfbN3hrRgzgc=
before_script:
- go get github.com/mattn/goveralls
script:
- make test build
- "$GOPATH/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ update_version:
@echo "Replace version to \"${VERSION}\""

test: setup
$(GO) test -covermode=count -coverprofile=coverage.out $$(go list ./... | grep -v vendor)
$(GO) test -covermode=count -coverprofile=coverage.out $$(go list ./...)

build: setup
cd cmd/heatman; $(GO) build -o $(NAME) -v
Expand Down
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,66 @@
[![Build Status](https://travis-ci.com/tamada/goheatman.svg?branch=master)](https://travis-ci.com/tamada/goheatman)
[![Coverage Status](https://coveralls.io/repos/github/tamada/goheatman/badge.svg?branch=master)](https://coveralls.io/github/tamada/goheatman?branch=master)

# goheatman

Create heat map image from given csv file.
Go language implementation of [tamada/heatman](https://github.com/tamada/heatman).

## Usage

```sh
$ heatman -h both testdata/sample.csv
# generate heatman.png.
$ heatman -H # print the following help message.
heatman [OPTIONS] [CSVFILE]
OPTIONS
-a, --additional-line-gap <GAP> specifies the gap of assistant lines per cells.
if GAP is less equals than 0, no assistant lines are drawn.
-c, --color <TYPE> specifies heatmap color type (color or gray), default: color.
-d, --dest <DEST> specifies the destination file.
-h, --headers <HEADER> specifies header model (both, row, column, or no), default: no.
-p, --pixel <SIZE> specifies the pixel size per cell.
-s, --scaler generates scaler of heatmap. If this option was specified,
additional-line-gap, headers, pixel, and CSVFILE are ignored.
-H, --help print this message.
ARGUMENTS
CSVFILE input csv files with no headers.
if no csv files are specified, heatman read csv from stdin.
The value of each cell must be 0.0 to 1.0.
$ heatman -p 15 -a 4 -h both -d heatman2.png testdata/sample.csv
# generate heatmap2.png.
$ heatman -p 15 -h both --color gray -d heatman3.png testdata/sample.csv
# generate heatmap3.png in gray scale.
$ heatman --scaler -d heatman_scaler.png
# generate heatmap_scaler.png which shows scaler of colors.
```

### The Results

Each image is generated by above command. The sources of below images are same.

#### heatman.png

![heatman.png](https://github.com/tamada/goheatman/raw/master/testdata/heatman.png)

It was too small.
The one cell in csv is shown in one pixel square.

#### heatman2.png

The one cell in csv is shown in 15-pixel square, and the auxiliary lines are drawn by 4 cells.

![heatman2.png](https://github.com/tamada/heatman/raw/master/testdata/heatman2.png)

#### heatman_gray.png

The image is gray-scaled heatmap.

![heatman3.png](https://github.com/tamada/heatman/raw/master/testdata/heatman_gray.png)

#### heatman_scaler.png

This is generated scaler image.
The most right side shows 1.0, and the most left side represents 0.0.

![heatman_scaler.png](https://github.com/tamada/heatman/raw/master/testdata/heatman_scaler.png)
41 changes: 27 additions & 14 deletions cmd/heatman/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ func printHelp(programName string) {
fmt.Printf(`%s [OPTIONS] [CSVFILE]
OPTIONS
-a, --additional-line-gap <GAP> specifies the gap of assistant lines per cells.
if the value is less equals than 0, no assistant lines are drawn.
-c, --color <TYPE> specifies heatmap color type (default or gray), default: default
if GAP is less equals than 0, no assistant lines are drawn.
-c, --color <TYPE> specifies heatmap color type (color or gray), default: color.
-d, --dest <DEST> specifies the destination file.
-h, --headers <HEADER> specifies header model (both, row, column, or no), default: no.
-H, --help print this message.
-p, --pixel <SIZE> specifies the pixel size per cell.
-s, --scaler generates scaler of heatmap. If this option was specified,
additional-line-gap, headers, pixel, and CSVFILE are ignored.
-H, --help print this message.
ARGUMENTS
CSVFILE input csv files with no headers.
if no csv files are specified, heatman read csv from stdin.
The value of each cell must be 0.0 to 1.0
The value of each cell must be 0.0 to 1.0.
`, programName)
}

Expand All @@ -36,26 +38,28 @@ type options struct {
heatmapType string
headerType string
helpFlag bool
scalerFlag bool
}

func buildFlagSet() (*flag.FlagSet, *options) {
var options = options{context: &heatman.Context{}, headerType: "no", helpFlag: false}
var flags = flag.NewFlagSet(heatmanName, flag.ContinueOnError)
flags.Usage = func() { printHelp(heatmanName) }
flags.StringVarP(&options.context.Destination, "dest", "d", "heatman.png", "specifies the destination file")
flags.IntVarP(&options.context.SizeOfAPixel, "pixelSize", "p", 1, "pixel size per cell")
flags.IntVarP(&options.context.SizeOfAPixel, "pixel", "p", 1, "pixel size per cell")
flags.IntVarP(&options.context.GapOfAdditionalLine, "additional-line-gap", "a", 0, "if greater than 0, draw assistant lines per specified number of cells")
flags.StringVarP(&options.headerType, "headers", "h", "no", "header model (both, row, column, or no), default: no")
flags.StringVarP(&options.heatmapType, "color", "c", "default", "specifies heatmap color type (default or gray)")
flags.StringVarP(&options.heatmapType, "color", "c", "color", "specifies heatmap color type (default or gray)")
flags.BoolVarP(&options.scalerFlag, "scaler", "s", false, "generates scaler")
flags.BoolVarP(&options.helpFlag, "help", "H", false, "print this message.")
return flags, &options
}

func findInput(flags *flag.FlagSet) (*os.File, error) {
if len(flags.Args()) == 1 {
func findInput(args []string) (*os.File, error) {
if len(args) == 1 {
return os.Stdin, nil
}
return os.Open(flags.Arg(1))
return os.Open(args[1])
}

func printError(err error) int {
Expand All @@ -74,17 +78,23 @@ func writeImage(image image.Image, context *heatman.Context) error {
return png.Encode(to, image)
}

func perform(flags *flag.FlagSet, context *heatman.Context) int {
if len(flags.Args()) > 2 {
func perform(args []string, context *heatman.Context, scalerFlag bool) int {
if len(args) > 2 {
printHelp(heatmanName)
return 1
}
var from, err = findInput(flags)
var from, err = findInput(args)
if err != nil {
return printError(err)
}
defer from.Close()
var image = heatman.NewTable(csv.NewReader(from), context)
var image image.Image
if scalerFlag {
image = heatman.ScalerImage(context)
} else {
image = heatman.NewTable(csv.NewReader(from), context)

}
var err2 = writeImage(image, context)
if err2 != nil {
return printError(err2)
Expand All @@ -105,6 +115,9 @@ func parseOptions(flags *flag.FlagSet, opts *options, args []string) error {
if err != nil {
return err
}
if opts.context.GapOfAdditionalLine < 0 {
opts.context.GapOfAdditionalLine = 0
}
return nil
}

Expand All @@ -118,7 +131,7 @@ func goMain() int {
printHelp(heatmanName)
return 0
}
return perform(flags, opts.context)
return perform(flags.Args(), opts.context, opts.scalerFlag)
}

func main() {
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/tamada/goheatman

go 1.12

require github.com/ogier/pflag v0.0.1
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/ogier/pflag v0.0.1 h1:RW6JSWSu/RkSatfcLtogGfFgpim5p7ARQ10ECk5O750=
github.com/ogier/pflag v0.0.1/go.mod h1:zkFki7tvTa0tafRvTBIZTvzYyAu6kQhPZFnshFFPE+g=
Loading