works, ish.

This commit is contained in:
Will Charczuk 2016-10-21 12:50:40 -07:00
parent ac5cb1a00b
commit 2e8d196621
3 changed files with 20 additions and 13 deletions

View file

@ -86,6 +86,9 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
Name: "Elapsed Millis",
NameStyle: chart.StyleShow(),
Style: chart.StyleShow(),
TickStyle: chart.Style{
TextRotationDegrees: 45.0,
},
},
XAxis: chart.XAxis{
Style: chart.Style{
@ -97,10 +100,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
StrokeColor: chart.ColorAlternateGray,
StrokeWidth: 1.0,
},
TickPosition: chart.TickPositionBetweenTicks,
TickStyle: chart.Style{
TextRotationDegrees: 45,
},
GridLines: releases(),
},
Series: []chart.Series{

View file

@ -160,6 +160,7 @@ func (xa XAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick
llx := ra.Translate(ticks[index-1].Value)
ltx := canvasBox.Left + llx
finalTickStyle := tickWithAxisStyle.InheritFrom(Style{TextHorizontalAlign: TextHorizontalAlignCenter})
Draw.TextWithin(r, t.Label, Box{
Left: ltx,
Right: tx,

View file

@ -125,11 +125,12 @@ func (ya YAxis) Measure(r Renderer, canvasBox Box, ra Range, defaults Style, tic
// Render renders the axis.
func (ya YAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, ticks []Tick) {
ya.Style.InheritFrom(defaults).WriteToRenderer(r)
tickStyle := ya.TickStyle.InheritFrom(ya.Style.InheritFrom(defaults))
tickStyle.WriteToRenderer(r)
sort.Sort(Ticks(ticks))
sw := ya.Style.GetStrokeWidth(defaults.StrokeWidth)
sw := tickStyle.GetStrokeWidth(defaults.StrokeWidth)
var lx int
var tx int
@ -146,26 +147,30 @@ func (ya YAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick
r.Stroke()
var maxTextWidth int
var finalTextX, finalTextY int
for _, t := range ticks {
ya.TickStyle.InheritFrom(ya.Style.InheritFrom(defaults)).WriteToRenderer(r)
v := t.Value
ly := canvasBox.Bottom - ra.Translate(v)
tb := r.MeasureText(t.Label)
tb := Draw.MeasureText(r, t.Label, tickStyle)
if tb.Width() > maxTextWidth {
maxTextWidth = tb.Width()
}
finalTextX := tx
finalTextY := ly + tb.Height()>>1
if ya.AxisType == YAxisSecondary {
finalTextX = tx - tb.Width()
} else {
finalTextX = tx
}
r.Text(t.Label, finalTextX, finalTextY)
if tickStyle.TextRotationDegrees == 0 {
finalTextY = ly + tb.Height()>>1
} else {
finalTextY = ly
}
ya.Style.InheritFrom(defaults).WriteToRenderer(r)
tickStyle.WriteToRenderer(r)
r.MoveTo(lx, ly)
if ya.AxisType == YAxisPrimary {
@ -174,6 +179,8 @@ func (ya YAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick
r.LineTo(lx-DefaultHorizontalTickWidth, ly)
}
r.Stroke()
Draw.Text(r, t.Label, finalTextX, finalTextY, tickStyle)
}
nameStyle := ya.NameStyle.InheritFrom(defaults.InheritFrom(Style{TextRotationDegrees: 90}))