Skip to content

Commit 431c310

Browse files
authored
This closes qax-os#1944, add new TickLabelPosition field in the ChartAxis data type (qax-os#1946)
- Introduce new exported ChartTickLabelPositionType enumeration - Update unit tests
1 parent 53b6515 commit 431c310

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed

chart.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ const (
9090
ChartLineAutomatic
9191
)
9292

93+
// ChartTickLabelPositionType is the type of supported chart tick label position
94+
// types.
95+
type ChartTickLabelPositionType byte
96+
97+
// This section defines the supported chart tick label position types
98+
// enumeration.
99+
const (
100+
ChartTickLabelNextToAxis ChartTickLabelPositionType = iota
101+
ChartTickLabelHigh
102+
ChartTickLabelLow
103+
ChartTickLabelNone
104+
)
105+
93106
// This section defines the default value of chart properties.
94107
var (
95108
chartView3DRotX = map[ChartType]int{
@@ -484,7 +497,13 @@ var (
484497
true: "r",
485498
false: "l",
486499
}
487-
valTickLblPos = map[ChartType]string{
500+
tickLblPosVal = map[ChartTickLabelPositionType]string{
501+
ChartTickLabelNextToAxis: "nextTo",
502+
ChartTickLabelHigh: "high",
503+
ChartTickLabelLow: "low",
504+
ChartTickLabelNone: "none",
505+
}
506+
tickLblPosNone = map[ChartType]string{
488507
Contour: "none",
489508
WireframeContour: "none",
490509
}

chart_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func TestAddChart(t *testing.T) {
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}},
240-
{sheetName: "Sheet2", cell: "X16", opts: &Chart{Type: Line, Series: series2, Format: format, Legend: ChartLegend{Position: "top", ShowLegendKey: false}, Title: []RichTextRun{{Text: "Line Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero", XAxis: ChartAxis{MajorGridLines: true, MinorGridLines: true, TickLabelSkip: 1}, YAxis: ChartAxis{MajorGridLines: true, MinorGridLines: true, MajorUnit: 1}}},
240+
{sheetName: "Sheet2", cell: "X16", opts: &Chart{Type: Line, Series: series2, Format: format, Legend: ChartLegend{Position: "top", ShowLegendKey: false}, Title: []RichTextRun{{Text: "Line Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero", XAxis: ChartAxis{MajorGridLines: true, MinorGridLines: true, TickLabelSkip: 1, TickLabelPosition: ChartTickLabelLow}, YAxis: ChartAxis{MajorGridLines: true, MinorGridLines: true, MajorUnit: 1}}},
241241
{sheetName: "Sheet2", cell: "P32", opts: &Chart{Type: Pie3D, Series: series3, Format: format, Legend: ChartLegend{Position: "bottom", ShowLegendKey: false}, Title: []RichTextRun{{Text: "3D Column Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}},
242242
{sheetName: "Sheet2", cell: "X32", opts: &Chart{Type: Pie, Series: series3, Format: format, Legend: ChartLegend{Position: "bottom", ShowLegendKey: false}, Title: []RichTextRun{{Text: "Pie Chart"}}, PlotArea: ChartPlotArea{ShowBubbleSize: true, ShowCatName: false, ShowLeaderLines: false, ShowPercent: true, ShowSerName: false, ShowVal: false, NumFmt: ChartNumFmt{CustomNumFmt: "0.00%;0;;"}}, ShowBlanksAs: "gap"}},
243243
// bar series chart

drawing.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ func (f *File) drawPlotAreaCatAx(pa *cPlotArea, opts *Chart) []*cAxs {
10011001
MajorTickMark: &attrValString{Val: stringPtr("none")},
10021002
MinorTickMark: &attrValString{Val: stringPtr("none")},
10031003
Title: f.drawPlotAreaTitles(opts.XAxis.Title, ""),
1004-
TickLblPos: &attrValString{Val: stringPtr("nextTo")},
1004+
TickLblPos: &attrValString{Val: stringPtr(tickLblPosVal[opts.XAxis.TickLabelPosition])},
10051005
SpPr: f.drawPlotAreaSpPr(),
10061006
TxPr: f.drawPlotAreaTxPr(&opts.XAxis),
10071007
CrossAx: &attrValInt{Val: intPtr(100000001)},
@@ -1063,7 +1063,7 @@ func (f *File) drawPlotAreaValAx(pa *cPlotArea, opts *Chart) []*cAxs {
10631063
},
10641064
MajorTickMark: &attrValString{Val: stringPtr("none")},
10651065
MinorTickMark: &attrValString{Val: stringPtr("none")},
1066-
TickLblPos: &attrValString{Val: stringPtr("nextTo")},
1066+
TickLblPos: &attrValString{Val: stringPtr(tickLblPosVal[opts.YAxis.TickLabelPosition])},
10671067
SpPr: f.drawPlotAreaSpPr(),
10681068
TxPr: f.drawPlotAreaTxPr(&opts.YAxis),
10691069
CrossAx: &attrValInt{Val: intPtr(100000000)},
@@ -1079,7 +1079,7 @@ func (f *File) drawPlotAreaValAx(pa *cPlotArea, opts *Chart) []*cAxs {
10791079
if opts.YAxis.MinorGridLines {
10801080
ax.MinorGridlines = &cChartLines{SpPr: f.drawPlotAreaSpPr()}
10811081
}
1082-
if pos, ok := valTickLblPos[opts.Type]; ok {
1082+
if pos, ok := tickLblPosNone[opts.Type]; ok {
10831083
ax.TickLblPos.Val = stringPtr(pos)
10841084
}
10851085
if opts.YAxis.MajorUnit != 0 {
@@ -1115,7 +1115,7 @@ func (f *File) drawPlotAreaSerAx(opts *Chart) []*cAxs {
11151115
},
11161116
Delete: &attrValBool{Val: boolPtr(opts.YAxis.None)},
11171117
AxPos: &attrValString{Val: stringPtr(catAxPos[opts.XAxis.ReverseOrder])},
1118-
TickLblPos: &attrValString{Val: stringPtr("nextTo")},
1118+
TickLblPos: &attrValString{Val: stringPtr(tickLblPosVal[opts.YAxis.TickLabelPosition])},
11191119
SpPr: f.drawPlotAreaSpPr(),
11201120
TxPr: f.drawPlotAreaTxPr(nil),
11211121
CrossAx: &attrValInt{Val: intPtr(100000001)},

xmlChart.go

+15-14
Original file line numberDiff line numberDiff line change
@@ -530,20 +530,21 @@ type ChartNumFmt struct {
530530

531531
// ChartAxis directly maps the format settings of the chart axis.
532532
type ChartAxis struct {
533-
None bool
534-
MajorGridLines bool
535-
MinorGridLines bool
536-
MajorUnit float64
537-
TickLabelSkip int
538-
ReverseOrder bool
539-
Secondary bool
540-
Maximum *float64
541-
Minimum *float64
542-
Font Font
543-
LogBase float64
544-
NumFmt ChartNumFmt
545-
Title []RichTextRun
546-
axID int
533+
None bool
534+
MajorGridLines bool
535+
MinorGridLines bool
536+
MajorUnit float64
537+
TickLabelPosition ChartTickLabelPositionType
538+
TickLabelSkip int
539+
ReverseOrder bool
540+
Secondary bool
541+
Maximum *float64
542+
Minimum *float64
543+
Font Font
544+
LogBase float64
545+
NumFmt ChartNumFmt
546+
Title []RichTextRun
547+
axID int
547548
}
548549

549550
// ChartDimension directly maps the dimension of the chart.

0 commit comments

Comments
 (0)