Merge branch 'master' of github.com:wcharczuk/go-chart

This commit is contained in:
Will Charczuk 2017-02-26 01:03:53 -08:00
commit 9a9af15fd4
5 changed files with 27 additions and 11 deletions

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"log"
"net/http" "net/http"
"github.com/wcharczuk/go-chart" "github.com/wcharczuk/go-chart"
@ -38,5 +39,5 @@ func drawChartWide(res http.ResponseWriter, req *http.Request) {
func main() { func main() {
http.HandleFunc("/", drawChart) http.HandleFunc("/", drawChart)
http.HandleFunc("/wide", drawChartWide) http.HandleFunc("/wide", drawChartWide)
http.ListenAndServe(":8080", nil) log.Fatal(http.ListenAndServe(":8080", nil))
} }

View file

@ -55,7 +55,7 @@ func TestAnnotationSeriesMeasure(t *testing.T) {
assert.False(box.IsZero()) assert.False(box.IsZero())
assert.Equal(-5.0, box.Top) assert.Equal(-5.0, box.Top)
assert.Equal(5.0, box.Left) 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) assert.Equal(115.0, box.Bottom)
} }

View file

@ -97,6 +97,8 @@ func (c Chart) Render(rp RendererProvider, w io.Writer) error {
err = c.checkRanges(xr, yr, yra) err = c.checkRanges(xr, yr, yra)
if err != nil { if err != nil {
// (try to) dump the raw background to the stream.
r.Save(w)
return err return err
} }
@ -461,7 +463,7 @@ func (c Chart) styleDefaultsBackground() Style {
return Style{ return Style{
FillColor: DefaultBackgroundColor, FillColor: DefaultBackgroundColor,
StrokeColor: DefaultBackgroundStrokeColor, StrokeColor: DefaultBackgroundStrokeColor,
StrokeWidth: DefaultStrokeWidth, StrokeWidth: DefaultBackgroundStrokeWidth,
} }
} }
@ -469,7 +471,7 @@ func (c Chart) styleDefaultsCanvas() Style {
return Style{ return Style{
FillColor: DefaultCanvasColor, FillColor: DefaultCanvasColor,
StrokeColor: DefaultCanvasStrokeColor, StrokeColor: DefaultCanvasStrokeColor,
StrokeWidth: DefaultStrokeWidth, StrokeWidth: DefaultCanvasStrokeWidth,
} }
} }
@ -477,7 +479,7 @@ func (c Chart) styleDefaultsSeries(seriesIndex int) Style {
strokeColor := GetDefaultColor(seriesIndex) strokeColor := GetDefaultColor(seriesIndex)
return Style{ return Style{
StrokeColor: strokeColor, StrokeColor: strokeColor,
StrokeWidth: DefaultStrokeWidth, StrokeWidth: DefaultSeriesLineWidth,
Font: c.GetFont(), Font: c.GetFont(),
FontSize: DefaultFontSize, FontSize: DefaultFontSize,
} }

View file

@ -12,8 +12,10 @@ const (
DefaultChartHeight = 400 DefaultChartHeight = 400
// DefaultChartWidth is the default chart width. // DefaultChartWidth is the default chart width.
DefaultChartWidth = 1024 DefaultChartWidth = 1024
// DefaultStrokeWidth is the default chart line/stroke width. // DefaultStrokeWidth is the default chart stroke width.
DefaultStrokeWidth = 1.0 DefaultStrokeWidth = 0.0
// DefaultSeriesLineWidth is the default line width.
DefaultSeriesLineWidth = 1.0
// DefaultAxisLineWidth is the line width of the axis lines. // DefaultAxisLineWidth is the line width of the axis lines.
DefaultAxisLineWidth = 1.0 DefaultAxisLineWidth = 1.0
//DefaultDPI is the default dots per inch for the chart. //DefaultDPI is the default dots per inch for the chart.
@ -33,6 +35,11 @@ const (
// DefaultTitleTop is the default distance from the top of the chart to put the title. // DefaultTitleTop is the default distance from the top of the chart to put the title.
DefaultTitleTop = 10 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 is the default vertical distance between lines of text.
DefaultLineSpacing = 5 DefaultLineSpacing = 5
@ -103,6 +110,9 @@ var (
ColorAlternateYellow = drawing.Color{R: 240, G: 174, B: 90, A: 255} ColorAlternateYellow = drawing.Color{R: 240, G: 174, B: 90, A: 255}
// ColorAlternateLightGray is a alternate theme color. // ColorAlternateLightGray is a alternate theme color.
ColorAlternateLightGray = drawing.Color{R: 187, G: 190, B: 191, A: 255} ColorAlternateLightGray = drawing.Color{R: 187, G: 190, B: 191, A: 255}
// ColorTransparent is a transparent (alpha zero) color.
ColorTransparent = drawing.Color{R: 1, G: 1, B: 1, A: 0}
) )
var ( var (
@ -171,6 +181,11 @@ var (
DashArrayDashesLarge = []int{10, 10} 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. // GetDefaultColor returns a color from the default list by index.
// NOTE: the index will wrap around (using a modulo). // NOTE: the index will wrap around (using a modulo).
func GetDefaultColor(index int) drawing.Color { func GetDefaultColor(index int) drawing.Color {

View file

@ -4,8 +4,6 @@ import (
"bufio" "bufio"
"io" "io"
"os" "os"
exception "github.com/blendlabs/go-exception"
) )
var ( var (
@ -26,7 +24,7 @@ func (fu fileUtil) ReadByLines(filePath string, handler func(line string)) error
handler(line) handler(line)
} }
} else { } else {
return exception.Wrap(err) return err
} }
return nil return nil
} }
@ -46,7 +44,7 @@ func (fu fileUtil) ReadByChunks(filePath string, chunkSize int, handler func(lin
handler(readData) handler(readData)
} }
} else { } else {
return exception.Wrap(err) return err
} }
return nil return nil
} }