custom padding example and slight fixes.
This commit is contained in:
parent
0e3d2e9c1f
commit
ae31a618df
2 changed files with 44 additions and 15 deletions
29
chart.go
29
chart.go
|
@ -253,17 +253,7 @@ func (c Chart) checkRanges(xr, yr, yra Range) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Chart) getDefaultCanvasBox() Box {
|
func (c Chart) getDefaultCanvasBox() Box {
|
||||||
dpt := c.Background.Padding.GetTop(DefaultBackgroundPadding.Top)
|
return c.Box()
|
||||||
dpl := c.Background.Padding.GetLeft(DefaultBackgroundPadding.Left)
|
|
||||||
dpr := c.Background.Padding.GetRight(DefaultBackgroundPadding.Right)
|
|
||||||
dpb := c.Background.Padding.GetBottom(DefaultBackgroundPadding.Bottom)
|
|
||||||
|
|
||||||
return Box{
|
|
||||||
Top: dpt,
|
|
||||||
Left: dpl,
|
|
||||||
Right: c.GetWidth() - dpr,
|
|
||||||
Bottom: c.GetHeight() - dpb,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Chart) getValueFormatters() (x, y, ya ValueFormatter) {
|
func (c Chart) getValueFormatters() (x, y, ya ValueFormatter) {
|
||||||
|
@ -323,7 +313,7 @@ func (c Chart) getAxisAdjustedCanvasBox(r Renderer, canvasBox Box, xr, yr, yra R
|
||||||
axesOuterBox = axesOuterBox.Grow(axesBounds)
|
axesOuterBox = axesOuterBox.Grow(axesBounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
return canvasBox.OuterConstrain(canvasBox, axesOuterBox)
|
return canvasBox.OuterConstrain(c.Box(), axesOuterBox)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Chart) setRangeDomains(canvasBox Box, xr, yr, yra Range) (xr2, yr2, yra2 Range) {
|
func (c Chart) setRangeDomains(canvasBox Box, xr, yr, yra Range) (xr2, yr2, yra2 Range) {
|
||||||
|
@ -382,7 +372,10 @@ func (c Chart) getBackgroundStyle() Style {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Chart) drawBackground(r Renderer) {
|
func (c Chart) drawBackground(r Renderer) {
|
||||||
DrawBox(r, c.Box(), c.getBackgroundStyle())
|
DrawBox(r, Box{
|
||||||
|
Right: c.GetWidth(),
|
||||||
|
Bottom: c.GetHeight(),
|
||||||
|
}, c.getBackgroundStyle())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Chart) getCanvasStyle() Style {
|
func (c Chart) getCanvasStyle() Style {
|
||||||
|
@ -477,5 +470,13 @@ func (c Chart) styleDefaultsElements() Style {
|
||||||
|
|
||||||
// Box returns the chart bounds as a box.
|
// Box returns the chart bounds as a box.
|
||||||
func (c Chart) Box() Box {
|
func (c Chart) Box() Box {
|
||||||
return Box{Right: c.GetWidth(), Bottom: c.GetHeight()}
|
dpr := c.Background.Padding.GetRight(DefaultBackgroundPadding.Right)
|
||||||
|
dpb := c.Background.Padding.GetBottom(DefaultBackgroundPadding.Bottom)
|
||||||
|
|
||||||
|
return Box{
|
||||||
|
Top: c.Background.Padding.GetTop(DefaultBackgroundPadding.Top),
|
||||||
|
Left: c.Background.Padding.GetLeft(DefaultBackgroundPadding.Left),
|
||||||
|
Right: c.GetWidth() - dpr,
|
||||||
|
Bottom: c.GetHeight() - dpb,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
graph := chart.Chart{
|
graph := chart.Chart{
|
||||||
Background: chart.Style{
|
Background: chart.Style{
|
||||||
Padding: chart.Box{
|
Padding: chart.Box{
|
||||||
Top: 10,
|
Top: 50,
|
||||||
Left: 25,
|
Left: 25,
|
||||||
Right: 25,
|
Right: 25,
|
||||||
Bottom: 10,
|
Bottom: 10,
|
||||||
|
@ -40,7 +40,35 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
graph.Render(chart.PNG, res)
|
graph.Render(chart.PNG, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func drawChartDefault(res http.ResponseWriter, req *http.Request) {
|
||||||
|
graph := chart.Chart{
|
||||||
|
Background: chart.Style{
|
||||||
|
FillColor: drawing.ColorFromHex("efefef"),
|
||||||
|
},
|
||||||
|
XAxis: chart.XAxis{
|
||||||
|
Style: chart.Style{
|
||||||
|
Show: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
YAxis: chart.YAxis{
|
||||||
|
Style: chart.Style{
|
||||||
|
Show: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Series: []chart.Series{
|
||||||
|
chart.ContinuousSeries{
|
||||||
|
XValues: chart.Seq(1.0, 100.0),
|
||||||
|
YValues: chart.SeqRand(100.0, 256.0),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
res.Header().Set("Content-Type", "image/png")
|
||||||
|
graph.Render(chart.PNG, res)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/", drawChart)
|
http.HandleFunc("/", drawChart)
|
||||||
|
http.HandleFunc("/default", drawChartDefault)
|
||||||
http.ListenAndServe(":8080", nil)
|
http.ListenAndServe(":8080", nil)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue