checklen
This commit is contained in:
parent
b1983d6777
commit
9c0d608a46
14
table.go
14
table.go
|
@ -114,6 +114,16 @@ func NewTableGenerator(config *TableConfig) *TableGenerator {
|
||||||
return &TableGenerator{config: config}
|
return &TableGenerator{config: config}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TableData) Check() error {
|
||||||
|
headerLen := len(t.Headers)
|
||||||
|
for _, row := range t.Rows {
|
||||||
|
if headerLen != len(row) {
|
||||||
|
return fmt.Errorf("header length does not match row length")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// 应用缩放因子
|
// 应用缩放因子
|
||||||
func (g *TableGenerator) scaled(value float64) float64 {
|
func (g *TableGenerator) scaled(value float64) float64 {
|
||||||
return value * g.config.ScaleFactor
|
return value * g.config.ScaleFactor
|
||||||
|
@ -281,6 +291,10 @@ func (g *TableGenerator) drawTitle(dc *gg.Context, margin, tableWidth float64, t
|
||||||
|
|
||||||
// 生成自适应表格(高清版本)
|
// 生成自适应表格(高清版本)
|
||||||
func (g *TableGenerator) Generate(data *TableData, filename string) error {
|
func (g *TableGenerator) Generate(data *TableData, filename string) error {
|
||||||
|
err := data.Check()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
g.lock.Lock()
|
g.lock.Lock()
|
||||||
defer g.lock.Unlock()
|
defer g.lock.Unlock()
|
||||||
// 先创建一个临时上下文来测量文本
|
// 先创建一个临时上下文来测量文本
|
||||||
|
|
Loading…
Reference in New Issue