tests pass

This commit is contained in:
Will Charczuk 2019-02-16 11:17:39 -08:00
parent fa93bd8abb
commit 781a45d770
5 changed files with 35 additions and 5 deletions

View file

@ -103,6 +103,8 @@ func (c Chart) Render(rp RendererProvider, w io.Writer) error {
canvasBox := c.getDefaultCanvasBox() canvasBox := c.getDefaultCanvasBox()
xf, yf, yfa := c.getValueFormatters() xf, yf, yfa := c.getValueFormatters()
Debugf(c.Log, "chart; canvas box: %v", canvasBox)
xr, yr, yra = c.setRangeDomains(canvasBox, xr, yr, yra) xr, yr, yra = c.setRangeDomains(canvasBox, xr, yr, yra)
err = c.checkRanges(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) canvasBox = c.getAxesAdjustedCanvasBox(r, canvasBox, xr, yr, yra, xt, yt, yta)
xr, yr, yra = c.setRangeDomains(canvasBox, xr, yr, yra) 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. // do a second pass in case things haven't settled yet.
xt, yt, yta = c.getAxesTicks(r, xr, yr, yra, xf, yf, yfa) xt, yt, yta = c.getAxesTicks(r, xr, yr, yra, xf, yf, yfa)
canvasBox = c.getAxesAdjustedCanvasBox(r, canvasBox, xr, yr, yra, xt, yt, yta) 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) canvasBox = c.getAnnotationAdjustedCanvasBox(r, canvasBox, xr, yr, yra, xf, yf, yfa)
xr, yr, yra = c.setRangeDomains(canvasBox, xr, yr, yra) xr, yr, yra = c.setRangeDomains(canvasBox, xr, yr, yra)
xt, yt, yta = c.getAxesTicks(r, xr, yr, yra, xf, yf, yfa) 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) c.drawCanvas(r, canvasBox)
@ -382,14 +388,17 @@ func (c Chart) getAxesAdjustedCanvasBox(r Renderer, canvasBox Box, xr, yr, yra R
axesOuterBox := canvasBox.Clone() axesOuterBox := canvasBox.Clone()
if !c.XAxis.Style.Hidden { if !c.XAxis.Style.Hidden {
axesBounds := c.XAxis.Measure(r, canvasBox, xr, c.styleDefaultsAxes(), xticks) axesBounds := c.XAxis.Measure(r, canvasBox, xr, c.styleDefaultsAxes(), xticks)
Debugf(c.Log, "chart; x-axis measured %v", axesBounds)
axesOuterBox = axesOuterBox.Grow(axesBounds) axesOuterBox = axesOuterBox.Grow(axesBounds)
} }
if !c.YAxis.Style.Hidden { if !c.YAxis.Style.Hidden {
axesBounds := c.YAxis.Measure(r, canvasBox, yr, c.styleDefaultsAxes(), yticks) axesBounds := c.YAxis.Measure(r, canvasBox, yr, c.styleDefaultsAxes(), yticks)
Debugf(c.Log, "chart; y-axis measured %v", axesBounds)
axesOuterBox = axesOuterBox.Grow(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) axesBounds := c.YAxisSecondary.Measure(r, canvasBox, yra, c.styleDefaultsAxes(), yticksAlt)
Debugf(c.Log, "chart; y-axis secondary measured %v", axesBounds)
axesOuterBox = axesOuterBox.Grow(axesBounds) axesOuterBox = axesOuterBox.Grow(axesBounds)
} }

View file

@ -484,8 +484,12 @@ func TestChartE2ELine(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
c := Chart{ c := Chart{
Height: 50, Height: 50,
Width: 50, Width: 50,
TitleStyle: Hidden(),
XAxis: HideXAxis(),
YAxis: HideYAxis(),
YAxisSecondary: HideYAxis(),
Canvas: Style{ Canvas: Style{
Padding: BoxZero, Padding: BoxZero,
}, },
@ -532,6 +536,10 @@ func TestChartE2ELineWithFill(t *testing.T) {
Background: Style{ Background: Style{
Padding: BoxZero, Padding: BoxZero,
}, },
TitleStyle: Hidden(),
XAxis: HideXAxis(),
YAxis: HideYAxis(),
YAxisSecondary: HideYAxis(),
Series: []Series{ Series: []Series{
ContinuousSeries{ ContinuousSeries{
Style: Style{ Style: Style{
@ -542,6 +550,7 @@ func TestChartE2ELineWithFill(t *testing.T) {
YValues: LinearRangeWithStep(0, 4, 1), YValues: LinearRangeWithStep(0, 4, 1),
}, },
}, },
Log: NewLogger(),
} }
assert.Equal(5, len(c.Series[0].(ContinuousSeries).XValues)) assert.Equal(5, len(c.Series[0].(ContinuousSeries).XValues))
@ -551,8 +560,6 @@ func TestChartE2ELineWithFill(t *testing.T) {
err := c.Render(PNG, buffer) err := c.Render(PNG, buffer)
assert.Nil(err) assert.Nil(err)
// do color tests ...
i, err := png.Decode(buffer) i, err := png.Decode(buffer)
assert.Nil(err) assert.Nil(err)

BIN
e2efill.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View file

@ -4,6 +4,13 @@ import (
"math" "math"
) )
// HideXAxis hides the x-axis.
func HideXAxis() XAxis {
return XAxis{
Style: Hidden(),
}
}
// XAxis represents the horizontal axis. // XAxis represents the horizontal axis.
type XAxis struct { type XAxis struct {
Name string Name string

View file

@ -4,6 +4,13 @@ import (
"math" "math"
) )
// HideYAxis hides a y-axis.
func HideYAxis() YAxis {
return YAxis{
Style: Hidden(),
}
}
// YAxis is a veritcal rule of the range. // YAxis is a veritcal rule of the range.
// There can be (2) y-axes; a primary and secondary. // There can be (2) y-axes; a primary and secondary.
type YAxis struct { type YAxis struct {