From cb8bca0e92cbec30db10c2a2863ef81fd98a6138 Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 24 Aug 2022 00:00:47 +0800 Subject: [PATCH] This closes #1290 and closes #1328 - Add new smooth field in chart format parameter, support specify if smooth line chart - Fix decimal number format round issue with build-in number format --- cell_test.go | 8 ++++++++ drawing.go | 4 +--- styles.go | 2 +- xmlChart.go | 7 ++++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cell_test.go b/cell_test.go index fb1e8ef..2a09a9d 100644 --- a/cell_test.go +++ b/cell_test.go @@ -699,6 +699,14 @@ func TestFormattedValue2(t *testing.T) { }) v = f.formattedValue(1, "43528", false) assert.Equal(t, "43528", v) + + // formatted decimal value with build-in number format ID + styleID, err := f.NewStyle(&Style{ + NumFmt: 1, + }) + assert.NoError(t, err) + v = f.formattedValue(styleID, "310.56", false) + assert.Equal(t, "311", v) } func TestSharedStringsError(t *testing.T) { diff --git a/drawing.go b/drawing.go index 5015d26..59b6d2a 100644 --- a/drawing.go +++ b/drawing.go @@ -543,9 +543,6 @@ func (f *File) drawLineChart(formatSet *formatChart) *cPlotArea { }, Ser: f.drawChartSeries(formatSet), DLbls: f.drawChartDLbls(formatSet), - Smooth: &attrValBool{ - Val: boolPtr(false), - }, AxID: []*attrValInt{ {Val: intPtr(754001152)}, {Val: intPtr(753999904)}, @@ -757,6 +754,7 @@ func (f *File) drawChartSeries(formatSet *formatChart) *[]cSer { DLbls: f.drawChartSeriesDLbls(formatSet), InvertIfNegative: &attrValBool{Val: boolPtr(false)}, Cat: f.drawChartSeriesCat(formatSet.Series[k], formatSet), + Smooth: &attrValBool{Val: boolPtr(formatSet.Series[k].Line.Smooth)}, Val: f.drawChartSeriesVal(formatSet.Series[k], formatSet), XVal: f.drawChartSeriesXVal(formatSet.Series[k], formatSet), YVal: f.drawChartSeriesYVal(formatSet.Series[k], formatSet), diff --git a/styles.go b/styles.go index 8eb0587..2986f16 100644 --- a/styles.go +++ b/styles.go @@ -852,7 +852,7 @@ func formatToInt(v, format string, date1904 bool) string { if err != nil { return v } - return fmt.Sprintf("%d", int64(f)) + return fmt.Sprintf("%d", int64(math.Round(f))) } // formatToFloat provides a function to convert original string to float diff --git a/xmlChart.go b/xmlChart.go index b6ee3cd..dcd33e4 100644 --- a/xmlChart.go +++ b/xmlChart.go @@ -620,9 +620,10 @@ type formatChartSeries struct { Categories string `json:"categories"` Values string `json:"values"` Line struct { - None bool `json:"none"` - Color string `json:"color"` - Width float64 `json:"width"` + None bool `json:"none"` + Color string `json:"color"` + Smooth bool `json:"smooth"` + Width float64 `json:"width"` } `json:"line"` Marker struct { Symbol string `json:"symbol"` -- GitLab