unification of sample and test coding styles will improve visibility (#67)

* "Style{Show: true}" to "StyleShow()"
* "Box{IsSet: true}" to "BoxZero"
This commit is contained in:
nptrx 2018-10-12 09:20:44 +09:00 committed by Will Charczuk
parent 0fb4aa53e9
commit 865ff54ab9
18 changed files with 45 additions and 94 deletions

View File

@ -15,14 +15,10 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
graph := chart.Chart{ graph := chart.Chart{
XAxis: chart.XAxis{ XAxis: chart.XAxis{
Style: chart.Style{ Style: chart.StyleShow(), //enables / displays the x-axis
Show: true, //enables / displays the x-axis
},
}, },
YAxis: chart.YAxis{ YAxis: chart.YAxis{
Style: chart.Style{ Style: chart.StyleShow(), //enables / displays the y-axis
Show: true, //enables / displays the y-axis
},
}, },
Series: []chart.Series{ Series: []chart.Series{
chart.ContinuousSeries{ chart.ContinuousSeries{

View File

@ -20,13 +20,9 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
}, },
Height: 512, Height: 512,
BarWidth: 60, BarWidth: 60,
XAxis: chart.Style{ XAxis: chart.StyleShow(),
Show: true,
},
YAxis: chart.YAxis{ YAxis: chart.YAxis{
Style: chart.Style{ Style: chart.StyleShow(),
Show: true,
},
}, },
Bars: []chart.Value{ Bars: []chart.Value{
{Value: 5.25, Label: "Blue"}, {Value: 5.25, Label: "Blue"},

View File

@ -16,9 +16,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
graph := chart.Chart{ graph := chart.Chart{
YAxis: chart.YAxis{ YAxis: chart.YAxis{
Style: chart.Style{ Style: chart.StyleShow(),
Show: true,
},
ValueFormatter: func(v interface{}) string { ValueFormatter: func(v interface{}) string {
if vf, isFloat := v.(float64); isFloat { if vf, isFloat := v.(float64); isFloat {
return fmt.Sprintf("%0.6f", vf) return fmt.Sprintf("%0.6f", vf)

View File

@ -20,14 +20,10 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
FillColor: drawing.ColorFromHex("efefef"), FillColor: drawing.ColorFromHex("efefef"),
}, },
XAxis: chart.XAxis{ XAxis: chart.XAxis{
Style: chart.Style{ Style: chart.StyleShow(),
Show: true,
},
}, },
YAxis: chart.YAxis{ YAxis: chart.YAxis{
Style: chart.Style{ Style: chart.StyleShow(),
Show: true,
},
}, },
Series: []chart.Series{ Series: []chart.Series{
chart.ContinuousSeries{ chart.ContinuousSeries{
@ -47,14 +43,10 @@ func drawChartDefault(res http.ResponseWriter, req *http.Request) {
FillColor: drawing.ColorFromHex("efefef"), FillColor: drawing.ColorFromHex("efefef"),
}, },
XAxis: chart.XAxis{ XAxis: chart.XAxis{
Style: chart.Style{ Style: chart.StyleShow(),
Show: true,
},
}, },
YAxis: chart.YAxis{ YAxis: chart.YAxis{
Style: chart.Style{ Style: chart.StyleShow(),
Show: true,
},
}, },
Series: []chart.Series{ Series: []chart.Series{
chart.ContinuousSeries{ chart.ContinuousSeries{

View File

@ -14,9 +14,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
graph := chart.Chart{ graph := chart.Chart{
YAxis: chart.YAxis{ YAxis: chart.YAxis{
Style: chart.Style{ Style: chart.StyleShow(),
Show: true,
},
Range: &chart.ContinuousRange{ Range: &chart.ContinuousRange{
Min: 0.0, Min: 0.0,
Max: 10.0, Max: 10.0,

View File

@ -14,9 +14,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
graph := chart.Chart{ graph := chart.Chart{
YAxis: chart.YAxis{ YAxis: chart.YAxis{
Style: chart.Style{ Style: chart.StyleShow(),
Show: true,
},
Range: &chart.ContinuousRange{ Range: &chart.ContinuousRange{
Min: 0.0, Min: 0.0,
Max: 4.0, Max: 4.0,

View File

@ -20,17 +20,13 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
Height: 500, Height: 500,
Width: 500, Width: 500,
XAxis: chart.XAxis{ XAxis: chart.XAxis{
Style: chart.Style{ Style: chart.StyleShow(),
Show: true,
},
/*Range: &chart.ContinuousRange{ /*Range: &chart.ContinuousRange{
Descending: true, Descending: true,
},*/ },*/
}, },
YAxis: chart.YAxis{ YAxis: chart.YAxis{
Style: chart.Style{ Style: chart.StyleShow(),
Show: true,
},
Range: &chart.ContinuousRange{ Range: &chart.ContinuousRange{
Descending: true, Descending: true,
}, },

View File

@ -16,10 +16,10 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
graph := chart.Chart{ graph := chart.Chart{
XAxis: chart.XAxis{ XAxis: chart.XAxis{
Style: chart.Style{Show: true}, Style: chart.StyleShow(),
}, },
YAxis: chart.YAxis{ YAxis: chart.YAxis{
Style: chart.Style{Show: true}, Style: chart.StyleShow(),
}, },
Background: chart.Style{ Background: chart.Style{
Padding: chart.Box{ Padding: chart.Box{

View File

@ -16,10 +16,10 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
graph := chart.Chart{ graph := chart.Chart{
XAxis: chart.XAxis{ XAxis: chart.XAxis{
Style: chart.Style{Show: true}, Style: chart.StyleShow(),
}, },
YAxis: chart.YAxis{ YAxis: chart.YAxis{
Style: chart.Style{Show: true}, Style: chart.StyleShow(),
}, },
Background: chart.Style{ Background: chart.Style{
Padding: chart.Box{ Padding: chart.Box{

View File

@ -105,9 +105,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
}, },
}, },
XAxis: chart.XAxis{ XAxis: chart.XAxis{
Style: chart.Style{ Style: chart.StyleShow(),
Show: true,
},
ValueFormatter: chart.TimeHourValueFormatter, ValueFormatter: chart.TimeHourValueFormatter,
GridMajorStyle: chart.Style{ GridMajorStyle: chart.Style{
Show: true, Show: true,

View File

@ -44,10 +44,10 @@ func unit(res http.ResponseWriter, req *http.Request) {
Height: 50, Height: 50,
Width: 50, Width: 50,
Canvas: chart.Style{ Canvas: chart.Style{
Padding: chart.Box{IsSet: true}, Padding: chart.BoxZero,
}, },
Background: chart.Style{ Background: chart.Style{
Padding: chart.Box{IsSet: true}, Padding: chart.BoxZero,
}, },
Series: []chart.Series{ Series: []chart.Series{
chart.ContinuousSeries{ chart.ContinuousSeries{

View File

@ -18,12 +18,8 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
}, },
}, },
Height: 512, Height: 512,
XAxis: chart.Style{ XAxis: chart.StyleShow(),
Show: true, YAxis: chart.StyleShow(),
},
YAxis: chart.Style{
Show: true,
},
Bars: []chart.StackedBar{ Bars: []chart.StackedBar{
{ {
Name: "This is a very long string to test word break wrapping.", Name: "This is a very long string to test word break wrapping.",

View File

@ -43,11 +43,11 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
graph := chart.Chart{ graph := chart.Chart{
XAxis: chart.XAxis{ XAxis: chart.XAxis{
Style: chart.Style{Show: true}, Style: chart.StyleShow(),
TickPosition: chart.TickPositionBetweenTicks, TickPosition: chart.TickPositionBetweenTicks,
}, },
YAxis: chart.YAxis{ YAxis: chart.YAxis{
Style: chart.Style{Show: true}, Style: chart.StyleShow(),
Range: &chart.ContinuousRange{ Range: &chart.ContinuousRange{
Max: 220.0, Max: 220.0,
Min: 180.0, Min: 180.0,

View File

@ -14,9 +14,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
*/ */
graph := chart.Chart{ graph := chart.Chart{
XAxis: chart.XAxis{ XAxis: chart.XAxis{
Style: chart.Style{ Style: chart.StyleShow(),
Show: true,
},
}, },
Series: []chart.Series{ Series: []chart.Series{
chart.TimeSeries{ chart.TimeSeries{
@ -48,9 +46,7 @@ func drawCustomChart(res http.ResponseWriter, req *http.Request) {
*/ */
graph := chart.Chart{ graph := chart.Chart{
XAxis: chart.XAxis{ XAxis: chart.XAxis{
Style: chart.Style{ Style: chart.StyleShow(),
Show: true,
},
ValueFormatter: chart.TimeHourValueFormatter, ValueFormatter: chart.TimeHourValueFormatter,
}, },
Series: []chart.Series{ Series: []chart.Series{

View File

@ -18,9 +18,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
graph := chart.Chart{ graph := chart.Chart{
XAxis: chart.XAxis{ XAxis: chart.XAxis{
Style: chart.Style{ Style: chart.StyleShow(), //enables / displays the x-axis
Show: true, //enables / displays the x-axis
},
TickPosition: chart.TickPositionBetweenTicks, TickPosition: chart.TickPositionBetweenTicks,
ValueFormatter: func(v interface{}) string { ValueFormatter: func(v interface{}) string {
typed := v.(float64) typed := v.(float64)
@ -29,14 +27,10 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
}, },
}, },
YAxis: chart.YAxis{ YAxis: chart.YAxis{
Style: chart.Style{ Style: chart.StyleShow(), //enables / displays the y-axis
Show: true, //enables / displays the y-axis
},
}, },
YAxisSecondary: chart.YAxis{ YAxisSecondary: chart.YAxis{
Style: chart.Style{ Style: chart.StyleShow(), //enables / displays the secondary y-axis
Show: true, //enables / displays the secondary y-axis
},
}, },
Series: []chart.Series{ Series: []chart.Series{
chart.ContinuousSeries{ chart.ContinuousSeries{

View File

@ -15,9 +15,7 @@ func main() {
ts1 := chart.ContinuousSeries{ //TimeSeries{ ts1 := chart.ContinuousSeries{ //TimeSeries{
Name: "Time Series", Name: "Time Series",
Style: chart.Style{ Style: chart.StyleShow(),
Show: true,
},
XValues: []float64{10 * b, 20 * b, 30 * b, 40 * b, 50 * b, 60 * b, 70 * b, 80 * b}, 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}, YValues: []float64{1.0, 2.0, 30.0, 4.0, 50.0, 6.0, 7.0, 88.0},
} }

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/blend/go-sdk/assert" "github.com/blend/go-sdk/assert"
"github.com/wcharczuk/go-chart/drawing" "github.com/wcharczuk/go-chart/drawing"
) )
@ -12,9 +13,7 @@ func TestAnnotationSeriesMeasure(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
as := AnnotationSeries{ as := AnnotationSeries{
Style: Style{ Style: StyleShow(),
Show: true,
},
Annotations: []Value2{ Annotations: []Value2{
{XValue: 1.0, YValue: 1.0, Label: "1.0"}, {XValue: 1.0, YValue: 1.0, Label: "1.0"},
{XValue: 2.0, YValue: 2.0, Label: "2.0"}, {XValue: 2.0, YValue: 2.0, Label: "2.0"},

View File

@ -8,7 +8,9 @@ import (
"testing" "testing"
"time" "time"
"github.com/blend/go-sdk/assert" "github.com/blend/go-sdk/assert"
"github.com/wcharczuk/go-chart/drawing" "github.com/wcharczuk/go-chart/drawing"
"github.com/wcharczuk/go-chart/seq" "github.com/wcharczuk/go-chart/seq"
) )
@ -278,27 +280,21 @@ func TestChartHasAxes(t *testing.T) {
x := Chart{ x := Chart{
XAxis: XAxis{ XAxis: XAxis{
Style: Style{ Style: StyleShow(),
Show: true,
},
}, },
} }
assert.True(x.hasAxes()) assert.True(x.hasAxes())
y := Chart{ y := Chart{
YAxis: YAxis{ YAxis: YAxis{
Style: Style{ Style: StyleShow(),
Show: true,
},
}, },
} }
assert.True(y.hasAxes()) assert.True(y.hasAxes())
ya := Chart{ ya := Chart{
YAxisSecondary: YAxis{ YAxisSecondary: YAxis{
Style: Style{ Style: StyleShow(),
Show: true,
},
}, },
} }
assert.True(ya.hasAxes()) assert.True(ya.hasAxes())
@ -312,15 +308,15 @@ func TestChartGetAxesTicks(t *testing.T) {
c := Chart{ c := Chart{
XAxis: XAxis{ XAxis: XAxis{
Style: Style{Show: true}, Style: StyleShow(),
Range: &ContinuousRange{Min: 9.8, Max: 19.8}, Range: &ContinuousRange{Min: 9.8, Max: 19.8},
}, },
YAxis: YAxis{ YAxis: YAxis{
Style: Style{Show: true}, Style: StyleShow(),
Range: &ContinuousRange{Min: 9.9, Max: 19.9}, Range: &ContinuousRange{Min: 9.9, Max: 19.9},
}, },
YAxisSecondary: YAxis{ YAxisSecondary: YAxis{
Style: Style{Show: true}, Style: StyleShow(),
Range: &ContinuousRange{Min: 9.7, Max: 19.7}, Range: &ContinuousRange{Min: 9.7, Max: 19.7},
}, },
} }
@ -482,10 +478,10 @@ func TestChartE2ELine(t *testing.T) {
Height: 50, Height: 50,
Width: 50, Width: 50,
Canvas: Style{ Canvas: Style{
Padding: Box{IsSet: true}, Padding: BoxZero,
}, },
Background: Style{ Background: Style{
Padding: Box{IsSet: true}, Padding: BoxZero,
}, },
Series: []Series{ Series: []Series{
ContinuousSeries{ ContinuousSeries{
@ -522,10 +518,10 @@ func TestChartE2ELineWithFill(t *testing.T) {
Height: 50, Height: 50,
Width: 50, Width: 50,
Canvas: Style{ Canvas: Style{
Padding: Box{IsSet: true}, Padding: BoxZero,
}, },
Background: Style{ Background: Style{
Padding: Box{IsSet: true}, Padding: BoxZero,
}, },
Series: []Series{ Series: []Series{
ContinuousSeries{ ContinuousSeries{