Debian Codegraph @

charts/bar.go

raw symbols SCIP
1 package charts
2
3 import (
4 "github.com/go-echarts/go-echarts/v2/opts"
5 "github.com/go-echarts/go-echarts/v2/render"
6 "github.com/go-echarts/go-echarts/v2/types"
7 )
8
9 // Bar represents a bar chart.
10 type Bar struct {
11 RectChart
12
13 isXYReversal bool
14 }
15
16 // Type returns the chart type.
17 func (*Bar) Type() string { return types.ChartBar }
18
19 // NewBar creates a new bar chart instance.
20 func NewBar() *Bar {
21 c := &Bar{}
22 c.initBaseConfiguration()
23 c.Renderer = render.NewChartRender(c, c.Validate)
24 c.hasXYAxis = true
25 return c
26 }
27
28 // EnablePolarType enables the polar bar.
29 func (c *Bar) EnablePolarType() *Bar {
30 c.hasXYAxis = false
31 c.hasPolar = true
32 return c
33 }
34
35 // SetXAxis sets the X axis.
36 func (c *Bar) SetXAxis(x interface{}) *Bar {
37 c.xAxisData = x
38 return c
39 }
40
41 // AddSeries adds the new series.
42 func (c *Bar) AddSeries(name string, data []opts.BarData, options ...SeriesOpts) *Bar {
43 series := SingleSeries{Name: name, Type: types.ChartBar, Data: data}
44 series.ConfigureSeriesOpts(options...)
45 c.MultiSeries = append(c.MultiSeries, series)
46 return c
47 }
48
49 // XYReversal checks if X axis and Y axis are reversed.
50 func (c *Bar) XYReversal() *Bar {
51 c.isXYReversal = true
52 return c
53 }
54
55 // Validate validates the given configuration.
56 func (c *Bar) Validate() {
57 c.XAxisList[0].Data = c.xAxisData
58 if c.isXYReversal {
59 c.YAxisList[0].Data = c.xAxisData
60 c.XAxisList[0].Data = nil
61 }
62 c.Assets.Validate(c.AssetsHost)
63 }