Skip to content

Commit 8a99deb

Browse files
authored
This closes #1862, closes #1904 and closes #1948 (#1742)
- Support set the data point color for doughnut, pie and 3D pie chart - Add new ChartDataPoint data type - Add new field DataPoint in the ChartSeries data type - Automating dependabot tasks with GitHub Actions - Upgrade GitHub Action tool chains version
1 parent 97fd800 commit 8a99deb

File tree

7 files changed

+43
-15
lines changed

7 files changed

+43
-15
lines changed

.github/dependabot.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 2
22
updates:
3-
- package-ecosystem: github-actions
4-
directory: /
5-
schedule:
6-
interval: monthly
7-
3+
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ jobs:
2020

2121
steps:
2222
- name: Checkout repository
23-
uses: actions/checkout@v5
23+
uses: actions/checkout@v6
2424

2525
# Initializes the CodeQL tools for scanning.
2626
- name: Initialize CodeQL
27-
uses: github/codeql-action/init@v3
27+
uses: github/codeql-action/init@v4
2828
with:
2929
languages: ${{ matrix.language }}
3030

3131
- name: Autobuild
32-
uses: github/codeql-action/autobuild@v3
32+
uses: github/codeql-action/autobuild@v4
3333

3434
- name: Perform CodeQL Analysis
35-
uses: github/codeql-action/analyze@v3
35+
uses: github/codeql-action/analyze@v4

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
cache: false
2121

2222
- name: Checkout code
23-
uses: actions/checkout@v5
23+
uses: actions/checkout@v6
2424

2525
- name: Get dependencies
2626
run: |

chart.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ func (opts *Chart) parseTitle() {
791791
// Marker
792792
// DataLabel
793793
// DataLabelPosition
794+
// DataPoint
794795
//
795796
// Name: Set the name for the series. The name is displayed in the chart legend
796797
// and in the formula bar. The 'Name' property is optional and if it isn't
@@ -840,6 +841,9 @@ func (opts *Chart) parseTitle() {
840841
//
841842
// DataLabelPosition: This sets the position of the chart series data label.
842843
//
844+
// DataPoint: This sets the format for individual data points in a doughnut, pie
845+
// or 3D pie chart series. The 'DataPoint' property is optional.
846+
//
843847
// Set properties of the chart legend. The options that can be set are:
844848
//
845849
// Position

chart_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,13 @@ func TestAddChart(t *testing.T) {
189189
{Name: "Sheet1!$A$37", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$37:$D$37", Line: ChartLine{Dash: ChartDashDash, Width: 0.25}},
190190
}
191191
series3 := []ChartSeries{{Name: "Sheet1!$A$30", Categories: "Sheet1!$A$30:$D$37", Values: "Sheet1!$B$30:$B$37"}}
192-
series4 := []ChartSeries{
192+
series4 := []ChartSeries{{Name: "Sheet1!$A$30", Categories: "Sheet1!$A$30:$D$37", Values: "Sheet1!$B$30:$B$37", DataPoint: []ChartDataPoint{
193+
{Index: 0, Fill: Fill{Type: "pattern", Color: []string{"003F5C"}, Pattern: 1}},
194+
{Index: 1, Fill: Fill{Type: "pattern", Color: []string{"58508D"}, Pattern: 1}},
195+
{Index: 2, Fill: Fill{Type: "pattern", Color: []string{"BC5090"}, Pattern: 1}},
196+
{Index: 3, Fill: Fill{Type: "pattern", Color: []string{"FF6361"}, Pattern: 1}},
197+
}}}
198+
series5 := []ChartSeries{
193199
{Name: "Sheet1!$A$30", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$30:$D$30", Sizes: "Sheet1!$B$30:$D$30", DataLabelPosition: ChartDataLabelsPositionAbove},
194200
{Name: "Sheet1!$A$31", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$31:$D$31", Sizes: "Sheet1!$B$31:$D$31", DataLabelPosition: ChartDataLabelsPositionLeft},
195201
{Name: "Sheet1!$A$32", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$32:$D$32", Sizes: "Sheet1!$B$32:$D$32", DataLabelPosition: ChartDataLabelsPositionBestFit},
@@ -248,7 +254,7 @@ func TestAddChart(t *testing.T) {
248254
{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}},
249255
{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}}},
250256
{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"}},
251-
{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"}},
257+
{sheetName: "Sheet2", cell: "X32", opts: &Chart{Type: Pie, Series: series4, 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"}},
252258
// bar series chart
253259
{sheetName: "Sheet2", cell: "P48", opts: &Chart{Type: Bar, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "2D Clustered Bar Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}},
254260
{sheetName: "Sheet2", cell: "X48", opts: &Chart{Type: BarStacked, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "2D Stacked Bar Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}},
@@ -280,8 +286,8 @@ func TestAddChart(t *testing.T) {
280286
{sheetName: "Sheet2", cell: "AV32", opts: &Chart{Type: Contour, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "Contour Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}},
281287
{sheetName: "Sheet2", cell: "BD1", opts: &Chart{Type: WireframeContour, Series: series, Format: format, Legend: legend, Title: []RichTextRun{{Text: "Wireframe Contour Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero"}},
282288
// bubble chart
283-
{sheetName: "Sheet2", cell: "BD16", opts: &Chart{Type: Bubble, Series: series4, Format: format, Legend: legend, Title: []RichTextRun{{Text: "Bubble Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero", BubbleSize: 75}},
284-
{sheetName: "Sheet2", cell: "BD32", opts: &Chart{Type: Bubble3D, Series: series4, Format: format, Legend: legend, Title: []RichTextRun{{Text: "Bubble 3D Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero", XAxis: ChartAxis{MajorGridLines: true}, YAxis: ChartAxis{MajorGridLines: true}}},
289+
{sheetName: "Sheet2", cell: "BD16", opts: &Chart{Type: Bubble, Series: series5, Format: format, Legend: legend, Title: []RichTextRun{{Text: "Bubble Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero", BubbleSize: 75}},
290+
{sheetName: "Sheet2", cell: "BD32", opts: &Chart{Type: Bubble3D, Series: series5, Format: format, Legend: legend, Title: []RichTextRun{{Text: "Bubble 3D Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero", XAxis: ChartAxis{MajorGridLines: true}, YAxis: ChartAxis{MajorGridLines: true}}},
285291
// pie of pie chart
286292
{sheetName: "Sheet2", cell: "BD48", opts: &Chart{Type: PieOfPie, Series: series3, Format: format, Legend: legend, Title: []RichTextRun{{Text: "Pie of Pie Chart"}}, PlotArea: plotArea, ShowBlanksAs: "zero", XAxis: ChartAxis{MajorGridLines: true}, YAxis: ChartAxis{MajorGridLines: true}}},
287293
// bar of pie chart

drawing.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,17 @@ func (f *File) drawChartSeriesDPt(i int, opts *Chart) []*cDPt {
895895
},
896896
},
897897
}}
898-
chartSeriesDPt := map[ChartType][]*cDPt{Pie: dpt, Pie3D: dpt}
898+
if len(opts.Series[i].DataPoint) > 0 {
899+
dpt = []*cDPt{}
900+
}
901+
for j := 0; j < len(opts.Series[i].DataPoint); j++ {
902+
spPr := &cSpPr{}
903+
dpt = append(dpt, &cDPt{
904+
IDx: &attrValInt{Val: intPtr(opts.Series[i].DataPoint[j].Index)},
905+
SpPr: f.drawShapeFill(opts.Series[i].DataPoint[j].Fill, spPr),
906+
})
907+
}
908+
chartSeriesDPt := map[ChartType][]*cDPt{Doughnut: dpt, Pie: dpt, Pie3D: dpt}
899909
return chartSeriesDPt[opts.Type]
900910
}
901911

xmlChart.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,13 @@ type ChartDataLabel struct {
703703
Fill Fill
704704
}
705705

706+
// ChartDataPoint directly maps the format settings of the chart data point for
707+
// doughnut, pie and 3D pie charts.
708+
type ChartDataPoint struct {
709+
Index int
710+
Fill Fill
711+
}
712+
706713
// ChartSeries directly maps the format settings of the chart series.
707714
type ChartSeries struct {
708715
Name string
@@ -715,4 +722,5 @@ type ChartSeries struct {
715722
Marker ChartMarker
716723
DataLabel ChartDataLabel
717724
DataLabelPosition ChartDataLabelPositionType
725+
DataPoint []ChartDataPoint
718726
}

0 commit comments

Comments
 (0)