Skip to content

Commit 5f446f2

Browse files
committed
This closes qax-os#2025, support set chart axis text direction and rotation
- Add new field Alignment in the ChartAxis data type - Update unit tests - Update doc of the AddHeaderFooterImage function
1 parent 30d3561 commit 5f446f2

File tree

6 files changed

+36
-6
lines changed

6 files changed

+36
-6
lines changed

chart.go

+20
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ func (opts *Chart) parseTitle() {
850850
// ReverseOrder
851851
// Maximum
852852
// Minimum
853+
// Alignment
853854
// Font
854855
// NumFmt
855856
// Title
@@ -864,6 +865,7 @@ func (opts *Chart) parseTitle() {
864865
// ReverseOrder
865866
// Maximum
866867
// Minimum
868+
// Alignment
867869
// Font
868870
// LogBase
869871
// NumFmt
@@ -896,6 +898,24 @@ func (opts *Chart) parseTitle() {
896898
// Minimum: Specifies that the fixed minimum, 0 is auto. The 'Minimum' property
897899
// is optional. The default value is auto.
898900
//
901+
// Alignment: Specifies that the alignment of the horizontal and vertical axis.
902+
// The properties of font that can be set are:
903+
//
904+
// TextRotation
905+
// Vertical
906+
//
907+
// The value of 'TextRotation' that can be set from -90 to 90:
908+
//
909+
// The value of 'Vertical' that can be set are:
910+
//
911+
// horz
912+
// vert
913+
// vert270
914+
// wordArtVert
915+
// eaVert
916+
// mongolianVert
917+
// wordArtVertRtl
918+
//
899919
// Font: Specifies that the font of the horizontal and vertical axis. The
900920
// properties of font that can be set are:
901921
//

chart_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ func TestAddChart(t *testing.T) {
216216
}{
217217
{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}}}}}},
218218
{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"}},
219-
{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"}},
219+
{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", XAxis: ChartAxis{Alignment: Alignment{Vertical: "wordArtVertRtl", TextRotation: 0}}}},
220220
{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"}},
221-
{sheetName: "Sheet1", cell: "P30", opts: &Chart{Type: Col3DStacked, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "3D Stacked Column Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}},
221+
{sheetName: "Sheet1", cell: "P30", opts: &Chart{Type: Col3DStacked, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "3D Stacked Column Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero", XAxis: ChartAxis{Alignment: Alignment{Vertical: "vert", TextRotation: 0}}}},
222222
{sheetName: "Sheet1", cell: "X30", opts: &Chart{Type: Col3DPercentStacked, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "3D 100% Stacked Column Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}},
223223
{sheetName: "Sheet1", cell: "X45", opts: &Chart{Type: Radar, Series: series, Format: format, Legend: ChartLegend{Position: "top_right", ShowLegendKey: false}, Title: []RichTextRun{{Text: "Radar Chart"}}, PlotArea: plotArea, ShowBlanksAs: "span"}},
224224
{sheetName: "Sheet1", cell: "AF1", opts: &Chart{Type: Col3DConeStacked, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "3D Column Cone Stacked Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}},
@@ -233,7 +233,7 @@ func TestAddChart(t *testing.T) {
233233
{sheetName: "Sheet1", cell: "AV16", opts: &Chart{Type: Col3DCylinderClustered, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "3D Column Cylinder Clustered Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}},
234234
{sheetName: "Sheet1", cell: "AV30", opts: &Chart{Type: Col3DCylinderPercentStacked, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "3D Column Cylinder Percent Stacked Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}},
235235
{sheetName: "Sheet1", cell: "AV45", opts: &Chart{Type: Col3DCylinder, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "3D Column Cylinder Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}},
236-
{sheetName: "Sheet1", cell: "P45", opts: &Chart{Type: Col3D, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "3D Column Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}},
236+
{sheetName: "Sheet1", cell: "P45", opts: &Chart{Type: Col3D, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "3D Column Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero", XAxis: ChartAxis{Alignment: Alignment{Vertical: "vert270", TextRotation: 0}}}},
237237
{sheetName: "Sheet2", cell: "P1", opts: &Chart{Type: Line3D, Series: series2, Format: format, Legend: ChartLegend{Position: "top", ShowLegendKey: false}, Title: []RichTextRun{{Text: "3D Line Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero", XAxis: ChartAxis{MajorGridLines: true, MinorGridLines: true, TickLabelSkip: 1, NumFmt: ChartNumFmt{CustomNumFmt: "General"}}, YAxis: ChartAxis{MajorGridLines: true, MinorGridLines: true, MajorUnit: 1, NumFmt: ChartNumFmt{CustomNumFmt: "General"}}}},
238238
{sheetName: "Sheet2", cell: "X1", opts: &Chart{Type: Scatter, Series: series, Format: format, Legend: ChartLegend{Position: "bottom", ShowLegendKey: false}, Title: []RichTextRun{{Text: "Scatter Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}},
239239
{sheetName: "Sheet2", cell: "P16", opts: &Chart{Type: Doughnut, Series: series3, Format: format, Legend: ChartLegend{Position: "right", ShowLegendKey: false}, Title: []RichTextRun{{Text: "Doughnut Chart"}}, PlotArea: ChartPlotArea{ShowBubbleSize: false, ShowCatName: false, ShowLeaderLines: false, ShowPercent: true, ShowSerName: false, ShowVal: false}, ShowBlanksAs: "zero", HoleSize: 30}},

drawing.go

+6
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,12 @@ func (f *File) drawPlotAreaTxPr(opts *ChartAxis) *cTxPr {
12561256
}
12571257
if opts != nil {
12581258
drawChartFont(&opts.Font, &cTxPr.P.PPr.DefRPr)
1259+
if -90 <= opts.Alignment.TextRotation && opts.Alignment.TextRotation <= 90 {
1260+
cTxPr.BodyPr.Rot = opts.Alignment.TextRotation * 60000
1261+
}
1262+
if idx := inStrSlice(supportedDrawingTextVerticalType, opts.Alignment.Vertical, true); idx != -1 {
1263+
cTxPr.BodyPr.Vert = supportedDrawingTextVerticalType[idx]
1264+
}
12591265
}
12601266
return cTxPr
12611267
}

templates.go

+4
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,10 @@ var supportedDrawingUnderlineTypes = []string{
495495
"wavyDbl",
496496
}
497497

498+
// supportedDrawingTextVerticalType defined supported text vertical types in
499+
// drawing markup language.
500+
var supportedDrawingTextVerticalType = []string{"horz", "vert", "vert270", "wordArtVert", "eaVert", "mongolianVert", "wordArtVertRtl"}
501+
498502
// supportedPositioning defined supported positioning types.
499503
var supportedPositioning = []string{"absolute", "oneCell", "twoCell"}
500504

vml.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1083,9 +1083,8 @@ func extractVMLFont(font []decodeVMLFont) []RichTextRun {
10831083
}
10841084

10851085
// AddHeaderFooterImage provides a mechanism to set the graphics that can be
1086-
// referenced in the header and footer definitions via &G, file base name,
1087-
// extension name and file bytes, supported image types: EMF, EMZ, GIF, JPEG,
1088-
// JPG, PNG, SVG, TIF, TIFF, WMF, and WMZ.
1086+
// referenced in the header and footer definitions via &G, supported image
1087+
// types: EMF, EMZ, GIF, JPEG, JPG, PNG, SVG, TIF, TIFF, WMF, and WMZ.
10891088
//
10901089
// The extension should be provided with a "." in front, e.g. ".png".
10911090
// The width and height should have units in them, e.g. "100pt".

xmlChart.go

+1
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ type ChartAxis struct {
540540
Secondary bool
541541
Maximum *float64
542542
Minimum *float64
543+
Alignment Alignment
543544
Font Font
544545
LogBase float64
545546
NumFmt ChartNumFmt

0 commit comments

Comments
 (0)