ChartTypes and the names chart types are saved with were two lists kept in step by hand; the list is now the name table, keyed by the type constants, and ChartTypes is built from it.
- commit
- 77e797dc42ed3d0ffa7af10d691860dcf702843b
- parent
- 487c1640c10c0c5064bef31056da9dc265c9a110
- author
- Dami <dami.etoile@gmail.com>
| M | internal/ | 18 | ++++++++++++++---- |
@@ -13,7 +13,9 @@ import (
1313 // follow inserted and deleted rows and columns, and every change to them1414 // is an undo step.1515 16-// ChartType is how a chart draws its series.16+// ChartType is how a chart draws its series. Adding one takes a constant17+// here and its name in chartTypeNames; the chart editor, the file format18+// and ChartTypes follow from the table, and internal/chart draws it.1719 type ChartType int1820 1921 const (@@ -23,10 +25,18 @@ const (
2325 ChartPie // the first series as slices of a whole2426 )2527 26-// ChartTypes lists the types in the order the chart editor offers them.27-var ChartTypes = []ChartType{ChartColumn, ChartBar, ChartLine, ChartPie}28+// chartTypeNames names every type, as files store it, in the order the29+// chart editor offers them.30+var chartTypeNames = [...]string{ChartColumn: "column", ChartBar: "bar", ChartLine: "line", ChartPie: "pie"}2831 29-var chartTypeNames = [...]string{"column", "bar", "line", "pie"}32+// ChartTypes lists the types in the order the chart editor offers them.33+var ChartTypes = func() []ChartType {34+ out := make([]ChartType, len(chartTypeNames))35+ for i := range out {36+ out[i] = ChartType(i)37+ }38+ return out39+}()3040 3141 func (t ChartType) String() string {3242 if t < 0 || int(t) >= len(chartTypeNames) {