Skip to content

Commit

Permalink
Support specifies the values in second plot for the bar/pie of pie chart
Browse files Browse the repository at this point in the history
- Upgrade dependencies package golang.org/x/image to 0.5.0
- Update unit tests
  • Loading branch information
xuri committed Feb 18, 2023
1 parent 21ec143 commit cb0c1b0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
4 changes: 4 additions & 0 deletions chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,13 +751,17 @@ 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
// ShowPercent
// 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.
//
Expand Down
13 changes: 7 additions & 6 deletions chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions drawing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -611,6 +615,7 @@ func (f *File) drawPieOfPieChart(opts *Chart) *cPlotArea {
Val: opts.VaryColors,
},
Ser: f.drawChartSeries(opts),
SplitPos: splitPos,
SerLines: &attrValString{},
},
}
Expand All @@ -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{
Expand All @@ -627,6 +636,7 @@ func (f *File) drawBarOfPieChart(opts *Chart) *cPlotArea {
VaryColors: &attrValBool{
Val: opts.VaryColors,
},
SplitPos: splitPos,
Ser: f.drawChartSeries(opts),
SerLines: &attrValString{},
},
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
14 changes: 8 additions & 6 deletions xmlChart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit cb0c1b0

Please sign in to comment.