row style
This commit is contained in:
@@ -10,12 +10,6 @@ import (
|
|||||||
"golang.org/x/image/math/fixed"
|
"golang.org/x/image/math/fixed"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TableBlock struct {
|
|
||||||
Title string
|
|
||||||
Header []string
|
|
||||||
Rows []any
|
|
||||||
}
|
|
||||||
|
|
||||||
type Document struct {
|
type Document struct {
|
||||||
Blocks []TableBlock
|
Blocks []TableBlock
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,10 +181,19 @@ func DrawTableWarm(header []string, rows []any) image.Image {
|
|||||||
y := headerHeight
|
y := headerHeight
|
||||||
for rowIndex, row := range rows {
|
for rowIndex, row := range rows {
|
||||||
bg := rowBg1
|
bg := rowBg1
|
||||||
|
|
||||||
if rowIndex%2 == 1 {
|
if rowIndex%2 == 1 {
|
||||||
bg = rowBg2
|
bg = rowBg2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sCells := row
|
||||||
|
|
||||||
|
switch rt := row.(type) {
|
||||||
|
case ITableRow:
|
||||||
|
bg = rt.GetBackgroundColor()
|
||||||
|
sCells = rt.GetCells()
|
||||||
|
}
|
||||||
|
|
||||||
// фон строки
|
// фон строки
|
||||||
for xx := 0; xx < imgWidth; xx++ {
|
for xx := 0; xx < imgWidth; xx++ {
|
||||||
for yy := 0; yy < rowHeight; yy++ {
|
for yy := 0; yy < rowHeight; yy++ {
|
||||||
@@ -197,7 +206,7 @@ func DrawTableWarm(header []string, rows []any) image.Image {
|
|||||||
img.Set(xx, y, dividerCol)
|
img.Set(xx, y, dividerCol)
|
||||||
}
|
}
|
||||||
|
|
||||||
cells := rowToStrings(row)
|
cells := rowToStrings(sCells)
|
||||||
|
|
||||||
x = 0
|
x = 0
|
||||||
for i := 0; i < colCount && i < len(cells); i++ {
|
for i := 0; i < colCount && i < len(cells); i++ {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package image_table
|
package image_table
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image/color"
|
||||||
"image/png"
|
"image/png"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -44,7 +45,10 @@ func TestDocument(t *testing.T) {
|
|||||||
Header: []string{"ID", "Name", "Age"},
|
Header: []string{"ID", "Name", "Age"},
|
||||||
Rows: []any{
|
Rows: []any{
|
||||||
[]any{1, "Иван", 30},
|
[]any{1, "Иван", 30},
|
||||||
[]any{2, "Пётр", 25},
|
&TableBlockStyle{
|
||||||
|
Cells: []any{2, "Пётр", 25},
|
||||||
|
BackgroundColor: color.RGBA{R: 225, G: 255, B: 225, A: 255},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -52,7 +56,10 @@ func TestDocument(t *testing.T) {
|
|||||||
Header: []string{"Метрика", "Значение"},
|
Header: []string{"Метрика", "Значение"},
|
||||||
Rows: []any{
|
Rows: []any{
|
||||||
[]any{"Requests", 12000},
|
[]any{"Requests", 12000},
|
||||||
[]any{"Errors", 37},
|
&TableBlockStyle{
|
||||||
|
Cells: []any{"Errors", 37},
|
||||||
|
BackgroundColor: color.RGBA{R: 255, G: 225, B: 225, A: 255},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
8
itablerow.go
Normal file
8
itablerow.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package image_table
|
||||||
|
|
||||||
|
import "image/color"
|
||||||
|
|
||||||
|
type ITableRow interface {
|
||||||
|
GetCells() []any
|
||||||
|
GetBackgroundColor() color.RGBA
|
||||||
|
}
|
||||||
7
table_block.go
Normal file
7
table_block.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package image_table
|
||||||
|
|
||||||
|
type TableBlock struct {
|
||||||
|
Title string
|
||||||
|
Header []string
|
||||||
|
Rows []any
|
||||||
|
}
|
||||||
16
tablle_block_style.go
Normal file
16
tablle_block_style.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package image_table
|
||||||
|
|
||||||
|
import "image/color"
|
||||||
|
|
||||||
|
type TableBlockStyle struct {
|
||||||
|
Cells []any
|
||||||
|
BackgroundColor color.RGBA
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TableBlockStyle) GetCells() []any {
|
||||||
|
return s.Cells
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TableBlockStyle) GetBackgroundColor() color.RGBA {
|
||||||
|
return s.BackgroundColor
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user