feat: support mark line and mark point render
This commit is contained in:
parent
72e11e49b1
commit
8a5990fe8f
10 changed files with 2046 additions and 19 deletions
24
legend.go
24
legend.go
|
|
@ -29,13 +29,13 @@ import (
|
|||
|
||||
type legendPainter struct {
|
||||
p *Painter
|
||||
opt *LegendPainterOption
|
||||
opt *LegendOption
|
||||
}
|
||||
|
||||
const IconRect = "rect"
|
||||
const IconLineDot = "lineDot"
|
||||
|
||||
type LegendPainterOption struct {
|
||||
type LegendOption struct {
|
||||
Theme ColorPalette
|
||||
// Text array of legend
|
||||
Data []string
|
||||
|
|
@ -58,7 +58,17 @@ type LegendPainterOption struct {
|
|||
FontColor Color
|
||||
}
|
||||
|
||||
func NewLegendPainter(p *Painter, opt LegendPainterOption) *legendPainter {
|
||||
func NewLegendOption(labels []string, left ...string) LegendOption {
|
||||
opt := LegendOption{
|
||||
Data: labels,
|
||||
}
|
||||
if len(left) != 0 {
|
||||
opt.Left = left[0]
|
||||
}
|
||||
return opt
|
||||
}
|
||||
|
||||
func NewLegendPainter(p *Painter, opt LegendOption) *legendPainter {
|
||||
return &legendPainter{
|
||||
p: p,
|
||||
opt: &opt,
|
||||
|
|
@ -71,6 +81,12 @@ func (l *legendPainter) Render() (Box, error) {
|
|||
if theme == nil {
|
||||
theme = l.p.theme
|
||||
}
|
||||
if opt.FontSize == 0 {
|
||||
opt.FontSize = theme.GetFontSize()
|
||||
}
|
||||
if opt.FontColor.IsZero() {
|
||||
opt.FontColor = theme.GetTextColor()
|
||||
}
|
||||
p := l.p
|
||||
p.SetTextStyle(Style{
|
||||
FontSize: opt.FontSize,
|
||||
|
|
@ -129,7 +145,7 @@ func (l *legendPainter) Render() (Box, error) {
|
|||
top, _ := strconv.Atoi(opt.Top)
|
||||
|
||||
x := int(left)
|
||||
y := int(top)
|
||||
y := int(top) + 10
|
||||
x0 := x
|
||||
y0 := y
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue