From cb0c1b012b55be6feccb99e66b7d9cae2c45e72f Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 19 Feb 2023 00:18:11 +0800 Subject: [PATCH] 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 --- chart.go | 4 ++++ chart_test.go | 13 +++++++------ drawing.go | 10 ++++++++++ go.mod | 2 +- go.sum | 4 ++-- xmlChart.go | 14 ++++++++------ 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/chart.go b/chart.go index a58eac4..a9b3aaa 100644 --- a/chart.go +++ b/chart.go @@ -751,6 +751,7 @@ func parseChartOptions(opts *Chart) (*Chart, error) { // Set the position of the chart plot area by PlotArea. The properties that can // be set are: // +// SecondPlotValues // ShowBubbleSize // ShowCatName // ShowLeaderLines @@ -758,6 +759,9 @@ func parseChartOptions(opts *Chart) (*Chart, error) { // ShowSerName // ShowVal // +// SecondPlotValues: Specifies the values in second plot for the 'pieOfPie' and +// 'barOfPie' chart. +// // ShowBubbleSize: Specifies the bubble size shall be shown in a data label. The // 'ShowBubbleSize' property is optional. The default value is false. // diff --git a/chart_test.go b/chart_test.go index cc78944..9a8660c 100644 --- a/chart_test.go +++ b/chart_test.go @@ -186,12 +186,13 @@ func TestAddChart(t *testing.T) { } legend := ChartLegend{Position: "left", ShowLegendKey: false} plotArea := ChartPlotArea{ - ShowBubbleSize: true, - ShowCatName: true, - ShowLeaderLines: false, - ShowPercent: true, - ShowSerName: true, - ShowVal: true, + SecondPlotValues: 3, + ShowBubbleSize: true, + ShowCatName: true, + ShowLeaderLines: false, + ShowPercent: true, + ShowSerName: true, + ShowVal: true, } for _, c := range []struct { sheetName, cell string diff --git a/drawing.go b/drawing.go index 7ce4b9e..93684a3 100644 --- a/drawing.go +++ b/drawing.go @@ -602,6 +602,10 @@ func (f *File) drawPie3DChart(opts *Chart) *cPlotArea { // drawPieOfPieChart provides a function to draw the c:plotArea element for // pie chart by given format sets. func (f *File) drawPieOfPieChart(opts *Chart) *cPlotArea { + var splitPos *attrValInt + if opts.PlotArea.SecondPlotValues > 0 { + splitPos = &attrValInt{Val: intPtr(opts.PlotArea.SecondPlotValues)} + } return &cPlotArea{ OfPieChart: &cCharts{ OfPieType: &attrValString{ @@ -611,6 +615,7 @@ func (f *File) drawPieOfPieChart(opts *Chart) *cPlotArea { Val: opts.VaryColors, }, Ser: f.drawChartSeries(opts), + SplitPos: splitPos, SerLines: &attrValString{}, }, } @@ -619,6 +624,10 @@ func (f *File) drawPieOfPieChart(opts *Chart) *cPlotArea { // drawBarOfPieChart provides a function to draw the c:plotArea element for // pie chart by given format sets. func (f *File) drawBarOfPieChart(opts *Chart) *cPlotArea { + var splitPos *attrValInt + if opts.PlotArea.SecondPlotValues > 0 { + splitPos = &attrValInt{Val: intPtr(opts.PlotArea.SecondPlotValues)} + } return &cPlotArea{ OfPieChart: &cCharts{ OfPieType: &attrValString{ @@ -627,6 +636,7 @@ func (f *File) drawBarOfPieChart(opts *Chart) *cPlotArea { VaryColors: &attrValBool{ Val: opts.VaryColors, }, + SplitPos: splitPos, Ser: f.drawChartSeries(opts), SerLines: &attrValString{}, }, diff --git a/go.mod b/go.mod index d5b408b..a4a0a74 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 golang.org/x/crypto v0.5.0 - golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 + golang.org/x/image v0.5.0 golang.org/x/net v0.7.0 golang.org/x/text v0.7.0 ) diff --git a/go.sum b/go.sum index 7f0afed..7e2b95a 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= -golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 h1:Lj6HJGCSn5AjxRAH2+r35Mir4icalbqku+CLUtjnvXY= -golang.org/x/image v0.0.0-20220902085622-e7cb96979f69/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY= +golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI= +golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= diff --git a/xmlChart.go b/xmlChart.go index 6688ed1..6c17ab8 100644 --- a/xmlChart.go +++ b/xmlChart.go @@ -333,6 +333,7 @@ type cCharts struct { VaryColors *attrValBool `xml:"varyColors"` Wireframe *attrValBool `xml:"wireframe"` Ser *[]cSer `xml:"ser"` + SplitPos *attrValInt `xml:"splitPos"` SerLines *attrValString `xml:"serLines"` DLbls *cDLbls `xml:"dLbls"` Shape *attrValString `xml:"shape"` @@ -540,12 +541,13 @@ type ChartDimension struct { // ChartPlotArea directly maps the format settings of the plot area. type ChartPlotArea struct { - ShowBubbleSize bool - ShowCatName bool - ShowLeaderLines bool - ShowPercent bool - ShowSerName bool - ShowVal bool + SecondPlotValues int + ShowBubbleSize bool + ShowCatName bool + ShowLeaderLines bool + ShowPercent bool + ShowSerName bool + ShowVal bool } // Chart directly maps the format settings of the chart.