From 3d02726ad4dc3bc6a92d5b68ef8421ac4db44076 Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 14 Oct 2022 00:48:16 +0800 Subject: This closes #320, support custom chart axis font style --- drawing.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'drawing.go') diff --git a/drawing.go b/drawing.go index 2da2573..974d627 100644 --- a/drawing.go +++ b/drawing.go @@ -1017,7 +1017,7 @@ func (f *File) drawPlotAreaCatAx(opts *chartOptions) []*cAxs { MinorTickMark: &attrValString{Val: stringPtr("none")}, TickLblPos: &attrValString{Val: stringPtr("nextTo")}, SpPr: f.drawPlotAreaSpPr(), - TxPr: f.drawPlotAreaTxPr(), + TxPr: f.drawPlotAreaTxPr(&opts.YAxis), CrossAx: &attrValInt{Val: intPtr(753999904)}, Crosses: &attrValString{Val: stringPtr("autoZero")}, Auto: &attrValBool{Val: boolPtr(true)}, @@ -1071,7 +1071,7 @@ func (f *File) drawPlotAreaValAx(opts *chartOptions) []*cAxs { MinorTickMark: &attrValString{Val: stringPtr("none")}, TickLblPos: &attrValString{Val: stringPtr("nextTo")}, SpPr: f.drawPlotAreaSpPr(), - TxPr: f.drawPlotAreaTxPr(), + TxPr: f.drawPlotAreaTxPr(&opts.XAxis), CrossAx: &attrValInt{Val: intPtr(754001152)}, Crosses: &attrValString{Val: stringPtr("autoZero")}, CrossBetween: &attrValString{Val: stringPtr(chartValAxCrossBetween[opts.Type])}, @@ -1114,7 +1114,7 @@ func (f *File) drawPlotAreaSerAx(opts *chartOptions) []*cAxs { AxPos: &attrValString{Val: stringPtr(catAxPos[opts.XAxis.ReverseOrder])}, TickLblPos: &attrValString{Val: stringPtr("nextTo")}, SpPr: f.drawPlotAreaSpPr(), - TxPr: f.drawPlotAreaTxPr(), + TxPr: f.drawPlotAreaTxPr(nil), CrossAx: &attrValInt{Val: intPtr(753999904)}, }, } @@ -1140,8 +1140,8 @@ func (f *File) drawPlotAreaSpPr() *cSpPr { } // drawPlotAreaTxPr provides a function to draw the c:txPr element. -func (f *File) drawPlotAreaTxPr() *cTxPr { - return &cTxPr{ +func (f *File) drawPlotAreaTxPr(opts *chartAxisOptions) *cTxPr { + cTxPr := &cTxPr{ BodyPr: aBodyPr{ Rot: -60000000, SpcFirstLastPara: true, @@ -1176,6 +1176,18 @@ func (f *File) drawPlotAreaTxPr() *cTxPr { EndParaRPr: &aEndParaRPr{Lang: "en-US"}, }, } + if opts != nil { + cTxPr.P.PPr.DefRPr.B = opts.NumFont.Bold + cTxPr.P.PPr.DefRPr.I = opts.NumFont.Italic + if idx := inStrSlice(supportedDrawingUnderlineTypes, opts.NumFont.Underline, true); idx != -1 { + cTxPr.P.PPr.DefRPr.U = supportedDrawingUnderlineTypes[idx] + } + if opts.NumFont.Color != "" { + cTxPr.P.PPr.DefRPr.SolidFill.SchemeClr = nil + cTxPr.P.PPr.DefRPr.SolidFill.SrgbClr = &attrValString{Val: stringPtr(strings.ReplaceAll(strings.ToUpper(opts.NumFont.Color), "#", ""))} + } + } + return cTxPr } // drawingParser provides a function to parse drawingXML. In order to solve -- cgit v1.2.1