From d88ba0ead310ef3e6a2afc21a042cf0b5119957b Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Wed, 22 Feb 2017 17:15:13 -0800 Subject: [PATCH 1/6] removing exception dep, saving blank canvas on checkRanges err --- _examples/basic/main.go | 3 ++- chart.go | 2 ++ file_util.go | 6 ++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/_examples/basic/main.go b/_examples/basic/main.go index 2e86ac5..215c4e4 100644 --- a/_examples/basic/main.go +++ b/_examples/basic/main.go @@ -1,6 +1,7 @@ package main import ( + "log" "net/http" "github.com/wcharczuk/go-chart" @@ -38,5 +39,5 @@ func drawChartWide(res http.ResponseWriter, req *http.Request) { func main() { http.HandleFunc("/", drawChart) http.HandleFunc("/wide", drawChartWide) - http.ListenAndServe(":8080", nil) + log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/chart.go b/chart.go index 7dee166..9d00254 100644 --- a/chart.go +++ b/chart.go @@ -97,6 +97,8 @@ func (c Chart) Render(rp RendererProvider, w io.Writer) error { err = c.checkRanges(xr, yr, yra) if err != nil { + // (try to) dump the raw background to the stream. + r.Save(w) return err } diff --git a/file_util.go b/file_util.go index 7fd66bf..504f3de 100644 --- a/file_util.go +++ b/file_util.go @@ -4,8 +4,6 @@ import ( "bufio" "io" "os" - - exception "github.com/blendlabs/go-exception" ) var ( @@ -26,7 +24,7 @@ func (fu fileUtil) ReadByLines(filePath string, handler func(line string)) error handler(line) } } else { - return exception.Wrap(err) + return err } return nil } @@ -46,7 +44,7 @@ func (fu fileUtil) ReadByChunks(filePath string, chunkSize int, handler func(lin handler(readData) } } else { - return exception.Wrap(err) + return err } return nil } From f986c3c075959286ec732761e1344eb65198b45c Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Wed, 22 Feb 2017 17:34:23 -0800 Subject: [PATCH 2/6] adding some color helpers --- defaults.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/defaults.go b/defaults.go index 482d489..f6d13d3 100644 --- a/defaults.go +++ b/defaults.go @@ -103,6 +103,9 @@ var ( ColorAlternateYellow = drawing.Color{R: 240, G: 174, B: 90, A: 255} // ColorAlternateLightGray is a alternate theme color. ColorAlternateLightGray = drawing.Color{R: 187, G: 190, B: 191, A: 255} + + // ColorTransparent is a transparent (alpha zero) color. + ColorTransparent = drawing.Color{R: 0, G: 0, B: 0, A: 0} ) var ( @@ -171,6 +174,11 @@ var ( DashArrayDashesLarge = []int{10, 10} ) +// NewColor returns a new color. +func NewColor(r, g, b, a uint8) drawing.Color { + return drawing.Color{R: r, G: g, B: b, A: a} +} + // GetDefaultColor returns a color from the default list by index. // NOTE: the index will wrap around (using a modulo). func GetDefaultColor(index int) drawing.Color { From 0cbdb3d88c901784e51321c6e1095d761d4c07bd Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Wed, 22 Feb 2017 17:40:59 -0800 Subject: [PATCH 3/6] transparent was also zero, needs to have values set. --- defaults.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/defaults.go b/defaults.go index f6d13d3..778678d 100644 --- a/defaults.go +++ b/defaults.go @@ -105,7 +105,7 @@ var ( ColorAlternateLightGray = drawing.Color{R: 187, G: 190, B: 191, A: 255} // ColorTransparent is a transparent (alpha zero) color. - ColorTransparent = drawing.Color{R: 0, G: 0, B: 0, A: 0} + ColorTransparent = drawing.Color{R: 1, G: 1, B: 1, A: 0} ) var ( From 84e7baf2ef1f7269bc8122644600d76dee57bc50 Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Wed, 22 Feb 2017 17:44:44 -0800 Subject: [PATCH 4/6] defaults --- chart.go | 4 ++-- defaults.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/chart.go b/chart.go index 9d00254..c3aeeb9 100644 --- a/chart.go +++ b/chart.go @@ -463,7 +463,7 @@ func (c Chart) styleDefaultsBackground() Style { return Style{ FillColor: DefaultBackgroundColor, StrokeColor: DefaultBackgroundStrokeColor, - StrokeWidth: DefaultStrokeWidth, + StrokeWidth: DefaultBackgroundStrokeWidth, } } @@ -471,7 +471,7 @@ func (c Chart) styleDefaultsCanvas() Style { return Style{ FillColor: DefaultCanvasColor, StrokeColor: DefaultCanvasStrokeColor, - StrokeWidth: DefaultStrokeWidth, + StrokeWidth: DefaultCanvasStrokeWidth, } } diff --git a/defaults.go b/defaults.go index 778678d..6255d54 100644 --- a/defaults.go +++ b/defaults.go @@ -33,6 +33,11 @@ const ( // DefaultTitleTop is the default distance from the top of the chart to put the title. DefaultTitleTop = 10 + // DefaultBackgroundStrokeWidth is the default stroke on the chart background. + DefaultBackgroundStrokeWidth = 0.0 + // DefaultCanvasStrokeWidth is the default stroke on the chart canvas. + DefaultCanvasStrokeWidth = 0.0 + // DefaultLineSpacing is the default vertical distance between lines of text. DefaultLineSpacing = 5 From 8b967158fd047abf0850fee0f4fd62bd700739ef Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Wed, 22 Feb 2017 17:47:08 -0800 Subject: [PATCH 5/6] defaults are hard. --- chart.go | 2 +- defaults.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/chart.go b/chart.go index c3aeeb9..1b2bd7f 100644 --- a/chart.go +++ b/chart.go @@ -479,7 +479,7 @@ func (c Chart) styleDefaultsSeries(seriesIndex int) Style { strokeColor := GetDefaultColor(seriesIndex) return Style{ StrokeColor: strokeColor, - StrokeWidth: DefaultStrokeWidth, + StrokeWidth: DefaultSeriesLineWidth, Font: c.GetFont(), FontSize: DefaultFontSize, } diff --git a/defaults.go b/defaults.go index 6255d54..17e48cb 100644 --- a/defaults.go +++ b/defaults.go @@ -12,8 +12,10 @@ const ( DefaultChartHeight = 400 // DefaultChartWidth is the default chart width. DefaultChartWidth = 1024 - // DefaultStrokeWidth is the default chart line/stroke width. - DefaultStrokeWidth = 1.0 + // DefaultStrokeWidth is the default chart stroke width. + DefaultStrokeWidth = 0.0 + // DefaultSeriesLineWidth is the default line width. + DefaultSeriesLineWidth = 1.0 // DefaultAxisLineWidth is the line width of the axis lines. DefaultAxisLineWidth = 1.0 //DefaultDPI is the default dots per inch for the chart. From 5bcde786bf23de4cf4f471fa9770850092f13d68 Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Wed, 22 Feb 2017 17:48:32 -0800 Subject: [PATCH 6/6] these tests are not a joke --- annotation_series_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/annotation_series_test.go b/annotation_series_test.go index 4437f82..8945836 100644 --- a/annotation_series_test.go +++ b/annotation_series_test.go @@ -55,7 +55,7 @@ func TestAnnotationSeriesMeasure(t *testing.T) { assert.False(box.IsZero()) assert.Equal(-5.0, box.Top) assert.Equal(5.0, box.Left) - assert.Equal(147.0, box.Right) //the top,left annotation sticks up 5px and out ~44px. + assert.Equal(146.0, box.Right) //the top,left annotation sticks up 5px and out ~44px. assert.Equal(115.0, box.Bottom) }