diff --git a/axis.go b/axis.go index 578813c..3f71451 100644 --- a/axis.go +++ b/axis.go @@ -75,7 +75,11 @@ type AxisOption struct { SplitLineShow bool // The color of split line SplitLineColor Color - Unit int + // The text rotation of label + TextRotation float64 + // The offset of label + LabelOffset Box + Unit int } func (a *axisPainter) Render() (Box, error) { @@ -153,7 +157,15 @@ func (a *axisPainter) Render() (Box, error) { } top.SetDrawingStyle(style).OverrideTextStyle(style) + isTextRotation := opt.TextRotation != 0 + + if isTextRotation { + top.SetTextRotation(opt.TextRotation) + } textMaxWidth, textMaxHeight := top.MeasureTextMaxWidthHeight(data) + if isTextRotation { + top.ClearTextRotation() + } // 增加30px来计算文本展示区域 textFillWidth := float64(textMaxWidth + 20) @@ -261,11 +273,13 @@ func (a *axisPainter) Render() (Box, error) { Top: labelPaddingTop, Right: labelPaddingRight, })).MultiText(MultiTextOption{ - Align: textAlign, - TextList: data, - Orient: orient, - Unit: unit, - Position: labelPosition, + Align: textAlign, + TextList: data, + Orient: orient, + Unit: unit, + Position: labelPosition, + TextRotation: opt.TextRotation, + Offset: opt.LabelOffset, }) // 显示辅助线 if opt.SplitLineShow { diff --git a/painter.go b/painter.go index a0f81ed..71d205f 100644 --- a/painter.go +++ b/painter.go @@ -71,6 +71,9 @@ type MultiTextOption struct { Unit int Position string Align string + // The text rotation of label + TextRotation float64 + Offset Box } type GridOption struct { @@ -682,10 +685,13 @@ func (p *Painter) MultiText(opt MultiTextOption) *Painter { } else { values = autoDivide(width, count) } + offset := opt.Offset for index, text := range opt.TextList { if opt.Unit != 0 && index%opt.Unit != showIndex { continue } + p.ClearTextRotation() + p.SetTextRotation(opt.TextRotation) box := p.MeasureText(text) start := values[index] if positionCenter { @@ -706,8 +712,11 @@ func (p *Painter) MultiText(opt MultiTextOption) *Painter { } else { x = start - box.Width()>>1 } + x += offset.Left + y += offset.Top p.Text(text, x, y) } + p.ClearTextRotation() return p } diff --git a/xaxis.go b/xaxis.go index 00636a5..95578ff 100644 --- a/xaxis.go +++ b/xaxis.go @@ -47,7 +47,11 @@ type XAxisOption struct { // The line color of axis StrokeColor Color // The color of label - FontColor Color + FontColor Color + // The text rotation of label + TextRotation float64 + // The offset of label + LabelOffset Box isValueAxis bool } @@ -81,6 +85,8 @@ func (opt *XAxisOption) ToAxisOption() AxisOption { FontColor: opt.FontColor, Show: opt.Show, SplitLineColor: opt.Theme.GetAxisSplitLineColor(), + TextRotation: opt.TextRotation, + LabelOffset: opt.LabelOffset, } if opt.isValueAxis { axisOpt.SplitLineShow = true