diff --git a/bar_chart_test.go b/bar_chart_test.go index 40e4c98..a2ae9c1 100644 --- a/bar_chart_test.go +++ b/bar_chart_test.go @@ -142,3 +142,33 @@ func TestBarChartHasAxes(t *testing.T) { assert.True(bc.hasAxes()) } + +func TestBarChartGetDefaultCanvasBox(t *testing.T) { + assert := assert.New(t) + + bc := BarChart{} + b := bc.getDefaultCanvasBox() + assert.False(b.IsZero()) +} + +func TestBarChartSetRangeDomains(t *testing.T) { + assert := assert.New(t) + + bc := BarChart{} + cb := bc.box() + yr := bc.getRanges() + yr2 := bc.setRangeDomains(cb, yr) + assert.NotZero(yr2.GetDomain()) +} + +func TestBarChartGetValueFormatters(t *testing.T) { + assert := assert.New(t) + + bc := BarChart{} + vf := bc.getValueFormatters() + assert.NotNil(vf) + assert.Equal("1234.00", vf(1234.0)) + + bc.YAxis.ValueFormatter = func(_ interface{}) string { return "test" } + assert.Equal("test", bc.getValueFormatters()(1234)) +} diff --git a/box_test.go b/box_test.go index fa95468..ba3b1ed 100644 --- a/box_test.go +++ b/box_test.go @@ -126,3 +126,20 @@ func TestBoxOuterConstrain(t *testing.T) { assert.Equal(85, d.Right, d.String()) assert.Equal(95, d.Bottom, d.String()) } + +func TestBoxShift(t *testing.T) { + assert := assert.New(t) + + b := Box{ + Top: 5, + Left: 5, + Right: 10, + Bottom: 10, + } + + shifted := b.Shift(1, 2) + assert.Equal(7, shifted.Top) + assert.Equal(6, shifted.Left) + assert.Equal(11, shifted.Right) + assert.Equal(12, shifted.Bottom) +} diff --git a/value_formatter.go b/value_formatter.go index 1a9afba..8789631 100644 --- a/value_formatter.go +++ b/value_formatter.go @@ -56,5 +56,14 @@ func FloatValueFormatterWithFormat(v interface{}, floatFormat string) string { if typed, isTyped := v.(float64); isTyped { return fmt.Sprintf(floatFormat, typed) } + if typed, isTyped := v.(float32); isTyped { + return fmt.Sprintf(floatFormat, typed) + } + if typed, isTyped := v.(int); isTyped { + return fmt.Sprintf(floatFormat, float64(typed)) + } + if typed, isTyped := v.(int64); isTyped { + return fmt.Sprintf(floatFormat, float64(typed)) + } return "" } diff --git a/value_formatter_test.go b/value_formatter_test.go index cc402b4..0675914 100644 --- a/value_formatter_test.go +++ b/value_formatter_test.go @@ -28,11 +28,31 @@ func TestTimeValueFormatterWithFormat(t *testing.T) { assert.Equal(s, sdf) } +func TestFloatValueFormatter(t *testing.T) { + assert := assert.New(t) + assert.Equal("1234.00", FloatValueFormatter(1234.00)) +} + +func TestFloatValueFormatterWithFloat32Input(t *testing.T) { + assert := assert.New(t) + assert.Equal("1234.00", FloatValueFormatter(float32(1234.00))) +} + +func TestFloatValueFormatterWithIntegerInput(t *testing.T) { + assert := assert.New(t) + assert.Equal("1234.00", FloatValueFormatter(1234)) +} + +func TestFloatValueFormatterWithInt64Input(t *testing.T) { + assert := assert.New(t) + assert.Equal("1234.00", FloatValueFormatter(int64(1234))) +} + func TestFloatValueFormatterWithFormat(t *testing.T) { assert := assert.New(t) v := 123.456 sv := FloatValueFormatterWithFormat(v, "%.3f") assert.Equal("123.456", sv) - assert.Equal("", FloatValueFormatterWithFormat(123, "%.3f")) + assert.Equal("123.000", FloatValueFormatterWithFormat(123, "%.3f")) }