• R/O
  • HTTP
  • SSH
  • HTTPS

excelize: 提交

Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets


Commit MetaInfo

修订版cb0c1b012b55be6feccb99e66b7d9cae2c45e72f (tree)
时间2023-02-19 01:18:11
作者xuri <xuri.me@gmai...>
Commiterxuri

Log Message

Support specifies the values in second plot for the bar/pie of pie chart

- Upgrade dependencies package golang.org/x/image to 0.5.0
- Update unit tests

更改概述

差异

--- a/chart.go
+++ b/chart.go
@@ -751,6 +751,7 @@ func parseChartOptions(opts *Chart) (*Chart, error) {
751751 // Set the position of the chart plot area by PlotArea. The properties that can
752752 // be set are:
753753 //
754+// SecondPlotValues
754755 // ShowBubbleSize
755756 // ShowCatName
756757 // ShowLeaderLines
@@ -758,6 +759,9 @@ func parseChartOptions(opts *Chart) (*Chart, error) {
758759 // ShowSerName
759760 // ShowVal
760761 //
762+// SecondPlotValues: Specifies the values in second plot for the 'pieOfPie' and
763+// 'barOfPie' chart.
764+//
761765 // ShowBubbleSize: Specifies the bubble size shall be shown in a data label. The
762766 // 'ShowBubbleSize' property is optional. The default value is false.
763767 //
--- a/chart_test.go
+++ b/chart_test.go
@@ -186,12 +186,13 @@ func TestAddChart(t *testing.T) {
186186 }
187187 legend := ChartLegend{Position: "left", ShowLegendKey: false}
188188 plotArea := ChartPlotArea{
189- ShowBubbleSize: true,
190- ShowCatName: true,
191- ShowLeaderLines: false,
192- ShowPercent: true,
193- ShowSerName: true,
194- ShowVal: true,
189+ SecondPlotValues: 3,
190+ ShowBubbleSize: true,
191+ ShowCatName: true,
192+ ShowLeaderLines: false,
193+ ShowPercent: true,
194+ ShowSerName: true,
195+ ShowVal: true,
195196 }
196197 for _, c := range []struct {
197198 sheetName, cell string
--- a/drawing.go
+++ b/drawing.go
@@ -602,6 +602,10 @@ func (f *File) drawPie3DChart(opts *Chart) *cPlotArea {
602602 // drawPieOfPieChart provides a function to draw the c:plotArea element for
603603 // pie chart by given format sets.
604604 func (f *File) drawPieOfPieChart(opts *Chart) *cPlotArea {
605+ var splitPos *attrValInt
606+ if opts.PlotArea.SecondPlotValues > 0 {
607+ splitPos = &attrValInt{Val: intPtr(opts.PlotArea.SecondPlotValues)}
608+ }
605609 return &cPlotArea{
606610 OfPieChart: &cCharts{
607611 OfPieType: &attrValString{
@@ -611,6 +615,7 @@ func (f *File) drawPieOfPieChart(opts *Chart) *cPlotArea {
611615 Val: opts.VaryColors,
612616 },
613617 Ser: f.drawChartSeries(opts),
618+ SplitPos: splitPos,
614619 SerLines: &attrValString{},
615620 },
616621 }
@@ -619,6 +624,10 @@ func (f *File) drawPieOfPieChart(opts *Chart) *cPlotArea {
619624 // drawBarOfPieChart provides a function to draw the c:plotArea element for
620625 // pie chart by given format sets.
621626 func (f *File) drawBarOfPieChart(opts *Chart) *cPlotArea {
627+ var splitPos *attrValInt
628+ if opts.PlotArea.SecondPlotValues > 0 {
629+ splitPos = &attrValInt{Val: intPtr(opts.PlotArea.SecondPlotValues)}
630+ }
622631 return &cPlotArea{
623632 OfPieChart: &cCharts{
624633 OfPieType: &attrValString{
@@ -627,6 +636,7 @@ func (f *File) drawBarOfPieChart(opts *Chart) *cPlotArea {
627636 VaryColors: &attrValBool{
628637 Val: opts.VaryColors,
629638 },
639+ SplitPos: splitPos,
630640 Ser: f.drawChartSeries(opts),
631641 SerLines: &attrValString{},
632642 },
--- a/go.mod
+++ b/go.mod
@@ -9,7 +9,7 @@ require (
99 github.com/xuri/efp v0.0.0-20220603152613-6918739fd470
1010 github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22
1111 golang.org/x/crypto v0.5.0
12- golang.org/x/image v0.0.0-20220902085622-e7cb96979f69
12+ golang.org/x/image v0.5.0
1313 golang.org/x/net v0.7.0
1414 golang.org/x/text v0.7.0
1515 )
--- a/go.sum
+++ b/go.sum
@@ -24,8 +24,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
2424 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
2525 golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
2626 golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
27-golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 h1:Lj6HJGCSn5AjxRAH2+r35Mir4icalbqku+CLUtjnvXY=
28-golang.org/x/image v0.0.0-20220902085622-e7cb96979f69/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY=
27+golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
28+golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
2929 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
3030 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
3131 golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
--- a/xmlChart.go
+++ b/xmlChart.go
@@ -333,6 +333,7 @@ type cCharts struct {
333333 VaryColors *attrValBool `xml:"varyColors"`
334334 Wireframe *attrValBool `xml:"wireframe"`
335335 Ser *[]cSer `xml:"ser"`
336+ SplitPos *attrValInt `xml:"splitPos"`
336337 SerLines *attrValString `xml:"serLines"`
337338 DLbls *cDLbls `xml:"dLbls"`
338339 Shape *attrValString `xml:"shape"`
@@ -540,12 +541,13 @@ type ChartDimension struct {
540541
541542 // ChartPlotArea directly maps the format settings of the plot area.
542543 type ChartPlotArea struct {
543- ShowBubbleSize bool
544- ShowCatName bool
545- ShowLeaderLines bool
546- ShowPercent bool
547- ShowSerName bool
548- ShowVal bool
544+ SecondPlotValues int
545+ ShowBubbleSize bool
546+ ShowCatName bool
547+ ShowLeaderLines bool
548+ ShowPercent bool
549+ ShowSerName bool
550+ ShowVal bool
549551 }
550552
551553 // Chart directly maps the format settings of the chart.
Show on old repository browser