Port changes 'fixing styling issues w/ the stack bar chart.' from commit a0ea012903
(#66)
This commit is contained in:
parent
f72f7fd57b
commit
11e380634b
3 changed files with 40 additions and 4 deletions
|
@ -11,6 +11,13 @@ import (
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
sbc := chart.BarChart{
|
sbc := chart.BarChart{
|
||||||
|
Title: "Test Bar Chart",
|
||||||
|
TitleStyle: chart.StyleShow(),
|
||||||
|
Background: chart.Style{
|
||||||
|
Padding: chart.Box{
|
||||||
|
Top: 40,
|
||||||
|
},
|
||||||
|
},
|
||||||
Height: 512,
|
Height: 512,
|
||||||
BarWidth: 60,
|
BarWidth: 60,
|
||||||
XAxis: chart.Style{
|
XAxis: chart.Style{
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 19 KiB |
37
bar_chart.go
37
bar_chart.go
|
@ -126,7 +126,7 @@ func (bc BarChart) Render(rp RendererProvider, w io.Writer) error {
|
||||||
canvasBox = bc.getAdjustedCanvasBox(r, canvasBox, yr, yt)
|
canvasBox = bc.getAdjustedCanvasBox(r, canvasBox, yr, yt)
|
||||||
yr = bc.setRangeDomains(canvasBox, yr)
|
yr = bc.setRangeDomains(canvasBox, yr)
|
||||||
}
|
}
|
||||||
|
bc.drawCanvas(r, canvasBox)
|
||||||
bc.drawBars(r, canvasBox, yr)
|
bc.drawBars(r, canvasBox, yr)
|
||||||
bc.drawXAxis(r, canvasBox)
|
bc.drawXAxis(r, canvasBox)
|
||||||
bc.drawYAxis(r, canvasBox, yr, yt)
|
bc.drawYAxis(r, canvasBox, yr, yt)
|
||||||
|
@ -139,6 +139,10 @@ func (bc BarChart) Render(rp RendererProvider, w io.Writer) error {
|
||||||
return r.Save(w)
|
return r.Save(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bc BarChart) drawCanvas(r Renderer, canvasBox Box) {
|
||||||
|
Draw.Box(r, canvasBox, bc.getCanvasStyle())
|
||||||
|
}
|
||||||
|
|
||||||
func (bc BarChart) getRanges() Range {
|
func (bc BarChart) getRanges() Range {
|
||||||
var yrange Range
|
var yrange Range
|
||||||
if bc.YAxis.Range != nil && !bc.YAxis.Range.IsZero() {
|
if bc.YAxis.Range != nil && !bc.YAxis.Range.IsZero() {
|
||||||
|
@ -280,7 +284,32 @@ func (bc BarChart) drawYAxis(r Renderer, canvasBox Box, yr Range, ticks []Tick)
|
||||||
|
|
||||||
func (bc BarChart) drawTitle(r Renderer) {
|
func (bc BarChart) drawTitle(r Renderer) {
|
||||||
if len(bc.Title) > 0 && bc.TitleStyle.Show {
|
if len(bc.Title) > 0 && bc.TitleStyle.Show {
|
||||||
Draw.TextWithin(r, bc.Title, bc.box(), bc.styleDefaultsTitle())
|
r.SetFont(bc.TitleStyle.GetFont(bc.GetFont()))
|
||||||
|
r.SetFontColor(bc.TitleStyle.GetFontColor(bc.GetColorPalette().TextColor()))
|
||||||
|
titleFontSize := bc.TitleStyle.GetFontSize(bc.getTitleFontSize())
|
||||||
|
r.SetFontSize(titleFontSize)
|
||||||
|
|
||||||
|
textBox := r.MeasureText(bc.Title)
|
||||||
|
|
||||||
|
textWidth := textBox.Width()
|
||||||
|
textHeight := textBox.Height()
|
||||||
|
|
||||||
|
titleX := (bc.GetWidth() >> 1) - (textWidth >> 1)
|
||||||
|
titleY := bc.TitleStyle.Padding.GetTop(DefaultTitleTop) + textHeight
|
||||||
|
|
||||||
|
r.Text(bc.Title, titleX, titleY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bc BarChart) getCanvasStyle() Style {
|
||||||
|
return bc.Canvas.InheritFrom(bc.styleDefaultsCanvas())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bc BarChart) styleDefaultsCanvas() Style {
|
||||||
|
return Style{
|
||||||
|
FillColor: bc.GetColorPalette().CanvasColor(),
|
||||||
|
StrokeColor: bc.GetColorPalette().CanvasStrokeColor(),
|
||||||
|
StrokeWidth: DefaultCanvasStrokeWidth,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,8 +426,8 @@ func (bc BarChart) box() Box {
|
||||||
dpb := bc.Background.Padding.GetBottom(50)
|
dpb := bc.Background.Padding.GetBottom(50)
|
||||||
|
|
||||||
return Box{
|
return Box{
|
||||||
Top: 20,
|
Top: bc.Background.Padding.GetTop(20),
|
||||||
Left: 20,
|
Left: bc.Background.Padding.GetLeft(20),
|
||||||
Right: bc.GetWidth() - dpr,
|
Right: bc.GetWidth() - dpr,
|
||||||
Bottom: bc.GetHeight() - dpb,
|
Bottom: bc.GetHeight() - dpb,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue