diff --git a/chart.go b/chart.go index 411a9c6..5212a43 100644 --- a/chart.go +++ b/chart.go @@ -103,6 +103,8 @@ func (c Chart) Render(rp RendererProvider, w io.Writer) error { canvasBox := c.getDefaultCanvasBox() xf, yf, yfa := c.getValueFormatters() + Debugf(c.Log, "chart; canvas box: %v", canvasBox) + xr, yr, yra = c.setRangeDomains(canvasBox, xr, yr, yra) err = c.checkRanges(xr, yr, yra) @@ -116,6 +118,8 @@ func (c Chart) Render(rp RendererProvider, w io.Writer) error { canvasBox = c.getAxesAdjustedCanvasBox(r, canvasBox, xr, yr, yra, xt, yt, yta) xr, yr, yra = c.setRangeDomains(canvasBox, xr, yr, yra) + Debugf(c.Log, "chart; axes adjusted canvas box: %v", canvasBox) + // do a second pass in case things haven't settled yet. xt, yt, yta = c.getAxesTicks(r, xr, yr, yra, xf, yf, yfa) canvasBox = c.getAxesAdjustedCanvasBox(r, canvasBox, xr, yr, yra, xt, yt, yta) @@ -126,6 +130,8 @@ func (c Chart) Render(rp RendererProvider, w io.Writer) error { canvasBox = c.getAnnotationAdjustedCanvasBox(r, canvasBox, xr, yr, yra, xf, yf, yfa) xr, yr, yra = c.setRangeDomains(canvasBox, xr, yr, yra) xt, yt, yta = c.getAxesTicks(r, xr, yr, yra, xf, yf, yfa) + + Debugf(c.Log, "chart; annotation adjusted canvas box: %v", canvasBox) } c.drawCanvas(r, canvasBox) @@ -382,14 +388,17 @@ func (c Chart) getAxesAdjustedCanvasBox(r Renderer, canvasBox Box, xr, yr, yra R axesOuterBox := canvasBox.Clone() if !c.XAxis.Style.Hidden { axesBounds := c.XAxis.Measure(r, canvasBox, xr, c.styleDefaultsAxes(), xticks) + Debugf(c.Log, "chart; x-axis measured %v", axesBounds) axesOuterBox = axesOuterBox.Grow(axesBounds) } if !c.YAxis.Style.Hidden { axesBounds := c.YAxis.Measure(r, canvasBox, yr, c.styleDefaultsAxes(), yticks) + Debugf(c.Log, "chart; y-axis measured %v", axesBounds) axesOuterBox = axesOuterBox.Grow(axesBounds) } - if !c.YAxisSecondary.Style.Hidden { + if !c.YAxisSecondary.Style.Hidden && c.hasSecondarySeries() { axesBounds := c.YAxisSecondary.Measure(r, canvasBox, yra, c.styleDefaultsAxes(), yticksAlt) + Debugf(c.Log, "chart; y-axis secondary measured %v", axesBounds) axesOuterBox = axesOuterBox.Grow(axesBounds) } diff --git a/chart_test.go b/chart_test.go index 8810374..dbbb34f 100644 --- a/chart_test.go +++ b/chart_test.go @@ -484,8 +484,12 @@ func TestChartE2ELine(t *testing.T) { assert := assert.New(t) c := Chart{ - Height: 50, - Width: 50, + Height: 50, + Width: 50, + TitleStyle: Hidden(), + XAxis: HideXAxis(), + YAxis: HideYAxis(), + YAxisSecondary: HideYAxis(), Canvas: Style{ Padding: BoxZero, }, @@ -532,6 +536,10 @@ func TestChartE2ELineWithFill(t *testing.T) { Background: Style{ Padding: BoxZero, }, + TitleStyle: Hidden(), + XAxis: HideXAxis(), + YAxis: HideYAxis(), + YAxisSecondary: HideYAxis(), Series: []Series{ ContinuousSeries{ Style: Style{ @@ -542,6 +550,7 @@ func TestChartE2ELineWithFill(t *testing.T) { YValues: LinearRangeWithStep(0, 4, 1), }, }, + Log: NewLogger(), } assert.Equal(5, len(c.Series[0].(ContinuousSeries).XValues)) @@ -551,8 +560,6 @@ func TestChartE2ELineWithFill(t *testing.T) { err := c.Render(PNG, buffer) assert.Nil(err) - // do color tests ... - i, err := png.Decode(buffer) assert.Nil(err) diff --git a/e2efill.png b/e2efill.png new file mode 100755 index 0000000..b4c121a Binary files /dev/null and b/e2efill.png differ diff --git a/xaxis.go b/xaxis.go index fbde599..4fcb569 100644 --- a/xaxis.go +++ b/xaxis.go @@ -4,6 +4,13 @@ import ( "math" ) +// HideXAxis hides the x-axis. +func HideXAxis() XAxis { + return XAxis{ + Style: Hidden(), + } +} + // XAxis represents the horizontal axis. type XAxis struct { Name string diff --git a/yaxis.go b/yaxis.go index 028fcc8..841fc86 100644 --- a/yaxis.go +++ b/yaxis.go @@ -4,6 +4,13 @@ import ( "math" ) +// HideYAxis hides a y-axis. +func HideYAxis() YAxis { + return YAxis{ + Style: Hidden(), + } +} + // YAxis is a veritcal rule of the range. // There can be (2) y-axes; a primary and secondary. type YAxis struct {