Debian Codegraph @

opts/global.go

raw symbols SCIP
1 package opts
2
3 import (
4 "strings"
5
6 "github.com/go-echarts/go-echarts/v2/types"
7 "github.com/go-echarts/go-echarts/v2/util"
8 )
9
10 const (
11 EchartsJS = "echarts.min.js"
12 // CompatibleEchartsJS The 3d charts and 3rd charts not support in v5+ echarts version, back to v4 (v4.9.0)
13 CompatibleEchartsJS = "[email protected]"
14 )
15
16 type PageConfiguration struct {
17 // HTML title
18 PageTitle string `default:"Awesome go-echarts"`
19
20 // Assets host
21 AssetsHost string `default:"https://go-echarts.github.io/go-echarts-assets/assets/"`
22 }
23
24 // Initialization contains options for the canvas.
25 type Initialization struct {
26 // Width of canvas
27 Width string `default:"900px"`
28
29 // Height of canvas
30 Height string `default:"500px"`
31
32 // BackgroundColor of canvas
33 BackgroundColor string
34
35 // Chart unique ID
36 ChartID string
37
38 // Theme of chart, preset themes in types.Theme<...>
39 Theme string `default:"white"`
40
41 // Renderer
42 Renderer string `default:"canvas"`
43
44 // Page configurations duplicate, a shortcut for single chart build with page settings
45 PageTitle string `default:"Awesome go-echarts"`
46
47 // Assets host
48 AssetsHost string `default:"https://go-echarts.github.io/go-echarts-assets/assets/"`
49 }
50
51 // Validate validates the initialization configurations.
52 func (opt *Initialization) Validate() {
53 util.SetDefaultValue(opt)
54 if opt.ChartID == "" {
55 opt.ChartID = util.GenerateUniqueID()
56 }
57 }
58
59 type Colors []string
60
61 // Assets contains options for static assets.
62 type Assets struct {
63 JSAssets types.OrderedSet
64 CSSAssets types.OrderedSet
65
66 CustomizedJSAssets types.OrderedSet
67 CustomizedCSSAssets types.OrderedSet
68 CustomizedHeaders types.OrderedSet
69 }
70
71 // InitAssets inits the static assets' storage.
72 func (opt *Assets) InitAssets() {
73 opt.JSAssets.Init(EchartsJS)
74 opt.CSSAssets.Init()
75
76 opt.CustomizedJSAssets.Init()
77 opt.CustomizedCSSAssets.Init()
78 opt.CustomizedHeaders.Init()
79 }
80
81 // ClearPresetAssets clear both the preset JS and CSS static assets.
82 func (opt *Assets) ClearPresetAssets() {
83 opt.ClearPresetJSAssets()
84 opt.ClearPresetCSSAssets()
85 }
86
87 // ClearPresetJSAssets only clear all the preset JS static assets.
88 func (opt *Assets) ClearPresetJSAssets() {
89 opt.JSAssets.Clear()
90 }
91
92 // ClearPresetCSSAssets only clear all the preset CSS static assets.
93 func (opt *Assets) ClearPresetCSSAssets() {
94 opt.CSSAssets.Clear()
95 }
96
97 // AddCustomizedJSAssets adds the customized javascript assets which will not be added the `host` prefix.
98 func (opt *Assets) AddCustomizedJSAssets(assets ...string) {
99 for i := 0; i < len(assets); i++ {
100 opt.CustomizedJSAssets.Add(assets[i])
101 }
102 }
103
104 // AddCustomizedCSSAssets adds the customized css assets which will not be added the `host` prefix.
105 func (opt *Assets) AddCustomizedCSSAssets(assets ...string) {
106 for i := 0; i < len(assets); i++ {
107 opt.CustomizedCSSAssets.Add(assets[i])
108 }
109 }
110
111 // AddCustomizedHeaders adds the customized headers, should be valid with header tag, e.g.
112 // <script src="assets/go-echarts/example.js"></script>
113 func (opt *Assets) AddCustomizedHeaders(headers ...string) {
114 for i := 0; i < len(headers); i++ {
115 opt.CustomizedHeaders.Add(headers[i])
116 }
117 }
118
119 // Validate validates the static assets configurations
120 func (opt *Assets) Validate(host string) {
121 for i := 0; i < len(opt.JSAssets.Values); i++ {
122 if !strings.HasPrefix(opt.JSAssets.Values[i], host) {
123 opt.JSAssets.Values[i] = host + opt.JSAssets.Values[i]
124 }
125 }
126
127 for i := 0; i < len(opt.CSSAssets.Values); i++ {
128 if !strings.HasPrefix(opt.CSSAssets.Values[i], host) {
129 opt.CSSAssets.Values[i] = host + opt.CSSAssets.Values[i]
130 }
131 }
132 }
133
134 // SplitArea is the option set for a split area.
135 type SplitArea struct {
136 // Set this to true to show the splitArea.
137 Show types.Bool `json:"show,omitempty"`
138
139 // Split area style.
140 AreaStyle *AreaStyle `json:"areaStyle,omitempty"`
141 }
142
143 // SplitLine is the option set for a split line.
144 type SplitLine struct {
145 // Set this to true to show the splitLine.
146 Show types.Bool `json:"show,omitempty"`
147
148 // Split line style.
149 LineStyle *LineStyle `json:"lineStyle,omitempty"`
150
151 // Align split line with label, which is available only when boundaryGap is set to be true in category axis.
152 AlignWithLabel types.Bool `json:"alignWithLabel,omitempty"`
153 }