potential fix for issue with large deltas rounding the y axis

This commit is contained in:
Will Charczuk 2017-03-05 23:20:58 -08:00
parent b713ff85cc
commit 182d5a199b
3 changed files with 13 additions and 26 deletions

View File

@ -16,26 +16,8 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
StrokeWidth: chart.Disabled, StrokeWidth: chart.Disabled,
DotWidth: 3, DotWidth: 3,
}, },
XValues: chart.Sequence.Random(32, 1024), XValues: chart.Sequence.Random(4096, 1024),
YValues: chart.Sequence.Random(32, 1024), YValues: chart.Sequence.Random(4096, 1024),
},
chart.ContinuousSeries{
Style: chart.Style{
Show: true,
StrokeWidth: chart.Disabled,
DotWidth: 5,
},
XValues: chart.Sequence.Random(16, 1024),
YValues: chart.Sequence.Random(16, 1024),
},
chart.ContinuousSeries{
Style: chart.Style{
Show: true,
StrokeWidth: chart.Disabled,
DotWidth: 7,
},
XValues: chart.Sequence.Random(8, 1024),
YValues: chart.Sequence.Random(8, 1024),
}, },
}, },
} }

View File

@ -98,11 +98,11 @@ func (c Chart) Render(rp RendererProvider, w io.Writer) error {
xr, yr, yra := c.getRanges() xr, yr, yra := c.getRanges()
canvasBox := c.getDefaultCanvasBox() canvasBox := c.getDefaultCanvasBox()
xf, yf, yfa := c.getValueFormatters() xf, yf, yfa := c.getValueFormatters()
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)
if err != nil { if err != nil {
// (try to) dump the raw background to the stream.
r.Save(w) r.Save(w)
return err return err
} }
@ -260,12 +260,16 @@ func (c Chart) getRanges() (xrange, yrange, yrangeAlt Range) {
yrange.SetMin(miny) yrange.SetMin(miny)
yrange.SetMax(maxy) yrange.SetMax(maxy)
// only round if we're showing the axis
if c.YAxis.Style.Show {
delta := yrange.GetDelta() delta := yrange.GetDelta()
roundTo := Math.GetRoundToForDelta(delta) roundTo := Math.GetRoundToForDelta(delta)
rmin, rmax := Math.RoundDown(yrange.GetMin(), roundTo), Math.RoundUp(yrange.GetMax(), roundTo) rmin, rmax := Math.RoundDown(yrange.GetMin(), roundTo), Math.RoundUp(yrange.GetMax(), roundTo)
yrange.SetMin(rmin) yrange.SetMin(rmin)
yrange.SetMax(rmax) yrange.SetMax(rmax)
} }
}
if len(c.YAxisSecondary.Ticks) > 0 { if len(c.YAxisSecondary.Ticks) > 0 {
tickMin, tickMax := math.MaxFloat64, -math.MaxFloat64 tickMin, tickMax := math.MaxFloat64, -math.MaxFloat64

View File

@ -205,6 +205,7 @@ func GetAlternateColor(index int) drawing.Color {
var ( var (
// DefaultAnnotationPadding is the padding around an annotation. // DefaultAnnotationPadding is the padding around an annotation.
DefaultAnnotationPadding = Box{Top: 5, Left: 5, Right: 5, Bottom: 5} DefaultAnnotationPadding = Box{Top: 5, Left: 5, Right: 5, Bottom: 5}
// DefaultBackgroundPadding is the default canvas padding config. // DefaultBackgroundPadding is the default canvas padding config.
DefaultBackgroundPadding = Box{Top: 5, Left: 5, Right: 5, Bottom: 5} DefaultBackgroundPadding = Box{Top: 5, Left: 5, Right: 5, Bottom: 5}
) )