From 8831afc5585c126ec4edbc21e0a2a67d7183eed7 Mon Sep 17 00:00:00 2001 From: xuri Date: Mon, 25 Dec 2023 21:51:09 +0800 Subject: [PATCH] This recover the Sizes field in the ChartSeries data type removed in commit dfaf418f340f260c5005e8343135cd6af60b8e58 - Update unit tests and documentation of the internal uintPtr function --- chart.go | 6 +++++- chart_test.go | 16 ++++++++-------- drawing.go | 6 +++++- lib.go | 4 ++-- xmlChart.go | 1 + 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/chart.go b/chart.go index d054841..3321697 100644 --- a/chart.go +++ b/chart.go @@ -707,7 +707,11 @@ func (opts *Chart) parseTitle() { // mandatory option for every chart object. This option links the chart with // the worksheet data that it displays. // -// Fill: This set the format for the data series fill. +// Sizes: This sets the bubble size in a data series. The 'Sizes' property is +// optional and the default value was same with 'Values'. +// +// Fill: This set the format for the data series fill. The 'Fill' property is +// optional // // Line: This sets the line format of the line chart. The 'Line' property is // optional and if it isn't supplied it will default style. The options that diff --git a/chart_test.go b/chart_test.go index 350852e..79501ee 100644 --- a/chart_test.go +++ b/chart_test.go @@ -176,14 +176,14 @@ func TestAddChart(t *testing.T) { } series3 := []ChartSeries{{Name: "Sheet1!$A$30", Categories: "Sheet1!$A$30:$D$37", Values: "Sheet1!$B$30:$B$37"}} series4 := []ChartSeries{ - {Name: "Sheet1!$A$30", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$30:$D$30", DataLabelPosition: ChartDataLabelsPositionAbove}, - {Name: "Sheet1!$A$31", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$31:$D$31", DataLabelPosition: ChartDataLabelsPositionLeft}, - {Name: "Sheet1!$A$32", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$32:$D$32", DataLabelPosition: ChartDataLabelsPositionBestFit}, - {Name: "Sheet1!$A$33", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$33:$D$33", DataLabelPosition: ChartDataLabelsPositionCenter}, - {Name: "Sheet1!$A$34", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$34:$D$34", DataLabelPosition: ChartDataLabelsPositionInsideBase}, - {Name: "Sheet1!$A$35", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$35:$D$35", DataLabelPosition: ChartDataLabelsPositionInsideEnd}, - {Name: "Sheet1!$A$36", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$36:$D$36", DataLabelPosition: ChartDataLabelsPositionOutsideEnd}, - {Name: "Sheet1!$A$37", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$37:$D$37", DataLabelPosition: ChartDataLabelsPositionRight}, + {Name: "Sheet1!$A$30", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$30:$D$30", Sizes: "Sheet1!$B$30:$D$30", DataLabelPosition: ChartDataLabelsPositionAbove}, + {Name: "Sheet1!$A$31", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$31:$D$31", Sizes: "Sheet1!$B$31:$D$31", DataLabelPosition: ChartDataLabelsPositionLeft}, + {Name: "Sheet1!$A$32", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$32:$D$32", Sizes: "Sheet1!$B$32:$D$32", DataLabelPosition: ChartDataLabelsPositionBestFit}, + {Name: "Sheet1!$A$33", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$33:$D$33", Sizes: "Sheet1!$B$33:$D$33", DataLabelPosition: ChartDataLabelsPositionCenter}, + {Name: "Sheet1!$A$34", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$34:$D$34", Sizes: "Sheet1!$B$34:$D$34", DataLabelPosition: ChartDataLabelsPositionInsideBase}, + {Name: "Sheet1!$A$35", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$35:$D$35", Sizes: "Sheet1!$B$35:$D$35", DataLabelPosition: ChartDataLabelsPositionInsideEnd}, + {Name: "Sheet1!$A$36", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$36:$D$36", Sizes: "Sheet1!$B$36:$D$36", DataLabelPosition: ChartDataLabelsPositionOutsideEnd}, + {Name: "Sheet1!$A$37", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$37:$D$37", Sizes: "Sheet1!$B$37:$D$37", DataLabelPosition: ChartDataLabelsPositionRight}, } format := GraphicOptions{ ScaleX: defaultDrawingScale, diff --git a/drawing.go b/drawing.go index 43e3312..6003235 100644 --- a/drawing.go +++ b/drawing.go @@ -891,9 +891,13 @@ func (f *File) drawCharSeriesBubbleSize(v ChartSeries, opts *Chart) *cVal { if _, ok := map[ChartType]bool{Bubble: true, Bubble3D: true}[opts.Type]; !ok { return nil } + fVal := v.Values + if v.Sizes != "" { + fVal = v.Sizes + } return &cVal{ NumRef: &cNumRef{ - F: v.Values, + F: fVal, }, } } diff --git a/lib.go b/lib.go index bc56422..db0d7d7 100644 --- a/lib.go +++ b/lib.go @@ -431,8 +431,8 @@ func boolPtr(b bool) *bool { return &b } // intPtr returns a pointer to an int with the given value. func intPtr(i int) *int { return &i } -// uintPtr returns a pointer to an int with the given value. -func uintPtr(i uint) *uint { return &i } +// uintPtr returns a pointer to an unsigned integer with the given value. +func uintPtr(u uint) *uint { return &u } // float64Ptr returns a pointer to a float64 with the given value. func float64Ptr(f float64) *float64 { return &f } diff --git a/xmlChart.go b/xmlChart.go index 5e20930..175fc86 100644 --- a/xmlChart.go +++ b/xmlChart.go @@ -607,6 +607,7 @@ type ChartSeries struct { Name string Categories string Values string + Sizes string Fill Fill Line ChartLine Marker ChartMarker -- GitLab