diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..007a11c --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,14 @@ +version: 2 +jobs: + build: + working_directory: /go/src/github.com/wcharczuk/go-chart + docker: + - image: circleci/golang:1.15 + steps: + - checkout + - run: + name: new-install + command: make new-install + - run: + name: Continuous Integration + command: make \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index b48761c..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: "Continuous Integration" - -on: - workflow_dispatch: - push: - branches: [ main ] - paths: [ "*.go" ] - pull_request: - branches: [ main ] - paths: [ "*.go" ] - -jobs: - ci: - name: "Tests" - runs-on: ubuntu-latest - - env: - GOOS: "linux" - GOARCH: "amd64" - GO111MODULE: "on" - CGO_ENABLED: "0" - - steps: - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: 1.21 - - - name: Check out go-incr - uses: actions/checkout@v3 - - - name: Run all tests - run: go test ./... diff --git a/LICENSE b/LICENSE index a1ec28f..8d9f1c5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,6 @@ MIT License Copyright (c) 2016 William Charczuk. -Copyright (c) 2024 Zeni Kim. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 872548b..735b884 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ go-chart ======== +[![CircleCI](https://circleci.com/gh/wcharczuk/go-chart.svg?style=svg)](https://circleci.com/gh/wcharczuk/go-chart) [![Go Report Card](https://goreportcard.com/badge/github.com/wcharczuk/go-chart)](https://goreportcard.com/report/github.com/wcharczuk/go-chart) -This project starts from a full copy from [https://git.smarteching.com/zeni/go-chart](https://git.smarteching.com/zeni/go-chart). 28 Oct 2024. - -- +Package `chart` is a very simple golang native charting library that supports timeseries and continuous line charts. Master should now be on the v3.x codebase, which overhauls the api significantly. Per usual, see `examples` for more information. @@ -12,7 +11,7 @@ Master should now be on the v3.x codebase, which overhauls the api significantly To install `chart` run the following: ```bash -> go get git.smarteching.com/zeni/go-chart/v2@latest +> go get github.com/wcharczuk/go-chart@latest ``` Most of the components are interchangeable so feel free to crib whatever you want. @@ -21,27 +20,27 @@ Most of the components are interchangeable so feel free to crib whatever you wan Spark Lines: -![](https://git.smarteching.com/zeni/go-chart/raw/branch/main/_images/tvix_ltm.png) +![](https://raw.githubusercontent.com/wcharczuk/go-chart/master/_images/tvix_ltm.png) Single axis: -![](https://git.smarteching.com/zeni/go-chart/raw/branch/main/_images/goog_ltm.png) +![](https://raw.githubusercontent.com/wcharczuk/go-chart/master/_images/goog_ltm.png) Two axis: -![](https://git.smarteching.com/zeni/go-chart/raw/branch/main/_images/two_axis.png) +![](https://raw.githubusercontent.com/wcharczuk/go-chart/master/_images/two_axis.png) # Other Chart Types Pie Chart: -![](https://git.smarteching.com/zeni/go-chart/raw/branch/main/_images/pie_chart.png) +![](https://raw.githubusercontent.com/wcharczuk/go-chart/master/_images/pie_chart.png) The code for this chart can be found in `examples/pie_chart/main.go`. Stacked Bar: -![](https://git.smarteching.com/zeni/go-chart/raw/branch/main/_images/stacked_bar.png) +![](https://raw.githubusercontent.com/wcharczuk/go-chart/master/_images/stacked_bar.png) The code for this chart can be found in `examples/stacked_bar/main.go`. @@ -49,8 +48,6 @@ The code for this chart can be found in `examples/stacked_bar/main.go`. Actual chart configurations and examples can be found in the `./examples/` directory. They are simple CLI programs that write to `output.png` (they are also updated with `go generate`. -If folder ends in "web", has web servers, so start them with `go run main.go` then access `http://localhost:8080` to see the output. - # Usage Everything starts with the `chart.Chart` object. The bare minimum to draw a chart would be the following: @@ -61,7 +58,7 @@ import ( ... "bytes" ... - "git.smarteching.com/zeni/go-chart/v2" //exposes "chart" + "github.com/wcharczuk/go-chart" //exposes "chart" ) graph := chart.Chart{ diff --git a/_colors/colors_extended.txt b/_colors/colors_extended.txt deleted file mode 100644 index 65cd288..0000000 --- a/_colors/colors_extended.txt +++ /dev/null @@ -1,147 +0,0 @@ -aliceblue #f0f8ff 240,248,255 -antiquewhite #faebd7 250,235,215 -aqua #00ffff 0,255,255 -aquamarine #7fffd4 127,255,212 -azure #f0ffff 240,255,255 -beige #f5f5dc 245,245,220 -bisque #ffe4c4 255,228,196 -black #000000 0,0,0 -blanchedalmond #ffebcd 255,235,205 -blue #0000ff 0,0,255 -blueviolet #8a2be2 138,43,226 -brown #a52a2a 165,42,42 -burlywood #deb887 222,184,135 -cadetblue #5f9ea0 95,158,160 -chartreuse #7fff00 127,255,0 -chocolate #d2691e 210,105,30 -coral #ff7f50 255,127,80 -cornflowerblue #6495ed 100,149,237 -cornsilk #fff8dc 255,248,220 -crimson #dc143c 220,20,60 -cyan #00ffff 0,255,255 -darkblue #00008b 0,0,139 -darkcyan #008b8b 0,139,139 -darkgoldenrod #b8860b 184,134,11 -darkgray #a9a9a9 169,169,169 -darkgreen #006400 0,100,0 -darkgrey #a9a9a9 169,169,169 -darkkhaki #bdb76b 189,183,107 -darkmagenta #8b008b 139,0,139 -darkolivegreen #556b2f 85,107,47 -darkorange #ff8c00 255,140,0 -darkorchid #9932cc 153,50,204 -darkred #8b0000 139,0,0 -darksalmon #e9967a 233,150,122 -darkseagreen #8fbc8f 143,188,143 -darkslateblue #483d8b 72,61,139 -darkslategray #2f4f4f 47,79,79 -darkslategrey #2f4f4f 47,79,79 -darkturquoise #00ced1 0,206,209 -darkviolet #9400d3 148,0,211 -deeppink #ff1493 255,20,147 -deepskyblue #00bfff 0,191,255 -dimgray #696969 105,105,105 -dimgrey #696969 105,105,105 -dodgerblue #1e90ff 30,144,255 -firebrick #b22222 178,34,34 -floralwhite #fffaf0 255,250,240 -forestgreen #228b22 34,139,34 -fuchsia #ff00ff 255,0,255 -gainsboro #dcdcdc 220,220,220 -ghostwhite #f8f8ff 248,248,255 -gold #ffd700 255,215,0 -goldenrod #daa520 218,165,32 -gray #808080 128,128,128 -green #008000 0,128,0 -greenyellow #adff2f 173,255,47 -grey #808080 128,128,128 -honeydew #f0fff0 240,255,240 -hotpink #ff69b4 255,105,180 -indianred #cd5c5c 205,92,92 -indigo #4b0082 75,0,130 -ivory #fffff0 255,255,240 -khaki #f0e68c 240,230,140 -lavender #e6e6fa 230,230,250 -lavenderblush #fff0f5 255,240,245 -lawngreen #7cfc00 124,252,0 -lemonchiffon #fffacd 255,250,205 -lightblue #add8e6 173,216,230 -lightcoral #f08080 240,128,128 -lightcyan #e0ffff 224,255,255 -lightgoldenrodyellow #fafad2 250,250,210 -lightgray #d3d3d3 211,211,211 -lightgreen #90ee90 144,238,144 -lightgrey #d3d3d3 211,211,211 -lightpink #ffb6c1 255,182,193 -lightsalmon #ffa07a 255,160,122 -lightseagreen #20b2aa 32,178,170 -lightskyblue #87cefa 135,206,250 -lightslategray #778899 119,136,153 -lightslategrey #778899 119,136,153 -lightsteelblue #b0c4de 176,196,222 -lightyellow #ffffe0 255,255,224 -lime #00ff00 0,255,0 -limegreen #32cd32 50,205,50 -linen #faf0e6 250,240,230 -magenta #ff00ff 255,0,255 -maroon #800000 128,0,0 -mediumaquamarine #66cdaa 102,205,170 -mediumblue #0000cd 0,0,205 -mediumorchid #ba55d3 186,85,211 -mediumpurple #9370db 147,112,219 -mediumseagreen #3cb371 60,179,113 -mediumslateblue #7b68ee 123,104,238 -mediumspringgreen #00fa9a 0,250,154 -mediumturquoise #48d1cc 72,209,204 -mediumvioletred #c71585 199,21,133 -midnightblue #191970 25,25,112 -mintcream #f5fffa 245,255,250 -mistyrose #ffe4e1 255,228,225 -moccasin #ffe4b5 255,228,181 -navajowhite #ffdead 255,222,173 -navy #000080 0,0,128 -oldlace #fdf5e6 253,245,230 -olive #808000 128,128,0 -olivedrab #6b8e23 107,142,35 -orange #ffa500 255,165,0 -orangered #ff4500 255,69,0 -orchid #da70d6 218,112,214 -palegoldenrod #eee8aa 238,232,170 -palegreen #98fb98 152,251,152 -paleturquoise #afeeee 175,238,238 -palevioletred #db7093 219,112,147 -papayawhip #ffefd5 255,239,213 -peachpuff #ffdab9 255,218,185 -peru #cd853f 205,133,63 -pink #ffc0cb 255,192,203 -plum #dda0dd 221,160,221 -powderblue #b0e0e6 176,224,230 -purple #800080 128,0,128 -red #ff0000 255,0,0 -rosybrown #bc8f8f 188,143,143 -royalblue #4169e1 65,105,225 -saddlebrown #8b4513 139,69,19 -salmon #fa8072 250,128,114 -sandybrown #f4a460 244,164,96 -seagreen #2e8b57 46,139,87 -seashell #fff5ee 255,245,238 -sienna #a0522d 160,82,45 -silver #c0c0c0 192,192,192 -skyblue #87ceeb 135,206,235 -slateblue #6a5acd 106,90,205 -slategray #708090 112,128,144 -slategrey #708090 112,128,144 -snow #fffafa 255,250,250 -springgreen #00ff7f 0,255,127 -steelblue #4682b4 70,130,180 -tan #d2b48c 210,180,140 -teal #008080 0,128,128 -thistle #d8bfd8 216,191,216 -tomato #ff6347 255,99,71 -turquoise #40e0d0 64,224,208 -violet #ee82ee 238,130,238 -wheat #f5deb3 245,222,179 -white #ffffff 255,255,255 -whitesmoke #f5f5f5 245,245,245 -yellow #ffff00 255,255,0 -yellowgreen #9acd32 154,205,50 \ No newline at end of file diff --git a/examples/horizontal_stacked_bar/main.go b/_examples/horizontal_stacked_bar/main.go similarity index 95% rename from examples/horizontal_stacked_bar/main.go rename to _examples/horizontal_stacked_bar/main.go index d695b46..5151524 100644 --- a/examples/horizontal_stacked_bar/main.go +++ b/_examples/horizontal_stacked_bar/main.go @@ -3,8 +3,8 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" - "git.smarteching.com/zeni/go-chart/v2/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func main() { @@ -23,7 +23,7 @@ func main() { stackedBarChart := chart.StackedBarChart{ Title: "Quarterly Sales", - TitleStyle: chart.Shown(), + TitleStyle: chart.StyleShow(), Background: chart.Style{ Padding: chart.Box{ Top: 75, @@ -31,8 +31,8 @@ func main() { }, Width: 800, Height: 600, - XAxis: chart.Shown(), - YAxis: chart.Shown(), + XAxis: chart.StyleShow(), + YAxis: chart.StyleShow(), BarSpacing: 40, IsHorizontal: true, Bars: []chart.StackedBar{ diff --git a/examples/horizontal_stacked_bar/output.png b/_examples/horizontal_stacked_bar/output.png similarity index 100% rename from examples/horizontal_stacked_bar/output.png rename to _examples/horizontal_stacked_bar/output.png diff --git a/examples/stacked_bar_labels/main.go b/_examples/stacked_bar_labels/main.go similarity index 95% rename from examples/stacked_bar_labels/main.go rename to _examples/stacked_bar_labels/main.go index 2af9e21..a62103f 100644 --- a/examples/stacked_bar_labels/main.go +++ b/_examples/stacked_bar_labels/main.go @@ -3,8 +3,8 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" - "git.smarteching.com/zeni/go-chart/v2/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func main() { @@ -23,7 +23,7 @@ func main() { stackedBarChart := chart.StackedBarChart{ Title: "Quarterly Sales", - TitleStyle: chart.Shown(), + TitleStyle: chart.StyleShow(), Background: chart.Style{ Padding: chart.Box{ Top: 100, @@ -31,8 +31,8 @@ func main() { }, Width: 810, Height: 500, - XAxis: chart.Shown(), - YAxis: chart.Shown(), + XAxis: chart.StyleShow(), + YAxis: chart.StyleShow(), BarSpacing: 50, Bars: []chart.StackedBar{ { diff --git a/examples/stacked_bar_labels/output.png b/_examples/stacked_bar_labels/output.png similarity index 100% rename from examples/stacked_bar_labels/output.png rename to _examples/stacked_bar_labels/output.png diff --git a/annotation_series_test.go b/annotation_series_test.go index 251e8f4..1a33900 100644 --- a/annotation_series_test.go +++ b/annotation_series_test.go @@ -4,8 +4,8 @@ import ( "image/color" "testing" - "git.smarteching.com/zeni/go-chart/v2/drawing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/drawing" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestAnnotationSeriesMeasure(t *testing.T) { diff --git a/bar_chart_test.go b/bar_chart_test.go index 7bd98ee..e62ef83 100644 --- a/bar_chart_test.go +++ b/bar_chart_test.go @@ -5,7 +5,7 @@ import ( "math" "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestBarChartRender(t *testing.T) { diff --git a/bollinger_band_series_test.go b/bollinger_band_series_test.go index e281e2d..b33b0ec 100644 --- a/bollinger_band_series_test.go +++ b/bollinger_band_series_test.go @@ -5,7 +5,7 @@ import ( "math" "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestBollingerBandSeries(t *testing.T) { diff --git a/box.go b/box.go index 2641bd4..9611ff9 100644 --- a/box.go +++ b/box.go @@ -254,22 +254,6 @@ func (b Box) OuterConstrain(bounds, other Box) Box { return newBox } -func (b Box) Validate() error { - if b.Left < 0 { - return fmt.Errorf("invalid left; must be >= 0") - } - if b.Right < 0 { - return fmt.Errorf("invalid right; must be > 0") - } - if b.Top < 0 { - return fmt.Errorf("invalid top; must be > 0") - } - if b.Bottom < 0 { - return fmt.Errorf("invalid bottom; must be > 0") - } - return nil -} - // BoxCorners is a box with independent corners. type BoxCorners struct { TopLeft, TopRight, BottomRight, BottomLeft Point diff --git a/box_test.go b/box_test.go index 1670256..e62d5b7 100644 --- a/box_test.go +++ b/box_test.go @@ -4,7 +4,7 @@ import ( "math" "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestBoxClone(t *testing.T) { diff --git a/chart_test.go b/chart_test.go index 8db42fd..8026848 100644 --- a/chart_test.go +++ b/chart_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" - "git.smarteching.com/zeni/go-chart/v2/drawing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/drawing" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestChartGetDPI(t *testing.T) { @@ -573,22 +573,3 @@ func TestChartE2ELineWithFill(t *testing.T) { testutil.AssertEqual(t, defaultSeriesColor, at(i, 0, 49)) testutil.AssertEqual(t, defaultSeriesColor, at(i, 49, 0)) } - -func Test_Chart_cve(t *testing.T) { - poc := StackedBarChart{ - Title: "poc", - Bars: []StackedBar{ - { - Name: "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", - Values: []Value{ - {Value: 1, Label: "infinite"}, - {Value: 1, Label: "loop"}, - }, - }, - }, - } - - var imgContent bytes.Buffer - err := poc.Render(PNG, &imgContent) - testutil.AssertNotNil(t, err) -} diff --git a/cmd/chart/main.go b/cmd/chart/main.go index fa41bbe..82ed907 100644 --- a/cmd/chart/main.go +++ b/cmd/chart/main.go @@ -7,7 +7,7 @@ import ( "os" "strings" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) var ( diff --git a/colors.go b/colors.go index de542d8..b51f9ea 100644 --- a/colors.go +++ b/colors.go @@ -1,6 +1,6 @@ package chart -import "git.smarteching.com/zeni/go-chart/v2/drawing" +import "github.com/wcharczuk/go-chart/v2/drawing" var ( // ColorWhite is white. diff --git a/concat_series_test.go b/concat_series_test.go index f4b7491..9424fb2 100644 --- a/concat_series_test.go +++ b/concat_series_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestConcatSeries(t *testing.T) { diff --git a/continuous_range_test.go b/continuous_range_test.go index aaa7ec4..5d0f436 100644 --- a/continuous_range_test.go +++ b/continuous_range_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestRangeTranslate(t *testing.T) { diff --git a/continuous_series_test.go b/continuous_series_test.go index ec6193b..783c236 100644 --- a/continuous_series_test.go +++ b/continuous_series_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestContinuousSeries(t *testing.T) { diff --git a/donut_chart_test.go b/donut_chart_test.go index 0d1946b..388f65d 100644 --- a/donut_chart_test.go +++ b/donut_chart_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestDonutChart(t *testing.T) { diff --git a/drawing/color.go b/drawing/color.go index 4b865d7..cfe0924 100644 --- a/drawing/color.go +++ b/drawing/color.go @@ -2,46 +2,27 @@ package drawing import ( "fmt" - "regexp" "strconv" - "strings" ) -// Basic Colors from: -// https://www.w3.org/wiki/CSS/Properties/color/keywords var ( // ColorTransparent is a fully transparent color. - ColorTransparent = Color{R: 255, G: 255, B: 255, A: 0} + ColorTransparent = Color{} + // ColorWhite is white. ColorWhite = Color{R: 255, G: 255, B: 255, A: 255} + // ColorBlack is black. ColorBlack = Color{R: 0, G: 0, B: 0, A: 255} + // ColorRed is red. ColorRed = Color{R: 255, G: 0, B: 0, A: 255} + // ColorGreen is green. - ColorGreen = Color{R: 0, G: 128, B: 0, A: 255} + ColorGreen = Color{R: 0, G: 255, B: 0, A: 255} + // ColorBlue is blue. ColorBlue = Color{R: 0, G: 0, B: 255, A: 255} - // ColorSilver is a known color. - ColorSilver = Color{R: 192, G: 192, B: 192, A: 255} - // ColorMaroon is a known color. - ColorMaroon = Color{R: 128, G: 0, B: 0, A: 255} - // ColorPurple is a known color. - ColorPurple = Color{R: 128, G: 0, B: 128, A: 255} - // ColorFuchsia is a known color. - ColorFuchsia = Color{R: 255, G: 0, B: 255, A: 255} - // ColorLime is a known color. - ColorLime = Color{R: 0, G: 255, B: 0, A: 255} - // ColorOlive is a known color. - ColorOlive = Color{R: 128, G: 128, B: 0, A: 255} - // ColorYellow is a known color. - ColorYellow = Color{R: 255, G: 255, B: 0, A: 255} - // ColorNavy is a known color. - ColorNavy = Color{R: 0, G: 0, B: 128, A: 255} - // ColorTeal is a known color. - ColorTeal = Color{R: 0, G: 128, B: 128, A: 255} - // ColorAqua is a known color. - ColorAqua = Color{R: 0, G: 255, B: 255, A: 255} ) func parseHex(hex string) uint8 { @@ -49,97 +30,8 @@ func parseHex(hex string) uint8 { return uint8(v) } -// ParseColor parses a color from a string. -func ParseColor(rawColor string) Color { - if strings.HasPrefix(rawColor, "rgba") { - return ColorFromRGBA(rawColor) - } - if strings.HasPrefix(rawColor, "rgb") { - return ColorFromRGB(rawColor) - } - if strings.HasPrefix(rawColor, "#") { - return ColorFromHex(rawColor) - } - return ColorFromKnown(rawColor) -} - -var rgbaexpr = regexp.MustCompile(`rgba\((?P.+),(?P.+),(?P.+),(?P.+)\)`) - -// ColorFromRGBA returns a color from an `rgba()` css function. -func ColorFromRGBA(rgba string) (output Color) { - values := rgbaexpr.FindStringSubmatch(rgba) - for i, name := range rgbaexpr.SubexpNames() { - if i == 0 { - continue - } - if i >= len(values) { - break - } - switch name { - case "R": - value := strings.TrimSpace(values[i]) - parsed, _ := strconv.ParseInt(value, 10, 16) - output.R = uint8(parsed) - case "G": - value := strings.TrimSpace(values[i]) - parsed, _ := strconv.ParseInt(value, 10, 16) - output.G = uint8(parsed) - case "B": - value := strings.TrimSpace(values[i]) - parsed, _ := strconv.ParseInt(value, 10, 16) - output.B = uint8(parsed) - case "A": - value := strings.TrimSpace(values[i]) - parsed, _ := strconv.ParseFloat(value, 32) - if parsed > 1 { - parsed = 1 - } else if parsed < 0 { - parsed = 0 - } - output.A = uint8(parsed * 255) - } - } - return -} - -var rgbexpr = regexp.MustCompile(`rgb\((?P.+),(?P.+),(?P.+)\)`) - -// ColorFromRGB returns a color from an `rgb()` css function. -func ColorFromRGB(rgb string) (output Color) { - output.A = 255 - values := rgbexpr.FindStringSubmatch(rgb) - for i, name := range rgbaexpr.SubexpNames() { - if i == 0 { - continue - } - if i >= len(values) { - break - } - switch name { - case "R": - value := strings.TrimSpace(values[i]) - parsed, _ := strconv.ParseInt(value, 10, 16) - output.R = uint8(parsed) - case "G": - value := strings.TrimSpace(values[i]) - parsed, _ := strconv.ParseInt(value, 10, 16) - output.G = uint8(parsed) - case "B": - value := strings.TrimSpace(values[i]) - parsed, _ := strconv.ParseInt(value, 10, 16) - output.B = uint8(parsed) - } - } - return -} - // ColorFromHex returns a color from a css hex code. -// -// NOTE: it will trim a leading '#' character if present. func ColorFromHex(hex string) Color { - if strings.HasPrefix(hex, "#") { - hex = strings.TrimPrefix(hex, "#") - } var c Color if len(hex) == 3 { c.R = parseHex(string(hex[0])) * 0x11 @@ -154,46 +46,6 @@ func ColorFromHex(hex string) Color { return c } -// ColorFromKnown returns an internal color from a known (basic) color name. -func ColorFromKnown(known string) Color { - switch strings.ToLower(known) { - case "transparent": - return ColorTransparent - case "white": - return ColorWhite - case "black": - return ColorBlack - case "red": - return ColorRed - case "blue": - return ColorBlue - case "green": - return ColorGreen - case "silver": - return ColorSilver - case "maroon": - return ColorMaroon - case "purple": - return ColorPurple - case "fuchsia": - return ColorFuchsia - case "lime": - return ColorLime - case "olive": - return ColorOlive - case "yellow": - return ColorYellow - case "navy": - return ColorNavy - case "teal": - return ColorTeal - case "aqua": - return ColorAqua - default: - return Color{} - } -} - // ColorFromAlphaMixedRGBA returns the system alpha mixed rgba values. func ColorFromAlphaMixedRGBA(r, g, b, a uint32) Color { fa := float64(a) / 255.0 diff --git a/drawing/color_test.go b/drawing/color_test.go index bb01ee1..15c3244 100644 --- a/drawing/color_test.go +++ b/drawing/color_test.go @@ -1,15 +1,16 @@ package drawing import ( - "fmt" "testing" "image/color" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestColorFromHex(t *testing.T) { + // replaced new assertions helper + white := ColorFromHex("FFFFFF") testutil.AssertEqual(t, ColorWhite, white) @@ -28,11 +29,11 @@ func TestColorFromHex(t *testing.T) { shortRed := ColorFromHex("F00") testutil.AssertEqual(t, ColorRed, shortRed) - green := ColorFromHex("008000") + green := ColorFromHex("00FF00") testutil.AssertEqual(t, ColorGreen, green) - // shortGreen := ColorFromHex("0F0") - // testutil.AssertEqual(t, ColorGreen, shortGreen) + shortGreen := ColorFromHex("0F0") + testutil.AssertEqual(t, ColorGreen, shortGreen) blue := ColorFromHex("0000FF") testutil.AssertEqual(t, ColorBlue, blue) @@ -41,74 +42,12 @@ func TestColorFromHex(t *testing.T) { testutil.AssertEqual(t, ColorBlue, shortBlue) } -func TestColorFromHex_handlesHash(t *testing.T) { - withHash := ColorFromHex("#FF0000") - testutil.AssertEqual(t, ColorRed, withHash) - - withoutHash := ColorFromHex("#FF0000") - testutil.AssertEqual(t, ColorRed, withoutHash) -} - func TestColorFromAlphaMixedRGBA(t *testing.T) { + // replaced new assertions helper + black := ColorFromAlphaMixedRGBA(color.Black.RGBA()) testutil.AssertTrue(t, black.Equals(ColorBlack), black.String()) white := ColorFromAlphaMixedRGBA(color.White.RGBA()) testutil.AssertTrue(t, white.Equals(ColorWhite), white.String()) } - -func Test_ColorFromRGBA(t *testing.T) { - value := "rgba(192, 192, 192, 1.0)" - parsed := ColorFromRGBA(value) - testutil.AssertEqual(t, ColorSilver, parsed) - - value = "rgba(192,192,192,1.0)" - parsed = ColorFromRGBA(value) - testutil.AssertEqual(t, ColorSilver, parsed) - - value = "rgba(192,192,192,1.5)" - parsed = ColorFromRGBA(value) - testutil.AssertEqual(t, ColorSilver, parsed) -} - -func TestParseColor(t *testing.T) { - testCases := [...]struct { - Input string - Expected Color - }{ - {"", Color{}}, - {"white", ColorWhite}, - {"WHITE", ColorWhite}, // caps! - {"black", ColorBlack}, - {"red", ColorRed}, - {"green", ColorGreen}, - {"blue", ColorBlue}, - {"silver", ColorSilver}, - {"maroon", ColorMaroon}, - {"purple", ColorPurple}, - {"fuchsia", ColorFuchsia}, - {"lime", ColorLime}, - {"olive", ColorOlive}, - {"yellow", ColorYellow}, - {"navy", ColorNavy}, - {"teal", ColorTeal}, - {"aqua", ColorAqua}, - - {"rgba(192, 192, 192, 1.0)", ColorSilver}, - {"rgba(192,192,192,1.0)", ColorSilver}, - {"rgb(192, 192, 192)", ColorSilver}, - {"rgb(192,192,192)", ColorSilver}, - - {"#FF0000", ColorRed}, - {"#008000", ColorGreen}, - {"#0000FF", ColorBlue}, - {"#F00", ColorRed}, - {"#080", Color{0, 136, 0, 255}}, - {"#00F", ColorBlue}, - } - - for index, tc := range testCases { - actual := ParseColor(tc.Input) - testutil.AssertEqual(t, tc.Expected, actual, fmt.Sprintf("test case: %d -> %s", index, tc.Input)) - } -} diff --git a/drawing/curve_test.go b/drawing/curve_test.go index f79cb79..31abe8e 100644 --- a/drawing/curve_test.go +++ b/drawing/curve_test.go @@ -3,7 +3,7 @@ package drawing import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) type point struct { diff --git a/ema_series_test.go b/ema_series_test.go index e1e5831..184319b 100644 --- a/ema_series_test.go +++ b/ema_series_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) var ( diff --git a/examples/annotations/main.go b/examples/annotations/main.go index b9d22be..20bf01f 100644 --- a/examples/annotations/main.go +++ b/examples/annotations/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/axes/main.go b/examples/axes/main.go index 7847ffa..a675bde 100644 --- a/examples/axes/main.go +++ b/examples/axes/main.go @@ -5,7 +5,7 @@ package main import ( "os" - chart "git.smarteching.com/zeni/go-chart/v2" + chart "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/axes_labels/main.go b/examples/axes_labels/main.go index 6c9055d..a68ac34 100644 --- a/examples/axes_labels/main.go +++ b/examples/axes_labels/main.go @@ -5,7 +5,7 @@ package main import ( "os" - chart "git.smarteching.com/zeni/go-chart/v2" + chart "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/bar_chart/main.go b/examples/bar_chart/main.go index 36b45a6..2a7895f 100644 --- a/examples/bar_chart/main.go +++ b/examples/bar_chart/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/bar_chart/output.png b/examples/bar_chart/output.png index 840c46e..321a341 100644 Binary files a/examples/bar_chart/output.png and b/examples/bar_chart/output.png differ diff --git a/examples/bar_chart_base_value/main.go b/examples/bar_chart_base_value/main.go index 52fa940..f17b6b8 100644 --- a/examples/bar_chart_base_value/main.go +++ b/examples/bar_chart_base_value/main.go @@ -5,8 +5,8 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" - "git.smarteching.com/zeni/go-chart/v2/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func main() { diff --git a/examples/bar_chart_web/main.go b/examples/bar_chart_web/main.go deleted file mode 100644 index 714276e..0000000 --- a/examples/bar_chart_web/main.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -//go:generate go run main.go - -import ( - "fmt" - "log" - "net/http" - "os" - - "git.smarteching.com/zeni/go-chart/v2" -) - -func drawChart(res http.ResponseWriter, req *http.Request) { - graph := chart.BarChart{ - Title: "Test Bar Chart", - Background: chart.Style{ - Padding: chart.Box{ - Top: 40, - }, - }, - Height: 512, - BarWidth: 60, - Bars: []chart.Value{ - {Value: 5.25, Label: "Blue"}, - {Value: 4.88, Label: "Green"}, - {Value: 4.74, Label: "Gray"}, - {Value: 3.22, Label: "Orange"}, - {Value: 3, Label: "Test"}, - {Value: 2.27, Label: "??"}, - {Value: 1, Label: "!!"}, - }, - } - - res.Header().Set("Content-Type", "image/png") - err := graph.Render(chart.PNG, res) - if err != nil { - fmt.Printf("Error rendering chart: %v\n", err) - } - -} - -func port() string { - if len(os.Getenv("PORT")) > 0 { - return os.Getenv("PORT") - } - return "8080" -} - -func main() { - listenPort := fmt.Sprintf(":%s", port()) - fmt.Printf("Listening on %s\n", listenPort) - http.HandleFunc("/", drawChart) - log.Fatal(http.ListenAndServe(listenPort, nil)) -} diff --git a/examples/basic/main.go b/examples/basic/main.go index e05df6a..aeca5a8 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/benchmark_line_charts/main.go b/examples/benchmark_line_charts/main.go index e79b4d4..1a70417 100644 --- a/examples/benchmark_line_charts/main.go +++ b/examples/benchmark_line_charts/main.go @@ -8,7 +8,7 @@ import ( "os" "time" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func random(min, max float64) float64 { diff --git a/examples/css_classes/main.go b/examples/css_classes/main.go index f34a3da..b5e65cf 100644 --- a/examples/css_classes/main.go +++ b/examples/css_classes/main.go @@ -5,7 +5,7 @@ import ( "log" "net/http" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) // Note: Additional examples on how to add Stylesheets are in the custom_stylesheets example diff --git a/examples/custom_formatters/main.go b/examples/custom_formatters/main.go index fbb3317..d2b6b90 100644 --- a/examples/custom_formatters/main.go +++ b/examples/custom_formatters/main.go @@ -6,7 +6,7 @@ import ( "fmt" "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/custom_padding/main.go b/examples/custom_padding/main.go index e0d6452..14c23ec 100644 --- a/examples/custom_padding/main.go +++ b/examples/custom_padding/main.go @@ -5,8 +5,8 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" - "git.smarteching.com/zeni/go-chart/v2/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func main() { diff --git a/examples/custom_ranges/main.go b/examples/custom_ranges/main.go index 01d3899..61ef67b 100644 --- a/examples/custom_ranges/main.go +++ b/examples/custom_ranges/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/custom_styles/main.go b/examples/custom_styles/main.go index 0ee519a..08889ea 100644 --- a/examples/custom_styles/main.go +++ b/examples/custom_styles/main.go @@ -5,8 +5,8 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" - "git.smarteching.com/zeni/go-chart/v2/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func main() { diff --git a/examples/custom_stylesheets/main.go b/examples/custom_stylesheets/main.go index 51b8bbf..1af1058 100644 --- a/examples/custom_stylesheets/main.go +++ b/examples/custom_stylesheets/main.go @@ -5,7 +5,7 @@ import ( "log" "net/http" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) const style = "svg .background { fill: white; }" + diff --git a/examples/custom_ticks/main.go b/examples/custom_ticks/main.go index 9bc5aa8..f95f64d 100644 --- a/examples/custom_ticks/main.go +++ b/examples/custom_ticks/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/descending/main.go b/examples/descending/main.go index 2d2e899..62ae7f7 100644 --- a/examples/descending/main.go +++ b/examples/descending/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/donut_chart/main.go b/examples/donut_chart/main.go index 3a4e804..8b504ad 100644 --- a/examples/donut_chart/main.go +++ b/examples/donut_chart/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/image_writer/main.go b/examples/image_writer/main.go index ce0a145..4981d21 100644 --- a/examples/image_writer/main.go +++ b/examples/image_writer/main.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/legend/main.go b/examples/legend/main.go index da4c212..83b5665 100644 --- a/examples/legend/main.go +++ b/examples/legend/main.go @@ -5,7 +5,7 @@ package main import ( "os" - chart "git.smarteching.com/zeni/go-chart/v2" + chart "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/legend_left/main.go b/examples/legend_left/main.go index 1e87578..a6dc413 100644 --- a/examples/legend_left/main.go +++ b/examples/legend_left/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/linear_regression/main.go b/examples/linear_regression/main.go index 6f268f0..ebe0125 100644 --- a/examples/linear_regression/main.go +++ b/examples/linear_regression/main.go @@ -5,7 +5,7 @@ package main import ( "os" - chart "git.smarteching.com/zeni/go-chart/v2" + chart "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/logarithmic_axes/main.go b/examples/logarithmic_axes/main.go index 2a19609..9f329c8 100644 --- a/examples/logarithmic_axes/main.go +++ b/examples/logarithmic_axes/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart" ) func main() { @@ -31,7 +31,7 @@ func main() { YAxis: chart.YAxis{ Style: chart.Shown(), NameStyle: chart.Shown(), - Range: &chart.LogarithmicRange{}, + Range: &chart.LogarithmicRange{}, }, } diff --git a/examples/min_max/main.go b/examples/min_max/main.go index 78e7b1c..f2c5479 100644 --- a/examples/min_max/main.go +++ b/examples/min_max/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/pie_chart/main.go b/examples/pie_chart/main.go index 22539da..5bd7c3f 100644 --- a/examples/pie_chart/main.go +++ b/examples/pie_chart/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/pie_chart_web/main.go b/examples/pie_chart_web/main.go deleted file mode 100644 index fa25594..0000000 --- a/examples/pie_chart_web/main.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -import ( - "fmt" - "log" - "net/http" - - "git.smarteching.com/zeni/go-chart/v2" -) - -func drawChart(res http.ResponseWriter, req *http.Request) { - pie := chart.PieChart{ - Width: 512, - Height: 512, - Values: []chart.Value{ - {Value: 5, Label: "Blue"}, - {Value: 5, Label: "Green"}, - {Value: 4, Label: "Gray"}, - {Value: 4, Label: "Orange"}, - {Value: 3, Label: "Deep Blue"}, - {Value: 3, Label: "??"}, - {Value: 1, Label: "!!"}, - }, - } - - res.Header().Set("Content-Type", "image/png") - err := pie.Render(chart.PNG, res) - if err != nil { - fmt.Printf("Error rendering pie chart: %v\n", err) - } -} - -func drawChartRegression(res http.ResponseWriter, req *http.Request) { - pie := chart.PieChart{ - Width: 512, - Height: 512, - Values: []chart.Value{ - {Value: 5, Label: "Blue"}, - {Value: 2, Label: "Two"}, - {Value: 1, Label: "One"}, - }, - } - - res.Header().Set("Content-Type", chart.ContentTypeSVG) - err := pie.Render(chart.SVG, res) - if err != nil { - fmt.Printf("Error rendering pie chart: %v\n", err) - } -} - -func main() { - http.HandleFunc("/", drawChart) - http.HandleFunc("/reg", drawChartRegression) - log.Fatal(http.ListenAndServe(":8080", nil)) -} diff --git a/examples/poly_regression/main.go b/examples/poly_regression/main.go index 9f797d3..040fcc0 100644 --- a/examples/poly_regression/main.go +++ b/examples/poly_regression/main.go @@ -5,7 +5,7 @@ package main import ( "os" - chart "git.smarteching.com/zeni/go-chart/v2" + chart "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/request_timings/main.go b/examples/request_timings/main.go index 0290b65..9ca0159 100644 --- a/examples/request_timings/main.go +++ b/examples/request_timings/main.go @@ -9,7 +9,7 @@ import ( "strconv" "time" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/rerender/main.go b/examples/rerender/main.go index 50a960e..155486b 100644 --- a/examples/rerender/main.go +++ b/examples/rerender/main.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) var lock sync.Mutex diff --git a/examples/scatter/main.go b/examples/scatter/main.go index c861104..b9ce850 100644 --- a/examples/scatter/main.go +++ b/examples/scatter/main.go @@ -6,8 +6,8 @@ import ( _ "net/http/pprof" - "git.smarteching.com/zeni/go-chart/v2" - "git.smarteching.com/zeni/go-chart/v2/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func drawChart(res http.ResponseWriter, req *http.Request) { diff --git a/examples/simple_moving_average/main.go b/examples/simple_moving_average/main.go index 2d7a03c..742d15c 100644 --- a/examples/simple_moving_average/main.go +++ b/examples/simple_moving_average/main.go @@ -5,7 +5,7 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/stacked_bar/main.go b/examples/stacked_bar/main.go index 234ada3..b9537e3 100644 --- a/examples/stacked_bar/main.go +++ b/examples/stacked_bar/main.go @@ -3,7 +3,7 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/stock_analysis/main.go b/examples/stock_analysis/main.go index 4640a59..b7ccadc 100644 --- a/examples/stock_analysis/main.go +++ b/examples/stock_analysis/main.go @@ -6,8 +6,8 @@ import ( "os" "time" - "git.smarteching.com/zeni/go-chart/v2" - "git.smarteching.com/zeni/go-chart/v2/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func main() { diff --git a/examples/text_rotation/main.go b/examples/text_rotation/main.go index da41c50..28fe0ab 100644 --- a/examples/text_rotation/main.go +++ b/examples/text_rotation/main.go @@ -5,8 +5,8 @@ package main import ( "os" - "git.smarteching.com/zeni/go-chart/v2" - "git.smarteching.com/zeni/go-chart/v2/drawing" + "github.com/wcharczuk/go-chart/v2" + "github.com/wcharczuk/go-chart/v2/drawing" ) func main() { diff --git a/examples/timeseries/main.go b/examples/timeseries/main.go index 61a8fc2..1540ccd 100644 --- a/examples/timeseries/main.go +++ b/examples/timeseries/main.go @@ -4,7 +4,7 @@ import ( "net/http" "time" - chart "git.smarteching.com/zeni/go-chart/v2" + chart "github.com/wcharczuk/go-chart/v2" ) func drawChart(res http.ResponseWriter, req *http.Request) { diff --git a/examples/twoaxis/main.go b/examples/twoaxis/main.go index 62fce18..d86f362 100644 --- a/examples/twoaxis/main.go +++ b/examples/twoaxis/main.go @@ -6,7 +6,7 @@ import ( "fmt" "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/examples/twopoint/main.go b/examples/twopoint/main.go index 26a4fa1..ad46905 100644 --- a/examples/twopoint/main.go +++ b/examples/twopoint/main.go @@ -7,7 +7,7 @@ import ( "log" "os" - "git.smarteching.com/zeni/go-chart/v2" + "github.com/wcharczuk/go-chart/v2" ) func main() { diff --git a/first_value_annotation_test.go b/first_value_annotation_test.go index ea1d26d..3675763 100644 --- a/first_value_annotation_test.go +++ b/first_value_annotation_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestFirstValueAnnotation(t *testing.T) { diff --git a/font.go b/font.go index 8cb42c4..401143b 100644 --- a/font.go +++ b/font.go @@ -3,8 +3,8 @@ package chart import ( "sync" - "git.smarteching.com/zeni/go-chart/v2/roboto" "github.com/golang/freetype/truetype" + "github.com/wcharczuk/go-chart/v2/roboto" ) var ( diff --git a/go.mod b/go.mod index 53e8c70..3824b21 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ -module git.smarteching.com/zeni/go-chart/v2 +module github.com/wcharczuk/go-chart/v2 -go 1.23.1 +go 1.15 require ( github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 - golang.org/x/image v0.21.0 + golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 ) diff --git a/go.sum b/go.sum index 928ee08..066121a 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,5 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= -golang.org/x/image v0.21.0 h1:c5qV36ajHpdj4Qi0GnE0jUc/yuo33OLFaa0d+crTD5s= -golang.org/x/image v0.21.0/go.mod h1:vUbsLavqK/W303ZroQQVKQ+Af3Yl6Uz1Ppu5J/cLz78= +golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 h1:QelT11PB4FXiDEXucrfNckHoFxwt8USGY1ajP1ZF5lM= +golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/grid_line_test.go b/grid_line_test.go index cc508e1..0e96d91 100644 --- a/grid_line_test.go +++ b/grid_line_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestGenerateGridLines(t *testing.T) { diff --git a/histogram_series_test.go b/histogram_series_test.go index 75e7db6..ff0ee54 100644 --- a/histogram_series_test.go +++ b/histogram_series_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestHistogramSeries(t *testing.T) { diff --git a/jet.go b/jet.go index a539a29..cce8c85 100644 --- a/jet.go +++ b/jet.go @@ -1,6 +1,6 @@ package chart -import "git.smarteching.com/zeni/go-chart/v2/drawing" +import "github.com/wcharczuk/go-chart/v2/drawing" // Jet is a color map provider based on matlab's jet color map. func Jet(v, vmin, vmax float64) drawing.Color { diff --git a/last_value_annotation_series_test.go b/last_value_annotation_series_test.go index afc2409..59fc1b3 100644 --- a/last_value_annotation_series_test.go +++ b/last_value_annotation_series_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestLastValueAnnotationSeries(t *testing.T) { diff --git a/legend.go b/legend.go index a1dec06..fbd48ed 100644 --- a/legend.go +++ b/legend.go @@ -1,7 +1,7 @@ package chart import ( - "git.smarteching.com/zeni/go-chart/v2/drawing" + "github.com/wcharczuk/go-chart/v2/drawing" ) // Legend returns a legend renderable function. diff --git a/legend_test.go b/legend_test.go index 7adbe5d..cfc9cfa 100644 --- a/legend_test.go +++ b/legend_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestLegend(t *testing.T) { diff --git a/linear_regression_series_test.go b/linear_regression_series_test.go index 0609af8..3c13d1c 100644 --- a/linear_regression_series_test.go +++ b/linear_regression_series_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestLinearRegressionSeries(t *testing.T) { diff --git a/logarithmic_range_test.go b/logarithmic_range_test.go index 6d3879b..110f761 100644 --- a/logarithmic_range_test.go +++ b/logarithmic_range_test.go @@ -3,41 +3,44 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/blend/go-sdk/assert" ) func TestLogRangeTranslate(t *testing.T) { + assert := assert.New(t) values := []float64{1, 10, 100, 1000, 10000, 100000, 1000000} r := LogarithmicRange{Domain: 1000} r.Min, r.Max = MinMax(values...) - testutil.AssertEqual(t, 0, r.Translate(0)) // goes to bottom - testutil.AssertEqual(t, 0, r.Translate(1)) // goes to bottom - testutil.AssertEqual(t, 160, r.Translate(10)) // roughly 1/6th of max - testutil.AssertEqual(t, 500, r.Translate(1000)) // roughly 1/2 of max (1.0e6 / 1.0e3) - testutil.AssertEqual(t, 1000, r.Translate(1000000)) // max value + assert.Equal(0, r.Translate(0)) // goes to bottom + assert.Equal(0, r.Translate(1)) // goes to bottom + assert.Equal(160, r.Translate(10)) // roughly 1/6th of max + assert.Equal(500, r.Translate(1000)) // roughly 1/2 of max (1.0e6 / 1.0e3) + assert.Equal(1000, r.Translate(1000000)) // max value } func TestGetTicks(t *testing.T) { + assert := assert.New(t) values := []float64{35, 512, 1525122} r := LogarithmicRange{Domain: 1000} r.Min, r.Max = MinMax(values...) ticks := r.GetTicks(nil, Style{}, FloatValueFormatter) - testutil.AssertEqual(t, 7, len(ticks)) - testutil.AssertEqual(t, 10, ticks[0].Value) - testutil.AssertEqual(t, 100, ticks[1].Value) - testutil.AssertEqual(t, 10000000, ticks[6].Value) + assert.Equal(7, len(ticks)) + assert.Equal(10, ticks[0].Value) + assert.Equal(100, ticks[1].Value) + assert.Equal(10000000, ticks[6].Value) } func TestGetTicksFromHigh(t *testing.T) { + assert := assert.New(t) values := []float64{1412, 352144, 1525122} // min tick should be 1000 r := LogarithmicRange{} r.Min, r.Max = MinMax(values...) ticks := r.GetTicks(nil, Style{}, FloatValueFormatter) - testutil.AssertEqual(t, 5, len(ticks)) - testutil.AssertEqual(t, float64(1000), ticks[0].Value) - testutil.AssertEqual(t, float64(10000), ticks[1].Value) - testutil.AssertEqual(t, float64(10000000), ticks[4].Value) + assert.Equal(5, len(ticks)) + assert.Equal(float64(1000), ticks[0].Value) + assert.Equal(float64(10000), ticks[1].Value) + assert.Equal(float64(10000000), ticks[4].Value) } diff --git a/macd_series_test.go b/macd_series_test.go index 28404b1..6471f6d 100644 --- a/macd_series_test.go +++ b/macd_series_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) var ( diff --git a/matrix/matrix_test.go b/matrix/matrix_test.go index 3a73cec..17b8be5 100644 --- a/matrix/matrix_test.go +++ b/matrix/matrix_test.go @@ -3,7 +3,7 @@ package matrix import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestNew(t *testing.T) { diff --git a/matrix/regression_test.go b/matrix/regression_test.go index 07c868d..d43c0f4 100644 --- a/matrix/regression_test.go +++ b/matrix/regression_test.go @@ -3,7 +3,7 @@ package matrix import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestPoly(t *testing.T) { diff --git a/percent_change_series_test.go b/percent_change_series_test.go index c80d370..dbc9413 100644 --- a/percent_change_series_test.go +++ b/percent_change_series_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestPercentageDifferenceSeries(t *testing.T) { diff --git a/pie_chart_test.go b/pie_chart_test.go index 50de754..1d9f17a 100644 --- a/pie_chart_test.go +++ b/pie_chart_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestPieChart(t *testing.T) { diff --git a/polynomial_regression_series.go b/polynomial_regression_series.go index 1187192..22cd3c1 100644 --- a/polynomial_regression_series.go +++ b/polynomial_regression_series.go @@ -4,7 +4,7 @@ import ( "fmt" "math" - "git.smarteching.com/zeni/go-chart/v2/matrix" + "github.com/wcharczuk/go-chart/v2/matrix" ) // Interface Assertions. diff --git a/polynomial_regression_test.go b/polynomial_regression_test.go index 54bd655..8535c74 100644 --- a/polynomial_regression_test.go +++ b/polynomial_regression_test.go @@ -3,8 +3,8 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/matrix" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/matrix" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestPolynomialRegression(t *testing.T) { diff --git a/raster_renderer.go b/raster_renderer.go index d209ca9..4de2655 100644 --- a/raster_renderer.go +++ b/raster_renderer.go @@ -6,8 +6,8 @@ import ( "io" "math" - "git.smarteching.com/zeni/go-chart/v2/drawing" "github.com/golang/freetype/truetype" + "github.com/wcharczuk/go-chart/v2/drawing" ) // PNG returns a new png/raster renderer. diff --git a/renderer.go b/renderer.go index b16f5e4..589c773 100644 --- a/renderer.go +++ b/renderer.go @@ -3,8 +3,8 @@ package chart import ( "io" - "git.smarteching.com/zeni/go-chart/v2/drawing" "github.com/golang/freetype/truetype" + "github.com/wcharczuk/go-chart/v2/drawing" ) // Renderer represents the basic methods required to draw a chart. diff --git a/seq_test.go b/seq_test.go index 585900b..3cd7f9c 100644 --- a/seq_test.go +++ b/seq_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestSeqEach(t *testing.T) { diff --git a/sma_series_test.go b/sma_series_test.go index 3951b02..5de32a9 100644 --- a/sma_series_test.go +++ b/sma_series_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) type mockValuesProvider struct { diff --git a/stacked_bar_chart.go b/stacked_bar_chart.go index b0c781c..10aa545 100644 --- a/stacked_bar_chart.go +++ b/stacked_bar_chart.go @@ -118,18 +118,12 @@ func (sbc StackedBarChart) Render(rp RendererProvider, w io.Writer) error { var canvasBox Box if sbc.IsHorizontal { canvasBox = sbc.getHorizontalAdjustedCanvasBox(r, sbc.getDefaultCanvasBox()) - if err := canvasBox.Validate(); err != nil { - return fmt.Errorf("invalid canvas box: %w", err) - } sbc.drawCanvas(r, canvasBox) sbc.drawHorizontalBars(r, canvasBox) sbc.drawHorizontalXAxis(r, canvasBox) sbc.drawHorizontalYAxis(r, canvasBox) } else { canvasBox = sbc.getAdjustedCanvasBox(r, sbc.getDefaultCanvasBox()) - if err := canvasBox.Validate(); err != nil { - return fmt.Errorf("invalid canvas box: %w", err) - } sbc.drawCanvas(r, canvasBox) sbc.drawBars(r, canvasBox) sbc.drawXAxis(r, canvasBox) diff --git a/stringutil_test.go b/stringutil_test.go index 56a60d9..bc22b23 100644 --- a/stringutil_test.go +++ b/stringutil_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestSplitCSV(t *testing.T) { diff --git a/style.go b/style.go index 6816cf4..c601d6d 100644 --- a/style.go +++ b/style.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - "git.smarteching.com/zeni/go-chart/v2/drawing" "github.com/golang/freetype/truetype" + "github.com/wcharczuk/go-chart/v2/drawing" ) const ( diff --git a/style_test.go b/style_test.go index 5568a92..5cc1c08 100644 --- a/style_test.go +++ b/style_test.go @@ -3,9 +3,9 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/drawing" - "git.smarteching.com/zeni/go-chart/v2/testutil" "github.com/golang/freetype/truetype" + "github.com/wcharczuk/go-chart/v2/drawing" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestStyleIsZero(t *testing.T) { diff --git a/testutil/helpers.go b/testutil/helpers.go index 899d4e5..a5774a6 100644 --- a/testutil/helpers.go +++ b/testutil/helpers.go @@ -9,7 +9,6 @@ import ( // AssertNil asserts an argument is nil. func AssertNil(t *testing.T, actual interface{}) { - t.Helper() if !isNil(actual) { t.Errorf("assertion failed; expected actual to be nil") t.FailNow() @@ -18,7 +17,6 @@ func AssertNil(t *testing.T, actual interface{}) { // AssertNotNil asserts an argument is not nil. func AssertNotNil(t *testing.T, actual interface{}, message ...interface{}) { - t.Helper() if isNil(actual) { t.Error("assertion failed; expected actual to not be nil") if len(message) > 0 { @@ -30,7 +28,6 @@ func AssertNotNil(t *testing.T, actual interface{}, message ...interface{}) { // AssertEqual asserts two arguments are equal. func AssertEqual(t *testing.T, expected, actual interface{}, message ...interface{}) { - t.Helper() if !equal(expected, actual) { t.Errorf("assertion failed; expected %v to equal %v", actual, expected) if len(message) > 0 { @@ -42,7 +39,6 @@ func AssertEqual(t *testing.T, expected, actual interface{}, message ...interfac // AssertNotEqual asserts two arguments are not equal. func AssertNotEqual(t *testing.T, expected, actual interface{}, message ...interface{}) { - t.Helper() if equal(expected, actual) { t.Errorf("assertion failed; expected %v to not equal %v", actual, expected) if len(message) > 0 { @@ -54,19 +50,16 @@ func AssertNotEqual(t *testing.T, expected, actual interface{}, message ...inter // AssertZero asserts an argument is zero. func AssertZero(t *testing.T, actual interface{}, message ...interface{}) { - t.Helper() AssertEqual(t, 0, actual) } // AssertNotZero asserts an argument is not zero. func AssertNotZero(t *testing.T, actual interface{}, message ...interface{}) { - t.Helper() AssertNotEqual(t, 0, actual) } // AssertTrue asserts an argument is true. func AssertTrue(t *testing.T, arg bool, message ...interface{}) { - t.Helper() if !arg { t.Errorf("assertion failed; expected actual to be true") if len(message) > 0 { @@ -78,7 +71,6 @@ func AssertTrue(t *testing.T, arg bool, message ...interface{}) { // AssertFalse asserts an argument is false. func AssertFalse(t *testing.T, arg bool, message ...interface{}) { - t.Helper() if arg { t.Errorf("assertion failed; expected actual to be false") if len(message) > 0 { @@ -92,7 +84,6 @@ func AssertFalse(t *testing.T, arg bool, message ...interface{}) { // // This delta will be determined absolute, and the delta should always be positive. func AssertInDelta(t *testing.T, from, to, delta float64, message ...interface{}) { - t.Helper() if diff := math.Abs(from - to); diff > delta { t.Errorf("assertion failed; expected absolute difference of %f and %f to be %f", from, to, delta) if len(message) > 0 { @@ -104,7 +95,6 @@ func AssertInDelta(t *testing.T, from, to, delta float64, message ...interface{} // AssertEmpty asserts an argument is empty. func AssertEmpty(t *testing.T, arg interface{}, message ...interface{}) { - t.Helper() if getLength(arg) != 0 { t.Errorf("assertion failed; expected actual to be empty") if len(message) > 0 { @@ -116,7 +106,6 @@ func AssertEmpty(t *testing.T, arg interface{}, message ...interface{}) { // AssertNotEmpty asserts an argument is not empty. func AssertNotEmpty(t *testing.T, arg interface{}, message ...interface{}) { - t.Helper() if getLength(arg) == 0 { t.Errorf("assertion failed; expected actual to not be empty") if len(message) > 0 { @@ -128,7 +117,6 @@ func AssertNotEmpty(t *testing.T, arg interface{}, message ...interface{}) { // AssertLen asserts an argument has a given length. func AssertLen(t *testing.T, arg interface{}, length int, message ...interface{}) { - t.Helper() if getLength(arg) != length { t.Errorf("assertion failed; expected actual to have length %d", length) if len(message) > 0 { @@ -140,7 +128,6 @@ func AssertLen(t *testing.T, arg interface{}, length int, message ...interface{} // AssertContains asserts an argument contains a given substring. func AssertContains(t *testing.T, s, substr string, message ...interface{}) { - t.Helper() if !strings.Contains(s, substr) { t.Errorf("assertion failed; expected actual to contain %q", substr) if len(message) > 0 { @@ -152,7 +139,6 @@ func AssertContains(t *testing.T, s, substr string, message ...interface{}) { // AssertNotContains asserts an argument does not contain a given substring. func AssertNotContains(t *testing.T, s, substr string, message ...interface{}) { - t.Helper() if strings.Contains(s, substr) { t.Errorf("assertion failed; expected actual to not contain %q", substr) if len(message) > 0 { diff --git a/text_test.go b/text_test.go index 54a0181..4f1e209 100644 --- a/text_test.go +++ b/text_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestTextWrapWord(t *testing.T) { diff --git a/tick_test.go b/tick_test.go index 0c28d99..9ea0ef2 100644 --- a/tick_test.go +++ b/tick_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestGenerateContinuousTicks(t *testing.T) { diff --git a/time_series_test.go b/time_series_test.go index 142e78a..3f65eaf 100644 --- a/time_series_test.go +++ b/time_series_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestTimeSeriesGetValue(t *testing.T) { diff --git a/value_buffer_test.go b/value_buffer_test.go index 1b60840..e8aa9a0 100644 --- a/value_buffer_test.go +++ b/value_buffer_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestBuffer(t *testing.T) { diff --git a/value_formatter_test.go b/value_formatter_test.go index 46396dd..808400f 100644 --- a/value_formatter_test.go +++ b/value_formatter_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestTimeValueFormatterWithFormat(t *testing.T) { @@ -58,7 +58,8 @@ func TestFloatValueFormatterWithFormat(t *testing.T) { } func TestExponentialValueFormatter(t *testing.T) { - testutil.AssertEqual(t, "1.23e+02", ExponentialValueFormatter(123.456)) - testutil.AssertEqual(t, "1.24e+07", ExponentialValueFormatter(12421243.424)) - testutil.AssertEqual(t, "4.50e-01", ExponentialValueFormatter(0.45)) + assert := assert.New(t) + assert.Equal("1.23e+02", ExponentialValueFormatter(123.456)) + assert.Equal("1.24e+07", ExponentialValueFormatter(12421243.424)) + assert.Equal("4.50e-01", ExponentialValueFormatter(0.45)) } diff --git a/value_provider.go b/value_provider.go index 88b719e..be985eb 100644 --- a/value_provider.go +++ b/value_provider.go @@ -1,6 +1,6 @@ package chart -import "git.smarteching.com/zeni/go-chart/v2/drawing" +import "github.com/wcharczuk/go-chart/v2/drawing" // ValuesProvider is a type that produces values. type ValuesProvider interface { diff --git a/value_test.go b/value_test.go index 9108bfc..1c12ce7 100644 --- a/value_test.go +++ b/value_test.go @@ -3,7 +3,7 @@ package chart import ( "testing" - "git.smarteching.com/zeni/go-chart/v2/testutil" + "github.com/wcharczuk/go-chart/v2/testutil" ) func TestValuesValues(t *testing.T) { diff --git a/vector_renderer.go b/vector_renderer.go index 979bea7..8865c61 100644 --- a/vector_renderer.go +++ b/vector_renderer.go @@ -9,8 +9,8 @@ import ( "golang.org/x/image/font" - "git.smarteching.com/zeni/go-chart/v2/drawing" "github.com/golang/freetype/truetype" + "github.com/wcharczuk/go-chart/v2/drawing" ) // SVG returns a new png/raster renderer. @@ -247,7 +247,7 @@ type canvas struct { func (c *canvas) Start(width, height int) { c.width = width c.height = height - c.w.Write([]byte(fmt.Sprintf(``, c.width, c.height))) + c.w.Write([]byte(fmt.Sprintf(`\n`, c.width, c.height))) if c.css != "" { c.w.Write([]byte(`