feat: support text rotation for series label, #38
This commit is contained in:
parent
ef04ac14ab
commit
d5533447f5
3 changed files with 36 additions and 7 deletions
26
axis.go
26
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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
8
xaxis.go
8
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue