Skip to content

Commit

Permalink
This closes #1368, fixes number parsing issue, adds support for creat…
Browse files Browse the repository at this point in the history
…e a 3D line chart
  • Loading branch information
xuri committed Oct 11, 2022
1 parent c02346b commit 0e657c8
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 17 deletions.
27 changes: 12 additions & 15 deletions cell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,51 +683,48 @@ func TestSetCellRichText(t *testing.T) {

func TestFormattedValue2(t *testing.T) {
f := NewFile()
v := f.formattedValue(0, "43528", false)
assert.Equal(t, "43528", v)
assert.Equal(t, "43528", f.formattedValue(0, "43528", false))

v = f.formattedValue(15, "43528", false)
assert.Equal(t, "43528", v)
assert.Equal(t, "43528", f.formattedValue(15, "43528", false))

v = f.formattedValue(1, "43528", false)
assert.Equal(t, "43528", v)
assert.Equal(t, "43528", f.formattedValue(1, "43528", false))
customNumFmt := "[$-409]MM/DD/YYYY"
_, err := f.NewStyle(&Style{
CustomNumFmt: &customNumFmt,
})
assert.NoError(t, err)
v = f.formattedValue(1, "43528", false)
assert.Equal(t, "03/04/2019", v)
assert.Equal(t, "03/04/2019", f.formattedValue(1, "43528", false))

// formatted value with no built-in number format ID
numFmtID := 5
f.Styles.CellXfs.Xf = append(f.Styles.CellXfs.Xf, xlsxXf{
NumFmtID: &numFmtID,
})
v = f.formattedValue(2, "43528", false)
assert.Equal(t, "43528", v)
assert.Equal(t, "43528", f.formattedValue(2, "43528", false))

// formatted value with invalid number format ID
f.Styles.CellXfs.Xf = append(f.Styles.CellXfs.Xf, xlsxXf{
NumFmtID: nil,
})
_ = f.formattedValue(3, "43528", false)
assert.Equal(t, "43528", f.formattedValue(3, "43528", false))

// formatted value with empty number format
f.Styles.NumFmts = nil
f.Styles.CellXfs.Xf = append(f.Styles.CellXfs.Xf, xlsxXf{
NumFmtID: &numFmtID,
})
v = f.formattedValue(1, "43528", false)
assert.Equal(t, "43528", v)
assert.Equal(t, "43528", f.formattedValue(1, "43528", false))

// 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)
assert.Equal(t, "311", f.formattedValue(styleID, "310.56", false))

for _, fn := range builtInNumFmtFunc {
assert.Equal(t, "0_0", fn("0_0", "", false))
}
}

func TestSharedStringsError(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const (
Col3DCylinderPercentStacked = "col3DCylinderPercentStacked"
Doughnut = "doughnut"
Line = "line"
Line3D = "line3D"
Pie = "pie"
Pie3D = "pie3D"
PieOfPieChart = "pieOfPie"
Expand Down Expand Up @@ -122,6 +123,7 @@ var (
Col3DCylinderPercentStacked: 15,
Doughnut: 0,
Line: 0,
Line3D: 20,
Pie: 0,
Pie3D: 30,
PieOfPieChart: 0,
Expand Down Expand Up @@ -176,6 +178,7 @@ var (
Col3DCylinderPercentStacked: 20,
Doughnut: 0,
Line: 0,
Line3D: 15,
Pie: 0,
Pie3D: 0,
PieOfPieChart: 0,
Expand All @@ -194,6 +197,7 @@ var (
ColPercentStacked: 100,
}
chartView3DPerspective = map[string]int{
Line3D: 30,
Contour: 0,
WireframeContour: 0,
}
Expand Down Expand Up @@ -240,6 +244,7 @@ var (
Col3DCylinderPercentStacked: 1,
Doughnut: 0,
Line: 0,
Line3D: 0,
Pie: 0,
Pie3D: 0,
PieOfPieChart: 0,
Expand Down Expand Up @@ -302,6 +307,7 @@ var (
Col3DCylinderPercentStacked: "0%",
Doughnut: "General",
Line: "General",
Line3D: "General",
Pie: "General",
Pie3D: "General",
PieOfPieChart: "General",
Expand Down Expand Up @@ -358,6 +364,7 @@ var (
Col3DCylinderPercentStacked: "between",
Doughnut: "between",
Line: "between",
Line3D: "between",
Pie: "between",
Pie3D: "between",
PieOfPieChart: "between",
Expand Down Expand Up @@ -413,6 +420,7 @@ var (
Col3DCylinderStacked: "stacked",
Col3DCylinderPercentStacked: "percentStacked",
Line: "standard",
Line3D: "standard",
}
plotAreaChartBarDir = map[string]string{
Bar: "bar",
Expand Down Expand Up @@ -450,6 +458,7 @@ var (
Col3DCylinderStacked: "col",
Col3DCylinderPercentStacked: "col",
Line: "standard",
Line3D: "standard",
}
orientation = map[bool]string{
true: "maxMin",
Expand Down Expand Up @@ -624,6 +633,7 @@ func parseChartOptions(opts string) (*chartOptions, error) {
// col3DCylinderPercentStacked | 3D cylinder percent stacked column chart
// doughnut | doughnut chart
// line | line chart
// line3D | 3D line chart
// pie | pie chart
// pie3D | 3D pie chart
// pieOfPie | pie of pie chart
Expand Down
Loading

0 comments on commit 0e657c8

Please sign in to comment.