From 865ff54ab9d0f7d1e557448ee4d2450c2ccaf990 Mon Sep 17 00:00:00 2001 From: nptrx <34382237+nptrx@users.noreply.github.com> Date: Fri, 12 Oct 2018 09:20:44 +0900 Subject: [PATCH] unification of sample and test coding styles will improve visibility (#67) * "Style{Show: true}" to "StyleShow()" * "Box{IsSet: true}" to "BoxZero" --- _examples/axes/main.go | 8 ++------ _examples/bar_chart/main.go | 8 ++------ _examples/custom_formatters/main.go | 4 +--- _examples/custom_padding/main.go | 16 ++++------------ _examples/custom_ranges/main.go | 4 +--- _examples/custom_ticks/main.go | 4 +--- _examples/descending/main.go | 8 ++------ _examples/legend/main.go | 4 ++-- _examples/legend_left/main.go | 4 ++-- _examples/request_timings/main.go | 4 +--- _examples/scatter/main.go | 4 ++-- _examples/stacked_bar/main.go | 8 ++------ _examples/stock_analysis/main.go | 4 ++-- _examples/timeseries/main.go | 8 ++------ _examples/twoaxis/main.go | 12 +++--------- _examples/twopoint/main.go | 6 ++---- annotation_series_test.go | 5 ++--- chart_test.go | 28 ++++++++++++---------------- 18 files changed, 45 insertions(+), 94 deletions(-) diff --git a/_examples/axes/main.go b/_examples/axes/main.go index ee0a88c..6f2bdd5 100644 --- a/_examples/axes/main.go +++ b/_examples/axes/main.go @@ -15,14 +15,10 @@ func drawChart(res http.ResponseWriter, req *http.Request) { graph := chart.Chart{ XAxis: chart.XAxis{ - Style: chart.Style{ - Show: true, //enables / displays the x-axis - }, + Style: chart.StyleShow(), //enables / displays the x-axis }, YAxis: chart.YAxis{ - Style: chart.Style{ - Show: true, //enables / displays the y-axis - }, + Style: chart.StyleShow(), //enables / displays the y-axis }, Series: []chart.Series{ chart.ContinuousSeries{ diff --git a/_examples/bar_chart/main.go b/_examples/bar_chart/main.go index 6b8db61..693a300 100644 --- a/_examples/bar_chart/main.go +++ b/_examples/bar_chart/main.go @@ -20,13 +20,9 @@ func drawChart(res http.ResponseWriter, req *http.Request) { }, Height: 512, BarWidth: 60, - XAxis: chart.Style{ - Show: true, - }, + XAxis: chart.StyleShow(), YAxis: chart.YAxis{ - Style: chart.Style{ - Show: true, - }, + Style: chart.StyleShow(), }, Bars: []chart.Value{ {Value: 5.25, Label: "Blue"}, diff --git a/_examples/custom_formatters/main.go b/_examples/custom_formatters/main.go index 5da4b00..fe1805d 100644 --- a/_examples/custom_formatters/main.go +++ b/_examples/custom_formatters/main.go @@ -16,9 +16,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) { graph := chart.Chart{ YAxis: chart.YAxis{ - Style: chart.Style{ - Show: true, - }, + Style: chart.StyleShow(), ValueFormatter: func(v interface{}) string { if vf, isFloat := v.(float64); isFloat { return fmt.Sprintf("%0.6f", vf) diff --git a/_examples/custom_padding/main.go b/_examples/custom_padding/main.go index f1a5db5..a7cfc17 100644 --- a/_examples/custom_padding/main.go +++ b/_examples/custom_padding/main.go @@ -20,14 +20,10 @@ func drawChart(res http.ResponseWriter, req *http.Request) { FillColor: drawing.ColorFromHex("efefef"), }, XAxis: chart.XAxis{ - Style: chart.Style{ - Show: true, - }, + Style: chart.StyleShow(), }, YAxis: chart.YAxis{ - Style: chart.Style{ - Show: true, - }, + Style: chart.StyleShow(), }, Series: []chart.Series{ chart.ContinuousSeries{ @@ -47,14 +43,10 @@ func drawChartDefault(res http.ResponseWriter, req *http.Request) { FillColor: drawing.ColorFromHex("efefef"), }, XAxis: chart.XAxis{ - Style: chart.Style{ - Show: true, - }, + Style: chart.StyleShow(), }, YAxis: chart.YAxis{ - Style: chart.Style{ - Show: true, - }, + Style: chart.StyleShow(), }, Series: []chart.Series{ chart.ContinuousSeries{ diff --git a/_examples/custom_ranges/main.go b/_examples/custom_ranges/main.go index 4529684..f4b4205 100644 --- a/_examples/custom_ranges/main.go +++ b/_examples/custom_ranges/main.go @@ -14,9 +14,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) { graph := chart.Chart{ YAxis: chart.YAxis{ - Style: chart.Style{ - Show: true, - }, + Style: chart.StyleShow(), Range: &chart.ContinuousRange{ Min: 0.0, Max: 10.0, diff --git a/_examples/custom_ticks/main.go b/_examples/custom_ticks/main.go index 21b9d31..8be25e0 100644 --- a/_examples/custom_ticks/main.go +++ b/_examples/custom_ticks/main.go @@ -14,9 +14,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) { graph := chart.Chart{ YAxis: chart.YAxis{ - Style: chart.Style{ - Show: true, - }, + Style: chart.StyleShow(), Range: &chart.ContinuousRange{ Min: 0.0, Max: 4.0, diff --git a/_examples/descending/main.go b/_examples/descending/main.go index 6270104..683c3dd 100644 --- a/_examples/descending/main.go +++ b/_examples/descending/main.go @@ -20,17 +20,13 @@ func drawChart(res http.ResponseWriter, req *http.Request) { Height: 500, Width: 500, XAxis: chart.XAxis{ - Style: chart.Style{ - Show: true, - }, + Style: chart.StyleShow(), /*Range: &chart.ContinuousRange{ Descending: true, },*/ }, YAxis: chart.YAxis{ - Style: chart.Style{ - Show: true, - }, + Style: chart.StyleShow(), Range: &chart.ContinuousRange{ Descending: true, }, diff --git a/_examples/legend/main.go b/_examples/legend/main.go index 41cff72..a82d7d3 100644 --- a/_examples/legend/main.go +++ b/_examples/legend/main.go @@ -16,10 +16,10 @@ func drawChart(res http.ResponseWriter, req *http.Request) { graph := chart.Chart{ XAxis: chart.XAxis{ - Style: chart.Style{Show: true}, + Style: chart.StyleShow(), }, YAxis: chart.YAxis{ - Style: chart.Style{Show: true}, + Style: chart.StyleShow(), }, Background: chart.Style{ Padding: chart.Box{ diff --git a/_examples/legend_left/main.go b/_examples/legend_left/main.go index b5e61b6..9eb7fc5 100644 --- a/_examples/legend_left/main.go +++ b/_examples/legend_left/main.go @@ -16,10 +16,10 @@ func drawChart(res http.ResponseWriter, req *http.Request) { graph := chart.Chart{ XAxis: chart.XAxis{ - Style: chart.Style{Show: true}, + Style: chart.StyleShow(), }, YAxis: chart.YAxis{ - Style: chart.Style{Show: true}, + Style: chart.StyleShow(), }, Background: chart.Style{ Padding: chart.Box{ diff --git a/_examples/request_timings/main.go b/_examples/request_timings/main.go index d5867af..000829d 100644 --- a/_examples/request_timings/main.go +++ b/_examples/request_timings/main.go @@ -105,9 +105,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) { }, }, XAxis: chart.XAxis{ - Style: chart.Style{ - Show: true, - }, + Style: chart.StyleShow(), ValueFormatter: chart.TimeHourValueFormatter, GridMajorStyle: chart.Style{ Show: true, diff --git a/_examples/scatter/main.go b/_examples/scatter/main.go index 6d0560c..e20539a 100644 --- a/_examples/scatter/main.go +++ b/_examples/scatter/main.go @@ -44,10 +44,10 @@ func unit(res http.ResponseWriter, req *http.Request) { Height: 50, Width: 50, Canvas: chart.Style{ - Padding: chart.Box{IsSet: true}, + Padding: chart.BoxZero, }, Background: chart.Style{ - Padding: chart.Box{IsSet: true}, + Padding: chart.BoxZero, }, Series: []chart.Series{ chart.ContinuousSeries{ diff --git a/_examples/stacked_bar/main.go b/_examples/stacked_bar/main.go index 7053bf3..3a6f22e 100644 --- a/_examples/stacked_bar/main.go +++ b/_examples/stacked_bar/main.go @@ -18,12 +18,8 @@ func drawChart(res http.ResponseWriter, req *http.Request) { }, }, Height: 512, - XAxis: chart.Style{ - Show: true, - }, - YAxis: chart.Style{ - Show: true, - }, + XAxis: chart.StyleShow(), + YAxis: chart.StyleShow(), Bars: []chart.StackedBar{ { Name: "This is a very long string to test word break wrapping.", diff --git a/_examples/stock_analysis/main.go b/_examples/stock_analysis/main.go index ddfa4b3..397e70f 100644 --- a/_examples/stock_analysis/main.go +++ b/_examples/stock_analysis/main.go @@ -43,11 +43,11 @@ func drawChart(res http.ResponseWriter, req *http.Request) { graph := chart.Chart{ XAxis: chart.XAxis{ - Style: chart.Style{Show: true}, + Style: chart.StyleShow(), TickPosition: chart.TickPositionBetweenTicks, }, YAxis: chart.YAxis{ - Style: chart.Style{Show: true}, + Style: chart.StyleShow(), Range: &chart.ContinuousRange{ Max: 220.0, Min: 180.0, diff --git a/_examples/timeseries/main.go b/_examples/timeseries/main.go index 87b2f67..b77f554 100644 --- a/_examples/timeseries/main.go +++ b/_examples/timeseries/main.go @@ -14,9 +14,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) { */ graph := chart.Chart{ XAxis: chart.XAxis{ - Style: chart.Style{ - Show: true, - }, + Style: chart.StyleShow(), }, Series: []chart.Series{ chart.TimeSeries{ @@ -48,9 +46,7 @@ func drawCustomChart(res http.ResponseWriter, req *http.Request) { */ graph := chart.Chart{ XAxis: chart.XAxis{ - Style: chart.Style{ - Show: true, - }, + Style: chart.StyleShow(), ValueFormatter: chart.TimeHourValueFormatter, }, Series: []chart.Series{ diff --git a/_examples/twoaxis/main.go b/_examples/twoaxis/main.go index baac87e..471cf85 100644 --- a/_examples/twoaxis/main.go +++ b/_examples/twoaxis/main.go @@ -18,9 +18,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) { graph := chart.Chart{ XAxis: chart.XAxis{ - Style: chart.Style{ - Show: true, //enables / displays the x-axis - }, + Style: chart.StyleShow(), //enables / displays the x-axis TickPosition: chart.TickPositionBetweenTicks, ValueFormatter: func(v interface{}) string { typed := v.(float64) @@ -29,14 +27,10 @@ func drawChart(res http.ResponseWriter, req *http.Request) { }, }, YAxis: chart.YAxis{ - Style: chart.Style{ - Show: true, //enables / displays the y-axis - }, + Style: chart.StyleShow(), //enables / displays the y-axis }, YAxisSecondary: chart.YAxis{ - Style: chart.Style{ - Show: true, //enables / displays the secondary y-axis - }, + Style: chart.StyleShow(), //enables / displays the secondary y-axis }, Series: []chart.Series{ chart.ContinuousSeries{ diff --git a/_examples/twopoint/main.go b/_examples/twopoint/main.go index d51d37e..fc49641 100644 --- a/_examples/twopoint/main.go +++ b/_examples/twopoint/main.go @@ -14,10 +14,8 @@ func main() { b = 1000 ts1 := chart.ContinuousSeries{ //TimeSeries{ - Name: "Time Series", - Style: chart.Style{ - Show: true, - }, + Name: "Time Series", + Style: chart.StyleShow(), XValues: []float64{10 * b, 20 * b, 30 * b, 40 * b, 50 * b, 60 * b, 70 * b, 80 * b}, YValues: []float64{1.0, 2.0, 30.0, 4.0, 50.0, 6.0, 7.0, 88.0}, } diff --git a/annotation_series_test.go b/annotation_series_test.go index a92d655..64ab4db 100644 --- a/annotation_series_test.go +++ b/annotation_series_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/drawing" ) @@ -12,9 +13,7 @@ func TestAnnotationSeriesMeasure(t *testing.T) { assert := assert.New(t) as := AnnotationSeries{ - Style: Style{ - Show: true, - }, + Style: StyleShow(), Annotations: []Value2{ {XValue: 1.0, YValue: 1.0, Label: "1.0"}, {XValue: 2.0, YValue: 2.0, Label: "2.0"}, diff --git a/chart_test.go b/chart_test.go index c7d089a..e57f8ae 100644 --- a/chart_test.go +++ b/chart_test.go @@ -8,7 +8,9 @@ import ( "testing" "time" + "github.com/blend/go-sdk/assert" + "github.com/wcharczuk/go-chart/drawing" "github.com/wcharczuk/go-chart/seq" ) @@ -278,27 +280,21 @@ func TestChartHasAxes(t *testing.T) { x := Chart{ XAxis: XAxis{ - Style: Style{ - Show: true, - }, + Style: StyleShow(), }, } assert.True(x.hasAxes()) y := Chart{ YAxis: YAxis{ - Style: Style{ - Show: true, - }, + Style: StyleShow(), }, } assert.True(y.hasAxes()) ya := Chart{ YAxisSecondary: YAxis{ - Style: Style{ - Show: true, - }, + Style: StyleShow(), }, } assert.True(ya.hasAxes()) @@ -312,15 +308,15 @@ func TestChartGetAxesTicks(t *testing.T) { c := Chart{ XAxis: XAxis{ - Style: Style{Show: true}, + Style: StyleShow(), Range: &ContinuousRange{Min: 9.8, Max: 19.8}, }, YAxis: YAxis{ - Style: Style{Show: true}, + Style: StyleShow(), Range: &ContinuousRange{Min: 9.9, Max: 19.9}, }, YAxisSecondary: YAxis{ - Style: Style{Show: true}, + Style: StyleShow(), Range: &ContinuousRange{Min: 9.7, Max: 19.7}, }, } @@ -482,10 +478,10 @@ func TestChartE2ELine(t *testing.T) { Height: 50, Width: 50, Canvas: Style{ - Padding: Box{IsSet: true}, + Padding: BoxZero, }, Background: Style{ - Padding: Box{IsSet: true}, + Padding: BoxZero, }, Series: []Series{ ContinuousSeries{ @@ -522,10 +518,10 @@ func TestChartE2ELineWithFill(t *testing.T) { Height: 50, Width: 50, Canvas: Style{ - Padding: Box{IsSet: true}, + Padding: BoxZero, }, Background: Style{ - Padding: Box{IsSet: true}, + Padding: BoxZero, }, Series: []Series{ ContinuousSeries{