feat: support table render
This commit is contained in:
parent
8c5647f65f
commit
2fb0ebcbf7
6 changed files with 476 additions and 23 deletions
|
|
@ -23,6 +23,7 @@
|
|||
package charts
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/golang/freetype/truetype"
|
||||
|
|
@ -336,3 +337,71 @@ func FunnelRender(values []float64, opts ...OptionFunc) (*Painter, error) {
|
|||
SeriesList: seriesList,
|
||||
}, opts...)
|
||||
}
|
||||
|
||||
func TableRender(opt TableChartOption) (*Painter, error) {
|
||||
if opt.Type == "" {
|
||||
opt.Type = ChartOutputPNG
|
||||
}
|
||||
if opt.Width <= 0 {
|
||||
opt.Width = defaultChartWidth
|
||||
}
|
||||
if opt.Height <= 0 {
|
||||
opt.Height = defaultChartHeight
|
||||
}
|
||||
if opt.Font == nil {
|
||||
opt.Font, _ = chart.GetDefaultFont()
|
||||
}
|
||||
|
||||
p, err := NewPainter(PainterOptions{
|
||||
Type: opt.Type,
|
||||
Width: opt.Width,
|
||||
Height: opt.Height,
|
||||
Font: opt.Font,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
info, err := NewTableChart(p, opt).render()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println(*info)
|
||||
fmt.Println(info.Height)
|
||||
|
||||
p, err = NewPainter(PainterOptions{
|
||||
Type: opt.Type,
|
||||
Width: info.Width,
|
||||
Height: info.Height,
|
||||
Font: opt.Font,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = NewTableChart(p, opt).Render()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// opt := ChartOption{}
|
||||
// for _, fn := range opts {
|
||||
// fn(&opt)
|
||||
// }
|
||||
// opt.fillDefault()
|
||||
// p, err := NewPainter(PainterOptions{
|
||||
// Type: opt.Type,
|
||||
// Width: opt.Width,
|
||||
// Height: opt.Height,
|
||||
// Font: opt.font,
|
||||
// })
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// _, err = NewTableChart(p, TableChartOption{
|
||||
// Header: header,
|
||||
// Data: data,
|
||||
// }).Render()
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
return p, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue