summaryrefslogtreecommitdiff
path: root/chart.go
diff options
context:
space:
mode:
authorEugene Dzhurinsky <jdevelop@gmail.com>2018-05-05 21:03:03 -0400
committerEugene Dzhurinsky <jdevelop@gmail.com>2018-05-08 20:21:26 -0400
commite09e47d9883c6d5928e59b8de1a49499d51cb4c8 (patch)
treec38f40666e0fbf8361c08ca14c46c8486dce0b54 /chart.go
parente8961f0affd1ce9656a57b24cad4cfd080781556 (diff)
Custom chart size.
Added helper functions to set the chart size. Added the unit test Signed-off-by: Eugene Dzhurinsky <jdevelop@gmail.com>
Diffstat (limited to 'chart.go')
-rw-r--r--chart.go38
1 files changed, 36 insertions, 2 deletions
diff --git a/chart.go b/chart.go
index c71dd9f..b589726 100644
--- a/chart.go
+++ b/chart.go
@@ -351,7 +351,13 @@ func parseFormatChartSet(formatSet string) *formatChart {
// maximum: Specifies that the fixed maximum, 0 is auto. The maximum property is optional. The default value is auto.
// minimum: Specifies that the fixed minimum, 0 is auto. The minimum property is optional. The default value is auto.
//
-func (f *File) AddChart(sheet, cell, format string) {
+func (f *File) AddChart(sheet, cell, format string, opts ...chartOpts) {
+
+ var defOpts = defaultChartOptions
+ for _, optF := range opts {
+ optF(&defOpts)
+ }
+
formatSet := parseFormatChartSet(format)
// Read sheet data.
xlsx := f.workSheetReader(sheet)
@@ -361,12 +367,40 @@ func (f *File) AddChart(sheet, cell, format string) {
drawingXML := "xl/drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
drawingID, drawingXML = f.prepareDrawing(xlsx, drawingID, sheet, drawingXML)
drawingRID := f.addDrawingRelationships(drawingID, SourceRelationshipChart, "../charts/chart"+strconv.Itoa(chartID)+".xml", "")
- f.addDrawingChart(sheet, drawingXML, cell, 480, 290, drawingRID, &formatSet.Format)
+ f.addDrawingChart(sheet, drawingXML, cell, defOpts.width, defOpts.height, drawingRID, &formatSet.Format)
f.addChart(formatSet)
f.addContentTypePart(chartID, "chart")
f.addContentTypePart(drawingID, "drawings")
}
+type chartOptions struct {
+ width int
+ height int
+}
+
+var defaultChartOptions = chartOptions{
+ width: 480,
+ height: 290,
+}
+
+type chartOpts func(opts *chartOptions)
+
+// ChartWidth sets the chart width.
+func ChartWidth(width int) chartOpts {
+ return func(opts *chartOptions) {
+ opts.width = width
+ return
+ }
+}
+
+// ChartHeight sets the chart height.
+func ChartHeight(height int) chartOpts {
+ return func(opts *chartOptions) {
+ opts.height = height
+ return
+ }
+}
+
// countCharts provides function to get chart files count storage in the
// folder xl/charts.
func (f *File) countCharts() int {