Skip to content

Commit

Permalink
Minor style change - Reduced newlines for struct initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jentfoo committed Feb 11, 2024
1 parent 28bb889 commit 79d3553
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 544 deletions.
7 changes: 1 addition & 6 deletions echarts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@ func TestEChartStyle(t *testing.T) {
es := EChartStyle{
Color: "#999",
}
color := drawing.Color{
R: 153,
G: 153,
B: 153,
A: 255,
}
color := drawing.Color{R: 153, G: 153, B: 153, A: 255}
assert.Equal(t, Style{
FillColor: color,
FontColor: color,
Expand Down
19 changes: 5 additions & 14 deletions examples/area_line_chart/main.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"

"github.com/go-analyze/charts"
"github.com/go-analyze/charts"
)

func writeFile(buf []byte) error {
tmpPath := "./tmp"
err := os.MkdirAll(tmpPath, 0700)
if err != nil {
if err := os.MkdirAll(tmpPath, 0700); err != nil {
return err
}

file := filepath.Join(tmpPath, "area-line-chart.png")
err = ioutil.WriteFile(file, buf, 0600)
if err != nil {
return err
}
return nil
return os.WriteFile(file, buf, 0600)
}

func main() {
Expand Down Expand Up @@ -63,12 +57,9 @@ func main() {
panic(err)
}

buf, err := p.Bytes()
if err != nil {
if buf, err := p.Bytes(); err != nil {
panic(err)
}
err = writeFile(buf)
if err != nil {
} else if err = writeFile(buf); err != nil {
panic(err)
}
}
17 changes: 4 additions & 13 deletions examples/bar_chart/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -10,17 +9,12 @@ import (

func writeFile(buf []byte) error {
tmpPath := "./tmp"
err := os.MkdirAll(tmpPath, 0700)
if err != nil {
if err := os.MkdirAll(tmpPath, 0700); err != nil {
return err
}

file := filepath.Join(tmpPath, "bar-chart.png")
err = ioutil.WriteFile(file, buf, 0600)
if err != nil {
return err
}
return nil
return os.WriteFile(file, buf, 0600)
}

func main() {
Expand Down Expand Up @@ -92,12 +86,9 @@ func main() {
panic(err)
}

buf, err := p.Bytes()
if err != nil {
if buf, err := p.Bytes(); err != nil {
panic(err)
}
err = writeFile(buf)
if err != nil {
} else if err = writeFile(buf); err != nil {
panic(err)
}
}
5 changes: 1 addition & 4 deletions examples/chinese/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ func writeFile(buf []byte) error {
}

file := filepath.Join(tmpPath, "chinese-line-chart.png")
if err := os.WriteFile(file, buf, 0600); err != nil {
return err
}
return nil
return os.WriteFile(file, buf, 0600)
}

func main() {
Expand Down
17 changes: 4 additions & 13 deletions examples/funnel_chart/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -10,17 +9,12 @@ import (

func writeFile(buf []byte) error {
tmpPath := "./tmp"
err := os.MkdirAll(tmpPath, 0700)
if err != nil {
if err := os.MkdirAll(tmpPath, 0700); err != nil {
return err
}

file := filepath.Join(tmpPath, "funnel-chart.png")
err = ioutil.WriteFile(file, buf, 0600)
if err != nil {
return err
}
return nil
return os.WriteFile(file, buf, 0600)
}

func main() {
Expand Down Expand Up @@ -50,12 +44,9 @@ func main() {
panic(err)
}

buf, err := p.Bytes()
if err != nil {
if buf, err := p.Bytes(); err != nil {
panic(err)
}
err = writeFile(buf)
if err != nil {
} else if err = writeFile(buf); err != nil {
panic(err)
}
}
17 changes: 4 additions & 13 deletions examples/line_chart/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -11,17 +10,12 @@ import (

func writeFile(buf []byte) error {
tmpPath := "./tmp"
err := os.MkdirAll(tmpPath, 0700)
if err != nil {
if err := os.MkdirAll(tmpPath, 0700); err != nil {
return err
}

file := filepath.Join(tmpPath, "line-chart.png")
err = ioutil.WriteFile(file, buf, 0600)
if err != nil {
return err
}
return nil
return os.WriteFile(file, buf, 0600)
}

func main() {
Expand Down Expand Up @@ -109,12 +103,9 @@ func main() {
panic(err)
}

buf, err := p.Bytes()
if err != nil {
if buf, err := p.Bytes(); err != nil {
panic(err)
}
err = writeFile(buf)
if err != nil {
} else if err = writeFile(buf); err != nil {
panic(err)
}
}
38 changes: 7 additions & 31 deletions examples/table/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand All @@ -14,17 +13,12 @@ import (

func writeFile(buf []byte, filename string) error {
tmpPath := "./tmp"
err := os.MkdirAll(tmpPath, 0700)
if err != nil {
if err := os.MkdirAll(tmpPath, 0700); err != nil {
return err
}

file := filepath.Join(tmpPath, filename)
err = ioutil.WriteFile(file, buf, 0600)
if err != nil {
return err
}
return nil
return os.WriteFile(file, buf, 0600)
}

func main() {
Expand Down Expand Up @@ -86,12 +80,7 @@ func main() {
panic(err)
}

bgColor := charts.Color{
R: 16,
G: 22,
B: 30,
A: 255,
}
bgColor := charts.Color{R: 16, G: 22, B: 30, A: 255}
p, err = charts.TableOptionRender(charts.TableChartOption{
Header: []string{
"Name",
Expand Down Expand Up @@ -148,19 +137,9 @@ func main() {
},
}
if value > 0 {
style.FillColor = charts.Color{
R: 179,
G: 53,
B: 20,
A: 255,
}
style.FillColor = charts.Color{R: 179, G: 53, B: 20, A: 255}
} else if value < 0 {
style.FillColor = charts.Color{
R: 33,
G: 124,
B: 50,
A: 255,
}
style.FillColor = charts.Color{R: 33, G: 124, B: 50, A: 255}
}
return &style
},
Expand All @@ -169,12 +148,9 @@ func main() {
panic(err)
}

buf, err = p.Bytes()
if err != nil {
if buf, err = p.Bytes(); err != nil {
panic(err)
}
err = writeFile(buf, "table-color.png")
if err != nil {
} else if err = writeFile(buf, "table-color.png"); err != nil {
panic(err)
}
}
18 changes: 3 additions & 15 deletions legend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ func TestNewLegend(t *testing.T) {
{
render: func(p *Painter) ([]byte, error) {
_, err := NewLegendPainter(p, LegendOption{
Data: []string{
"One",
"Two",
"Three",
},
Data: []string{"One", "Two", "Three"},
}).Render()
if err != nil {
return nil, err
Expand All @@ -34,11 +30,7 @@ func TestNewLegend(t *testing.T) {
{
render: func(p *Painter) ([]byte, error) {
_, err := NewLegendPainter(p, LegendOption{
Data: []string{
"One",
"Two",
"Three",
},
Data: []string{"One", "Two", "Three"},
Left: PositionLeft,
}).Render()
if err != nil {
Expand All @@ -51,11 +43,7 @@ func TestNewLegend(t *testing.T) {
{
render: func(p *Painter) ([]byte, error) {
_, err := NewLegendPainter(p, LegendOption{
Data: []string{
"One",
"Two",
"Three",
},
Data: []string{"One", "Two", "Three"},
Orient: OrientVertical,
Icon: IconRect,
Left: "10%",
Expand Down
6 changes: 1 addition & 5 deletions mark_line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ func TestMarkLine(t *testing.T) {
{
render: func(p *Painter) ([]byte, error) {
markLine := NewMarkLinePainter(p)
series := NewSeriesFromValues([]float64{
1,
2,
3,
})
series := NewSeriesFromValues([]float64{1, 2, 3})
series.MarkLine = NewMarkLine(
SeriesMarkDataTypeMax,
SeriesMarkDataTypeAverage,
Expand Down
21 changes: 4 additions & 17 deletions mark_point_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,16 @@ func TestMarkPoint(t *testing.T) {
}{
{
render: func(p *Painter) ([]byte, error) {
series := NewSeriesFromValues([]float64{
1,
2,
3,
})
series := NewSeriesFromValues([]float64{1, 2, 3})
series.MarkPoint = NewMarkPoint(SeriesMarkDataTypeMax)
markPoint := NewMarkPointPainter(p)
markPoint.Add(markPointRenderOption{
FillColor: drawing.ColorBlack,
Series: series,
Points: []Point{
{
X: 10,
Y: 10,
},
{
X: 30,
Y: 30,
},
{
X: 50,
Y: 50,
},
{X: 10, Y: 10},
{X: 30, Y: 30},
{X: 50, Y: 50},
},
})
if _, err := markPoint.Render(); err != nil {
Expand Down
Loading

0 comments on commit 79d3553

Please sign in to comment.