Skip to content

Commit afe6925

Browse files
committed
feature: refactor guides
1 parent 60e7a44 commit afe6925

File tree

7 files changed

+26
-8
lines changed

7 files changed

+26
-8
lines changed

cmd/timeseries/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func main() {
2121
prop := props.Chart{
2222
XLabels: []float64{0, 10, 20, 30},
2323
YLabels: []float64{0, 1, 2},
24-
Font: &props.Font{
24+
Font: props.Font{
2525
Family: fontfamily.Arial,
2626
Style: fontstyle.Normal,
2727
Size: 7,

docs/assets/pdf/timeseries.pdf

0 Bytes
Binary file not shown.

internal/providers/gofpdf/chart/chart.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ func NewChart(pdf gofpdfwrapper.Fpdf, font core.Font) *chart {
2424
}
2525

2626
func (s chart) Add(margins *entity.Margins, cell *entity.Cell, width float64, height float64, props *props.Chart) {
27-
if props.Font != nil {
28-
s.font.SetFont(props.Font.Family, props.Font.Style, props.Font.Size)
29-
}
27+
s.font.SetFont(props.Font.Family, props.Font.Style, props.Font.Size)
3028

3129
stepX, stepY := s.GetSteps(width, height, cell)
3230
s.horizontalLine(margins, cell, width, stepX, props)

internal/providers/gofpdf/chart/heatmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (s heatMap) Add(heatMap [][]int, cell *entity.Cell, margins *entity.Margins
5858
}
5959
}
6060

61-
s.chart.Add(margins, cell, width, height, prop.Chart)
61+
s.chart.Add(margins, cell, width, height, &prop.Chart)
6262
}
6363

6464
func GetHeatColor(i int, total int) (int, int, int) {

pkg/components/chart/timeseries.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func NewTimeSeries(timeSeriesList []entity.TimeSeries, ps ...props.Chart) core.C
2020
if len(ps) > 0 {
2121
prop = ps[0]
2222
}
23+
prop.MakeValid()
2324

2425
return &TimeSeries{
2526
timeSeriesList: timeSeriesList,

pkg/props/chart.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
package props
22

3+
import (
4+
"github.com/johnfercher/maroto/v2/pkg/consts/fontfamily"
5+
"github.com/johnfercher/maroto/v2/pkg/consts/fontstyle"
6+
)
7+
38
type Chart struct {
49
XLabels []float64
510
YLabels []float64
6-
Font *Font
11+
Font Font
12+
}
13+
14+
func (c *Chart) MakeValid() {
15+
if c.Font.Family == "" {
16+
c.Font.Family = fontfamily.Arial
17+
}
18+
19+
if c.Font.Style == "" {
20+
c.Font.Style = fontstyle.Normal
21+
}
22+
23+
if c.Font.Size == 0.0 {
24+
c.Font.Size = 8.0
25+
}
726
}

pkg/props/heatmap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ type HeatMap struct {
44
TransparentValues []int
55
HalfColor bool
66
InvertScale bool
7-
Chart *Chart
7+
Chart Chart
88
}
99

1010
func (h *HeatMap) MakeValid() {
11-
11+
h.Chart.MakeValid()
1212
}
1313

1414
func (h *HeatMap) ToMap() map[string]any {

0 commit comments

Comments
 (0)