diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ff0c8d07d0..5eed9fd7f5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -31,7 +31,7 @@ jobs: run: env GO111MODULE=on go test -v -timeout 30m -race ./... -coverprofile=coverage.txt -covermode=atomic - name: Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: file: coverage.txt flags: unittests diff --git a/chart_test.go b/chart_test.go index e70f06aa6a..969b57fc7c 100644 --- a/chart_test.go +++ b/chart_test.go @@ -214,7 +214,7 @@ func TestAddChart(t *testing.T) { sheetName, cell string opts *Chart }{ - {sheetName: "Sheet1", cell: "P1", opts: &Chart{Type: Col, Series: series, Format: format, Legend: ChartLegend{Position: "none", ShowLegendKey: true}, Title: []RichTextRun{{Text: "2D Column Chart"}}, PlotArea: plotArea, Border: ChartLine{Type: ChartLineNone}, ShowBlanksAs: "zero", XAxis: ChartAxis{Font: Font{Bold: true, Italic: true, Underline: "dbl", Color: "000000"}, Title: []RichTextRun{{Text: "Primary Horizontal Axis Title"}}}, YAxis: ChartAxis{Font: Font{Bold: false, Italic: false, Underline: "sng", Color: "777777"}, Title: []RichTextRun{{Text: "Primary Vertical Axis Title", Font: &Font{Color: "777777", Bold: true, Italic: true, Size: 12}}}}}}, + {sheetName: "Sheet1", cell: "P1", opts: &Chart{Type: Col, Series: series, Format: format, Legend: ChartLegend{Position: "none", ShowLegendKey: true}, Title: []RichTextRun{{Text: "2D Column Chart"}}, PlotArea: plotArea, Border: ChartLine{Type: ChartLineNone}, ShowBlanksAs: "zero", XAxis: ChartAxis{Font: Font{Bold: true, Italic: true, Underline: "dbl", Family: "Times New Roman", Size: 15, Strike: true, Color: "000000"}, Title: []RichTextRun{{Text: "Primary Horizontal Axis Title"}}}, YAxis: ChartAxis{Font: Font{Bold: false, Italic: false, Underline: "sng", Color: "777777"}, Title: []RichTextRun{{Text: "Primary Vertical Axis Title", Font: &Font{Color: "777777", Bold: true, Italic: true, Size: 12}}}}}}, {sheetName: "Sheet1", cell: "X1", opts: &Chart{Type: ColStacked, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "2D Stacked Column Chart"}}, PlotArea: plotArea, Fill: Fill{Type: "pattern", Pattern: 1}, Border: ChartLine{Type: ChartLineAutomatic}, ShowBlanksAs: "zero"}}, {sheetName: "Sheet1", cell: "P16", opts: &Chart{Type: ColPercentStacked, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "100% Stacked Column Chart"}}, PlotArea: plotArea, Fill: Fill{Type: "pattern", Color: []string{"EEEEEE"}, Pattern: 1}, Border: ChartLine{Type: ChartLineSolid, Width: 2}, ShowBlanksAs: "zero"}}, {sheetName: "Sheet1", cell: "X16", opts: &Chart{Type: Col3DClustered, Series: series, Format: format, Legend: ChartLegend{Position: "bottom", ShowLegendKey: false}, Title: []RichTextRun{{Text: "3D Clustered Column Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}}, diff --git a/drawing.go b/drawing.go index 035ca4b072..bc7b8a47aa 100644 --- a/drawing.go +++ b/drawing.go @@ -1155,6 +1155,34 @@ func (f *File) drawPlotAreaSerAx(opts *Chart) []*cAxs { } } +// drawChartFont provides a function to draw the a:rPr element. +func drawChartFont(fnt *Font, r *aRPr) { + if fnt == nil { + return + } + r.B = fnt.Bold + r.I = fnt.Italic + if idx := inStrSlice(supportedDrawingUnderlineTypes, fnt.Underline, true); idx != -1 { + r.U = supportedDrawingUnderlineTypes[idx] + } + if fnt.Color != "" { + if r.SolidFill == nil { + r.SolidFill = &aSolidFill{} + } + r.SolidFill.SchemeClr = nil + r.SolidFill.SrgbClr = &attrValString{Val: stringPtr(strings.ReplaceAll(strings.ToUpper(fnt.Color), "#", ""))} + } + if fnt.Family != "" { + r.Latin.Typeface = fnt.Family + } + if fnt.Size > 0 { + r.Sz = fnt.Size * 100 + } + if fnt.Strike { + r.Strike = "sngStrike" + } +} + // drawPlotAreaTitles provides a function to draw the c:title element. func (f *File) drawPlotAreaTitles(runs []RichTextRun, vert string) *cTitle { if len(runs) == 0 { @@ -1163,15 +1191,7 @@ func (f *File) drawPlotAreaTitles(runs []RichTextRun, vert string) *cTitle { title := &cTitle{Tx: cTx{Rich: &cRich{}}, Overlay: &attrValBool{Val: boolPtr(false)}} for _, run := range runs { r := &aR{T: run.Text} - if run.Font != nil { - r.RPr.B, r.RPr.I = run.Font.Bold, run.Font.Italic - if run.Font.Color != "" { - r.RPr.SolidFill = &aSolidFill{SrgbClr: &attrValString{Val: stringPtr(run.Font.Color)}} - } - if run.Font.Size > 0 { - r.RPr.Sz = run.Font.Size * 100 - } - } + drawChartFont(run.Font, &r.RPr) title.Tx.Rich.P = append(title.Tx.Rich.P, aP{ PPr: &aPPr{DefRPr: aRPr{}}, R: r, @@ -1241,15 +1261,7 @@ func (f *File) drawPlotAreaTxPr(opts *ChartAxis) *cTxPr { }, } if opts != nil { - cTxPr.P.PPr.DefRPr.B = opts.Font.Bold - cTxPr.P.PPr.DefRPr.I = opts.Font.Italic - if idx := inStrSlice(supportedDrawingUnderlineTypes, opts.Font.Underline, true); idx != -1 { - cTxPr.P.PPr.DefRPr.U = supportedDrawingUnderlineTypes[idx] - } - if opts.Font.Color != "" { - cTxPr.P.PPr.DefRPr.SolidFill.SchemeClr = nil - cTxPr.P.PPr.DefRPr.SolidFill.SrgbClr = &attrValString{Val: stringPtr(strings.ReplaceAll(strings.ToUpper(opts.Font.Color), "#", ""))} - } + drawChartFont(&opts.Font, &cTxPr.P.PPr.DefRPr) } return cTxPr }