snapshot.
This commit is contained in:
parent
cd4bbc6503
commit
8595962d99
|
@ -57,33 +57,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
|
||||
res.Header().Set("Content-Type", "image/png")
|
||||
graph.Elements = []chart.Renderable{
|
||||
func(r chart.Renderer, cb chart.Box, defaults chart.Style) {
|
||||
|
||||
b := chart.Box{Top: 70, Left: 100, Right: 170, Bottom: 300}
|
||||
|
||||
cx, cy := b.Center()
|
||||
|
||||
chart.Draw.Box(r, chart.Box{Top: cy - 2, Left: cx - 2, Right: cx + 2, Bottom: cy + 2}, chart.Style{
|
||||
StrokeWidth: 2,
|
||||
StrokeColor: chart.ColorBlack,
|
||||
})
|
||||
|
||||
chart.Draw.Box(r, b, chart.Style{
|
||||
StrokeWidth: 2,
|
||||
StrokeColor: chart.ColorBlue,
|
||||
})
|
||||
chart.Draw.Box(r, b.BoundedRotate(chart.Math.DegreesToRadians(60)), chart.Style{
|
||||
StrokeWidth: 2,
|
||||
StrokeColor: chart.ColorRed,
|
||||
})
|
||||
|
||||
chart.Draw.BoxRotated(r, b, chart.Math.DegreesToRadians(60), chart.Style{
|
||||
StrokeWidth: 2,
|
||||
StrokeColor: chart.ColorOrange,
|
||||
})
|
||||
},
|
||||
}
|
||||
graph.Render(chart.PNG, res)
|
||||
}
|
||||
|
||||
|
|
8
chart.go
8
chart.go
|
@ -102,12 +102,12 @@ func (c Chart) Render(rp RendererProvider, w io.Writer) error {
|
|||
|
||||
if c.hasAxes() {
|
||||
xt, yt, yta = c.getAxesTicks(r, xr, yr, yra, xf, yf, yfa)
|
||||
canvasBox = c.getAxisAdjustedCanvasBox(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)
|
||||
|
||||
// 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.getAxisAdjustedCanvasBox(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)
|
||||
}
|
||||
|
||||
|
@ -320,14 +320,16 @@ func (c Chart) getAxesTicks(r Renderer, xr, yr, yar Range, xf, yf, yfa ValueForm
|
|||
return
|
||||
}
|
||||
|
||||
func (c Chart) getAxisAdjustedCanvasBox(r Renderer, canvasBox Box, xr, yr, yra Range, xticks, yticks, yticksAlt []Tick) Box {
|
||||
func (c Chart) getAxesAdjustedCanvasBox(r Renderer, canvasBox Box, xr, yr, yra Range, xticks, yticks, yticksAlt []Tick) Box {
|
||||
axesOuterBox := canvasBox.Clone()
|
||||
if c.XAxis.Style.Show {
|
||||
axesBounds := c.XAxis.Measure(r, canvasBox, xr, c.styleDefaultsAxes(), xticks)
|
||||
Draw.Box(r, axesBounds, Style{StrokeWidth: 2, StrokeColor: ColorRed})
|
||||
axesOuterBox = axesOuterBox.Grow(axesBounds)
|
||||
}
|
||||
if c.YAxis.Style.Show {
|
||||
axesBounds := c.YAxis.Measure(r, canvasBox, yr, c.styleDefaultsAxes(), yticks)
|
||||
Draw.Box(r, axesBounds, Style{StrokeWidth: 2, StrokeColor: ColorBlue})
|
||||
axesOuterBox = axesOuterBox.Grow(axesBounds)
|
||||
}
|
||||
if c.YAxisSecondary.Style.Show {
|
||||
|
|
12
yaxis.go
12
yaxis.go
|
@ -84,23 +84,20 @@ func (ya YAxis) Measure(r Renderer, canvasBox Box, ra Range, defaults Style, tic
|
|||
}
|
||||
|
||||
ya.TickStyle.InheritFrom(ya.Style.InheritFrom(defaults)).WriteToRenderer(r)
|
||||
|
||||
var minx, maxx, miny, maxy = math.MaxInt32, 0, math.MaxInt32, 0
|
||||
var maxTextHeight int
|
||||
for _, t := range ticks {
|
||||
|
||||
v := t.Value
|
||||
ly := canvasBox.Bottom - ra.Translate(v)
|
||||
|
||||
tb := r.MeasureText(t.Label)
|
||||
tbh2 := tb.Height() >> 1
|
||||
finalTextX := tx
|
||||
if ya.AxisType == YAxisSecondary {
|
||||
finalTextX = tx - tb.Width()
|
||||
}
|
||||
|
||||
if tb.Height() > maxTextHeight {
|
||||
maxTextHeight = tb.Height()
|
||||
}
|
||||
maxTextHeight = Math.MaxInt(tb.Height(), maxTextHeight)
|
||||
|
||||
if ya.AxisType == YAxisPrimary {
|
||||
minx = canvasBox.Right
|
||||
|
@ -109,8 +106,9 @@ func (ya YAxis) Measure(r Renderer, canvasBox Box, ra Range, defaults Style, tic
|
|||
minx = Math.MinInt(minx, finalTextX)
|
||||
maxx = Math.MaxInt(maxx, tx)
|
||||
}
|
||||
miny = Math.MinInt(miny, ly-tb.Height()>>1)
|
||||
maxy = Math.MaxInt(maxy, ly+tb.Height()>>1)
|
||||
|
||||
miny = Math.MinInt(miny, ly-tbh2)
|
||||
maxy = Math.MaxInt(maxy, ly+tbh2)
|
||||
}
|
||||
|
||||
if ya.NameStyle.Show && len(ya.Name) > 0 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user