| 1 |
package charts |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/go-echarts/go-echarts/v2/opts" |
| 5 |
) |
| 6 |
|
| 7 |
type Overlaper interface { |
| 8 |
asRectChart() *RectChart |
| 9 |
} |
| 10 |
|
| 11 |
|
| 12 |
type XYAxis struct { |
| 13 |
XAxisList []opts.XAxis `json:"xaxis"` |
| 14 |
YAxisList []opts.YAxis `json:"yaxis"` |
| 15 |
} |
| 16 |
|
| 17 |
func (xy *XYAxis) initXYAxis() { |
| 18 |
xy.XAxisList = append(xy.XAxisList, opts.XAxis{}) |
| 19 |
xy.YAxisList = append(xy.YAxisList, opts.YAxis{}) |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
func (xy *XYAxis) ExtendXAxis(xAxis ...opts.XAxis) { |
| 24 |
xy.XAxisList = append(xy.XAxisList, xAxis...) |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
func (xy *XYAxis) ExtendYAxis(yAxis ...opts.YAxis) { |
| 29 |
xy.YAxisList = append(xy.YAxisList, yAxis...) |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
func WithXAxisOpts(opt opts.XAxis, index ...int) GlobalOpts { |
| 34 |
return func(bc *BaseConfiguration) { |
| 35 |
if len(index) == 0 { |
| 36 |
index = []int{0} |
| 37 |
} |
| 38 |
for i := 0; i < len(index); i++ { |
| 39 |
bc.XYAxis.XAxisList[index[i]] = opt |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
func WithYAxisOpts(opt opts.YAxis, index ...int) GlobalOpts { |
| 46 |
return func(bc *BaseConfiguration) { |
| 47 |
if len(index) == 0 { |
| 48 |
index = []int{0} |
| 49 |
} |
| 50 |
for i := 0; i < len(index); i++ { |
| 51 |
bc.XYAxis.YAxisList[index[i]] = opt |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
type RectConfiguration struct { |
| 58 |
BaseConfiguration |
| 59 |
} |
| 60 |
|
| 61 |
func (rect *RectConfiguration) setRectGlobalOptions(options ...GlobalOpts) { |
| 62 |
rect.BaseConfiguration.setBaseGlobalOptions(options...) |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
type RectChart struct { |
| 67 |
RectConfiguration |
| 68 |
|
| 69 |
xAxisData interface{} |
| 70 |
} |
| 71 |
|
| 72 |
func (rc *RectChart) asRectChart() *RectChart { |
| 73 |
return rc |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
func (rc *RectChart) overlap() RectAggregator { |
| 78 |
return func(this *RectChart, that *RectChart) *RectChart { |
| 79 |
this.MultiSeries = append(this.MultiSeries, that.MultiSeries...) |
| 80 |
return this |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
func (rc *RectChart) SetGlobalOptions(options ...GlobalOpts) *RectChart { |
| 86 |
rc.RectConfiguration.setRectGlobalOptions(options...) |
| 87 |
return rc |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
func (rc *RectChart) Overlap(a ...Overlaper) { |
| 94 |
rc.Aggregate(rc.overlap(), a...) |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
type RectAggregator func(this *RectChart, that *RectChart) *RectChart |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
func (rc *RectChart) Aggregate(aggregator RectAggregator, charts ...Overlaper) { |
| 104 |
identity := rc |
| 105 |
for _, o := range charts { |
| 106 |
c := o.asRectChart() |
| 107 |
identity = aggregator(identity, c) |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
func (rc *RectChart) Validate() { |
| 113 |
|
| 114 |
rc.XAxisList[0].Data = rc.xAxisData |
| 115 |
|
| 116 |
for i := 0; i < len(rc.YAxisList); i++ { |
| 117 |
rc.YAxisList[i].AxisLabel.Show = opts.Bool(true) |
| 118 |
} |
| 119 |
rc.Assets.Validate(rc.AssetsHost) |
| 120 |
} |