potential fix for issue with large deltas rounding the y axis
This commit is contained in:
parent
b713ff85cc
commit
182d5a199b
3 changed files with 13 additions and 26 deletions
|
@ -16,26 +16,8 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
StrokeWidth: chart.Disabled,
|
||||
DotWidth: 3,
|
||||
},
|
||||
XValues: chart.Sequence.Random(32, 1024),
|
||||
YValues: chart.Sequence.Random(32, 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),
|
||||
XValues: chart.Sequence.Random(4096, 1024),
|
||||
YValues: chart.Sequence.Random(4096, 1024),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
6
chart.go
6
chart.go
|
@ -98,11 +98,11 @@ func (c Chart) Render(rp RendererProvider, w io.Writer) error {
|
|||
xr, yr, yra := c.getRanges()
|
||||
canvasBox := c.getDefaultCanvasBox()
|
||||
xf, yf, yfa := c.getValueFormatters()
|
||||
|
||||
xr, yr, yra = c.setRangeDomains(canvasBox, xr, yr, yra)
|
||||
|
||||
err = c.checkRanges(xr, yr, yra)
|
||||
if err != nil {
|
||||
// (try to) dump the raw background to the stream.
|
||||
r.Save(w)
|
||||
return err
|
||||
}
|
||||
|
@ -260,12 +260,16 @@ func (c Chart) getRanges() (xrange, yrange, yrangeAlt Range) {
|
|||
yrange.SetMin(miny)
|
||||
yrange.SetMax(maxy)
|
||||
|
||||
// only round if we're showing the axis
|
||||
if c.YAxis.Style.Show {
|
||||
delta := yrange.GetDelta()
|
||||
roundTo := Math.GetRoundToForDelta(delta)
|
||||
rmin, rmax := Math.RoundDown(yrange.GetMin(), roundTo), Math.RoundUp(yrange.GetMax(), roundTo)
|
||||
|
||||
yrange.SetMin(rmin)
|
||||
yrange.SetMax(rmax)
|
||||
}
|
||||
}
|
||||
|
||||
if len(c.YAxisSecondary.Ticks) > 0 {
|
||||
tickMin, tickMax := math.MaxFloat64, -math.MaxFloat64
|
||||
|
|
|
@ -205,6 +205,7 @@ func GetAlternateColor(index int) drawing.Color {
|
|||
var (
|
||||
// DefaultAnnotationPadding is the padding around an annotation.
|
||||
DefaultAnnotationPadding = Box{Top: 5, Left: 5, Right: 5, Bottom: 5}
|
||||
|
||||
// DefaultBackgroundPadding is the default canvas padding config.
|
||||
DefaultBackgroundPadding = Box{Top: 5, Left: 5, Right: 5, Bottom: 5}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue