works, ish.
This commit is contained in:
parent
ac5cb1a00b
commit
2e8d196621
|
@ -86,6 +86,9 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
Name: "Elapsed Millis",
|
Name: "Elapsed Millis",
|
||||||
NameStyle: chart.StyleShow(),
|
NameStyle: chart.StyleShow(),
|
||||||
Style: chart.StyleShow(),
|
Style: chart.StyleShow(),
|
||||||
|
TickStyle: chart.Style{
|
||||||
|
TextRotationDegrees: 45.0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
XAxis: chart.XAxis{
|
XAxis: chart.XAxis{
|
||||||
Style: chart.Style{
|
Style: chart.Style{
|
||||||
|
@ -97,10 +100,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
StrokeColor: chart.ColorAlternateGray,
|
StrokeColor: chart.ColorAlternateGray,
|
||||||
StrokeWidth: 1.0,
|
StrokeWidth: 1.0,
|
||||||
},
|
},
|
||||||
TickPosition: chart.TickPositionBetweenTicks,
|
|
||||||
TickStyle: chart.Style{
|
|
||||||
TextRotationDegrees: 45,
|
|
||||||
},
|
|
||||||
GridLines: releases(),
|
GridLines: releases(),
|
||||||
},
|
},
|
||||||
Series: []chart.Series{
|
Series: []chart.Series{
|
||||||
|
|
1
xaxis.go
1
xaxis.go
|
@ -160,6 +160,7 @@ func (xa XAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick
|
||||||
llx := ra.Translate(ticks[index-1].Value)
|
llx := ra.Translate(ticks[index-1].Value)
|
||||||
ltx := canvasBox.Left + llx
|
ltx := canvasBox.Left + llx
|
||||||
finalTickStyle := tickWithAxisStyle.InheritFrom(Style{TextHorizontalAlign: TextHorizontalAlignCenter})
|
finalTickStyle := tickWithAxisStyle.InheritFrom(Style{TextHorizontalAlign: TextHorizontalAlignCenter})
|
||||||
|
|
||||||
Draw.TextWithin(r, t.Label, Box{
|
Draw.TextWithin(r, t.Label, Box{
|
||||||
Left: ltx,
|
Left: ltx,
|
||||||
Right: tx,
|
Right: tx,
|
||||||
|
|
25
yaxis.go
25
yaxis.go
|
@ -125,11 +125,12 @@ func (ya YAxis) Measure(r Renderer, canvasBox Box, ra Range, defaults Style, tic
|
||||||
|
|
||||||
// Render renders the axis.
|
// Render renders the axis.
|
||||||
func (ya YAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, ticks []Tick) {
|
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))
|
sort.Sort(Ticks(ticks))
|
||||||
|
|
||||||
sw := ya.Style.GetStrokeWidth(defaults.StrokeWidth)
|
sw := tickStyle.GetStrokeWidth(defaults.StrokeWidth)
|
||||||
|
|
||||||
var lx int
|
var lx int
|
||||||
var tx int
|
var tx int
|
||||||
|
@ -146,26 +147,30 @@ func (ya YAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick
|
||||||
r.Stroke()
|
r.Stroke()
|
||||||
|
|
||||||
var maxTextWidth int
|
var maxTextWidth int
|
||||||
|
var finalTextX, finalTextY int
|
||||||
for _, t := range ticks {
|
for _, t := range ticks {
|
||||||
ya.TickStyle.InheritFrom(ya.Style.InheritFrom(defaults)).WriteToRenderer(r)
|
|
||||||
|
|
||||||
v := t.Value
|
v := t.Value
|
||||||
ly := canvasBox.Bottom - ra.Translate(v)
|
ly := canvasBox.Bottom - ra.Translate(v)
|
||||||
tb := r.MeasureText(t.Label)
|
|
||||||
|
tb := Draw.MeasureText(r, t.Label, tickStyle)
|
||||||
|
|
||||||
if tb.Width() > maxTextWidth {
|
if tb.Width() > maxTextWidth {
|
||||||
maxTextWidth = tb.Width()
|
maxTextWidth = tb.Width()
|
||||||
}
|
}
|
||||||
|
|
||||||
finalTextX := tx
|
|
||||||
finalTextY := ly + tb.Height()>>1
|
|
||||||
if ya.AxisType == YAxisSecondary {
|
if ya.AxisType == YAxisSecondary {
|
||||||
finalTextX = tx - tb.Width()
|
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)
|
r.MoveTo(lx, ly)
|
||||||
if ya.AxisType == YAxisPrimary {
|
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.LineTo(lx-DefaultHorizontalTickWidth, ly)
|
||||||
}
|
}
|
||||||
r.Stroke()
|
r.Stroke()
|
||||||
|
|
||||||
|
Draw.Text(r, t.Label, finalTextX, finalTextY, tickStyle)
|
||||||
}
|
}
|
||||||
|
|
||||||
nameStyle := ya.NameStyle.InheritFrom(defaults.InheritFrom(Style{TextRotationDegrees: 90}))
|
nameStyle := ya.NameStyle.InheritFrom(defaults.InheritFrom(Style{TextRotationDegrees: 90}))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user