/
global.go
1244 lines (1029 loc) · 48.4 KB
/
global.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package opts
import (
"fmt"
"math/rand"
"reflect"
"regexp"
"strconv"
"strings"
"time"
"github.com/go-echarts/go-echarts/v2/types"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
// Initialization contains options for the canvas.
type Initialization struct {
// HTML title
PageTitle string `default:"Awesome go-echarts"`
// Width of canvas
Width string `default:"900px"`
// Height of canvas
Height string `default:"500px"`
// BackgroundColor of canvas
BackgroundColor string
// Chart unique ID
ChartID string
// Assets host
AssetsHost string `default:"https://go-echarts.github.io/go-echarts-assets/assets/"`
// Theme of chart
Theme string `default:"white"`
}
// Validate validates the initialization configurations.
func (opt *Initialization) Validate() {
setDefaultValue(opt)
if opt.ChartID == "" {
opt.ChartID = generateUniqueID()
}
}
// set default values for the struct field.
// origin from: https://github.com/mcuadros/go-defaults
func setDefaultValue(ptr interface{}) {
elem := reflect.ValueOf(ptr).Elem()
t := elem.Type()
for i := 0; i < t.NumField(); i++ {
// handle `default` tag only
if defaultVal := t.Field(i).Tag.Get("default"); defaultVal != "" {
setField(elem.Field(i), defaultVal)
}
}
}
// setField handles String/Bool types only.
func setField(field reflect.Value, defaultVal string) {
switch field.Kind() {
case reflect.String:
if field.String() == "" {
field.Set(reflect.ValueOf(defaultVal).Convert(field.Type()))
}
case reflect.Bool:
if val, err := strconv.ParseBool(defaultVal); err == nil {
field.Set(reflect.ValueOf(val).Convert(field.Type()))
}
}
}
const (
chartIDSize = 12
)
// generate the unique ID for each chart.
func generateUniqueID() string {
var b [chartIDSize]byte
for i := range b {
b[i] = randByte()
}
return string(b[:])
}
func randByte() byte {
c := 65 // A
if rand.Intn(10) > 5 {
c = 97 // a
}
return byte(c + rand.Intn(26))
}
// Title is the option set for a title component.
// https://echarts.apache.org/en/option.html#title
type Title struct {
// The main title text, supporting \n for newlines.
Title string `json:"text,omitempty"`
// TextStyle of the main title.
TitleStyle *TextStyle `json:"textStyle,omitempty"`
// The hyper link of main title text.
Link string `json:"link,omitempty"`
// Subtitle text, supporting \n for newlines.
Subtitle string `json:"subtext,omitempty"`
// TextStyle of the sub title.
SubtitleStyle *TextStyle `json:"subtextStyle,omitempty"`
// The hyper link of sub title text.
SubLink string `json:"sublink,omitempty"`
// Open the hyper link of main title in specified tab.
// options:
// 'self' opening it in current tab
// 'blank' opening it in a new tab
Target string `json:"target,omitempty"`
// Distance between title component and the top side of the container.
// top value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'; and it can also be 'top', 'middle', or 'bottom'.
// If the left value is set to be 'top', 'middle', or 'bottom',
// then the component will be aligned automatically based on position.
Top string `json:"top,omitempty"`
// Distance between title component and the bottom side of the container.
// bottom value can be instant pixel value like 20;
// it can also be a percentage value relative to container width like '20%'.
// Adaptive by default.
Bottom string `json:"bottom,omitempty"`
// Distance between title component and the left side of the container.
// left value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'; and it can also be 'left', 'center', or 'right'.
// If the left value is set to be 'left', 'center', or 'right',
// then the component will be aligned automatically based on position.
Left string `json:"left,omitempty"`
// Distance between title component and the right side of the container.
// right value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'.
//Adaptive by default.
Right string `json:"right,omitempty"`
}
// Legend is the option set for a legend component.
// Legend component shows symbol, color and name of different series. You can click legends to toggle displaying series in the chart.
// https://echarts.apache.org/en/option.html#legend
type Legend struct {
// Whether to show the Legend, default true.
Show bool `json:"show"`
// Distance between legend component and the left side of the container.
// left value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'; and it can also be 'left', 'center', or 'right'.
// If the left value is set to be 'left', 'center', or 'right', then the component
// will be aligned automatically based on position.
Left string `json:"left,omitempty"`
// Distance between legend component and the top side of the container.
// top value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'; and it can also be 'top', 'middle', or 'bottom'.
// If the left value is set to be 'top', 'middle', or 'bottom', then the component
// will be aligned automatically based on position.
Top string `json:"top,omitempty"`
// Distance between legend component and the right side of the container.
// right value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'.
// Adaptive by default.
Right string `json:"right,omitempty"`
// Distance between legend component and the bottom side of the container.
// bottom value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'.
// Adaptive by default.
Bottom string `json:"bottom,omitempty"`
// Data array of legend. An array item is usually a name representing string.
// set Data as []string{} if you wants to hide the legend.
Data interface{} `json:"data,omitempty"`
// The layout orientation of legend.
// Options: 'horizontal', 'vertical'
Orient string `json:"orient,omitempty"`
// Legend color when not selected.
InactiveColor string `json:"inactiveColor,omitempty"`
// State table of selected legend.
// example:
// var selected = map[string]bool{}
// selected["series1"] = true
// selected["series2"] = false
Selected map[string]bool `json:"selected,omitempty"`
// Selected mode of legend, which controls whether series can be toggled displaying by clicking legends.
// It is enabled by default, and you may set it to be false to disabled it.
// Besides, it can be set to 'single' or 'multiple', for single selection and multiple selection.
SelectedMode string `json:"selectedMode,omitempty"`
// Legend space around content. The unit is px.
// Default values for each position are 5.
// And they can be set to different values with left, right, top, and bottom.
// Examples:
// 1. Set padding to be 5
// padding: 5
// 2. Set the top and bottom paddings to be 5, and left and right paddings to be 10
// padding: [5, 10]
// 3. Set each of the four paddings seperately
// padding: [
// 5, // up
// 10, // right
// 5, // down
// 10, // left
// ]
Padding interface{} `json:"padding,omitempty"`
// Image width of legend symbol.
ItemWidth int `json:"itemWidth,omitempty"`
// Image height of legend symbol.
ItemHeight int `json:"itemHeight,omitempty"`
// Legend X position, right/left/center
X string `json:"x,omitempty"`
// Legend Y position, right/left/center
Y string `json:"y,omitempty"`
// Width of legend component. Adaptive by default.
Width string `json:"width,omitempty"`
// Height of legend component. Adaptive by default.
Height string `json:"height,omitempty"`
// Legend marker and text aligning.
// By default, it automatically calculates from component location and orientation.
// When left value of this component is 'right' and orient is 'vertical', it would be aligned to 'right'.
// Options: auto/left/right
Align string `json:"align,omitempty"`
// Legend text style.
TextStyle *TextStyle `json:"textStyle,omitempty"`
}
// Tooltip is the option set for a tooltip component.
// https://echarts.apache.org/en/option.html#tooltip
type Tooltip struct {
// Whether to show the tooltip component, including tooltip floating layer and axisPointer.
Show bool `json:"show"`
// Type of triggering.
// Options:
// * 'item': Triggered by data item, which is mainly used for charts that
// don't have a category axis like scatter charts or pie charts.
// * 'axis': Triggered by axes, which is mainly used for charts that have category axes,
// like bar charts or line charts.
// * 'none': Trigger nothing.
Trigger string `json:"trigger,omitempty"`
// Conditions to trigger tooltip. Options:
// * 'mousemove': Trigger when mouse moves.
// * 'click': Trigger when mouse clicks.
// * 'mousemove|click': Trigger when mouse clicks and moves.
// * 'none': Do not triggered by 'mousemove' and 'click'. Tooltip can be triggered and hidden
// manually by calling action.tooltip.showTip and action.tooltip.hideTip.
// It can also be triggered by axisPointer.handle in this case.
TriggerOn string `json:"triggerOn,omitempty"`
// The content formatter of tooltip's floating layer which supports string template and callback function.
//
// 1. String template
// The template variables are {a}, {b}, {c}, {d} and {e}, which stands for series name,
// data name and data value and ect. When trigger is set to be 'axis', there may be data from multiple series.
// In this time, series index can be refereed as {a0}, {a1}, or {a2}.
// {a}, {b}, {c}, {d} have different meanings for different series types:
//
// * Line (area) charts, bar (column) charts, K charts: {a} for series name,
// {b} for category name, {c} for data value, {d} for none;
// * Scatter (bubble) charts: {a} for series name, {b} for data name, {c} for data value, {d} for none;
// * Map: {a} for series name, {b} for area name, {c} for merging data, {d} for none;
// * Pie charts, gauge charts, funnel charts: {a} for series name, {b} for data item name,
// {c} for data value, {d} for percentage.
//
// 2. Callback function
// The format of callback function:
// (params: Object|Array, ticket: string, callback: (ticket: string, html: string)) => string
// The first parameter params is the data that the formatter needs. Its format is shown as follows:
// {
// componentType: 'series',
// // Series type
// seriesType: string,
// // Series index in option.series
// seriesIndex: number,
// // Series name
// seriesName: string,
// // Data name, or category name
// name: string,
// // Data index in input data array
// dataIndex: number,
// // Original data as input
// data: Object,
// // Value of data. In most series it is the same as data.
// // But in some series it is some part of the data (e.g., in map, radar)
// value: number|Array|Object,
// // encoding info of coordinate system
// // Key: coord, like ('x' 'y' 'radius' 'angle')
// // value: Must be an array, not null/undefined. Contain dimension indices, like:
// // {
// // x: [2] // values on dimension index 2 are mapped to x axis.
// // y: [0] // values on dimension index 0 are mapped to y axis.
// // }
// encode: Object,
// // dimension names list
// dimensionNames: Array<String>,
// // data dimension index, for example 0 or 1 or 2 ...
// // Only work in `radar` series.
// dimensionIndex: number,
// // Color of data
// color: string,
//
// // the percentage of pie chart
// percent: number,
// }
Formatter string `json:"formatter,omitempty"`
// Configuration item for axisPointer
AxisPointer *AxisPointer `json:"axisPointer,omitempty"`
}
// AxisPointer is the option set for an axisPointer component
// https://echarts.apache.org/en/option.html#axisPointer
type AxisPointer struct {
// Indicator type.
// Options:
// - 'line' line indicator.
// - 'shadow' shadow crosshair indicator.
// - 'none' no indicator displayed.
// - 'cross' crosshair indicator, which is actually the shortcut of enable two axisPointers of two orthometric axes.
Type string `json:"type,omitempty"`
// Whether snap to point automatically. The default value is auto determined.
// This feature usually makes sense in value axis and time axis, where tiny points can be seeked automatically.
Snap bool `json:"snap,omitempty"`
}
// Toolbox is the option set for a toolbox component.
// https://echarts.apache.org/en/option.html#toolbox
type Toolbox struct {
// Whether to show toolbox component.
Show bool `json:"show"`
// The layout orientation of toolbox's icon.
// Options: 'horizontal','vertical'
Orient string `json:"orient,omitempty"`
// Distance between toolbox component and the left side of the container.
// left value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'; and it can also be 'left', 'center', or 'right'.
// If the left value is set to be 'left', 'center', or 'right', then the component
// will be aligned automatically based on position.
Left string `json:"left,omitempty"`
// Distance between toolbox component and the top side of the container.
// top value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'; and it can also be 'top', 'middle', or 'bottom'.
// If the left value is set to be 'top', 'middle', or 'bottom', then the component
// will be aligned automatically based on position.
Top string `json:"top,omitempty"`
// Distance between toolbox component and the right side of the container.
// right value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'.
// Adaptive by default.
Right string `json:"right,omitempty"`
// Distance between toolbox component and the bottom side of the container.
// bottom value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'.
// Adaptive by default.
Bottom string `json:"bottom,omitempty"`
// The configuration item for each tool.
// Besides the tools we provide, user-defined toolbox is also supported.
Feature *ToolBoxFeature `json:"feature,omitempty"`
}
// ToolBoxFeature is a feature component under toolbox.
// https://echarts.apache.org/en/option.html#toolbox
type ToolBoxFeature struct {
// Save as image tool
SaveAsImage *ToolBoxFeatureSaveAsImage `json:"saveAsImage,omitempty"`
// Data area zooming, which only supports rectangular coordinate by now.
DataZoom *ToolBoxFeatureDataZoom `json:"dataZoom,omitempty"`
// Data view tool, which could display data in current chart and updates chart after being edited.
DataView *ToolBoxFeatureDataView `json:"dataView,omitempty"`
// Restore configuration item.
Restore *ToolBoxFeatureRestore `json:"restore,omitempty"`
}
// ToolBoxFeatureSaveAsImage is the option for saving chart as image.
// https://echarts.apache.org/en/option.html#toolbox.feature.saveAsImage
type ToolBoxFeatureSaveAsImage struct {
// Whether to show the tool.
Show bool `json:"show"`
// toolbox.feature.saveAsImage. type = 'png'
// File suffix of the image saved.
// If the renderer is set to be 'canvas' when chart initialized (default), t
// hen 'png' (default) and 'jpeg' are supported.
// If the renderer is set to be 'svg' when when chart initialized, then only 'svg' is supported
// for type ('svg' type is supported since v4.8.0).
Type string `json:"png,omitempty"`
// Name to save the image, whose default value is title.text.
Name string `json:"name,omitempty"`
// Title for the tool.
Title string `json:"title,omitempty"`
}
// ToolBoxFeatureDataZoom
// https://echarts.apache.org/en/option.html#toolbox.feature.dataZoom
type ToolBoxFeatureDataZoom struct {
// Whether to show the tool.
Show bool `json:"show"`
// Restored and zoomed title text.
// m["zoom"] = "area zooming"
// m["back"] = "restore area zooming"
Title map[string]string `json:"title"`
}
// ToolBoxFeatureDataView
// https://echarts.apache.org/en/option.html#toolbox.feature.dataView
type ToolBoxFeatureDataView struct {
// Whether to show the tool.
Show bool `json:"show"`
// title for the tool.
Title string `json:"title,omitempty"`
// There are 3 names in data view
// you could set them like this: []string["data view", "turn off", "refresh"]
Lang []string `json:"lang"`
// Background color of the floating layer in data view.
BackgroundColor string `json:"backgroundColor"`
}
// ToolBoxFeatureRestore
// https://echarts.apache.org/en/option.html#toolbox.feature.restore
type ToolBoxFeatureRestore struct {
// Whether to show the tool.
Show bool `json:"show"`
// title for the tool.
Title string `json:"title,omitempty"`
}
// AxisLabel settings related to axis label.
// https://echarts.apache.org/en/option.html#xAxis.axisLabel
type AxisLabel struct {
// Set this to false to prevent the axis label from appearing.
Show bool `json:"show,omitempty"`
// Interval of Axis label, which is available in category axis.
// It uses a strategy that labels do not overlap by default.
// You may set it to be 0 to display all labels compulsively.
// If it is set to be 1, it means that labels are shown once after one label.
// And if it is set to be 2, it means labels are shown once after two labels, and so on.
Interval string `json:"interval,omitempty"`
// Set this to true so the axis labels face the inside direction.
Inside bool `json:"inside,omitempty"`
// Rotation degree of axis label, which is especially useful when there is no enough space for category axis.
// Rotation degree is from -90 to 90.
Rotate float64 `json:"rotate,omitempty"`
// The margin between the axis label and the axis line.
Margin float64 `json:"margin,omitempty"`
// Formatter of axis label, which supports string template and callback function.
//
// Example:
//
// Use string template; template variable is the default label of axis {value}
// formatter: '{value} kg'
//
// Use callback function; function parameters are axis index
//
//
// formatter: function (value, index) {
// // Formatted to be month/day; display year only in the first label
// var date = new Date(value);
// var texts = [(date.getMonth() + 1), date.getDate()];
// if (idx === 0) {
// texts.unshift(date.getYear());
// }
// return texts.join('/');
//}
Formatter string `json:"formatter,omitempty"`
ShowMinLabel bool `json:"showMinLabel"`
ShowMaxLabel bool `json:"showMaxLabel"`
// Color of axis label is set to be axisLine.lineStyle.color by default. Callback function is supported,
// in the following format:
//
// (val: string) => Color
// Parameter is the text of label, and return value is the color. See the following example:
//
// textStyle: {
// color: function (value, index) {
// return value >= 0 ? 'green' : 'red';
// }
// }
Color string `json:"color,omitempty"`
// axis label font style
FontStyle string `json:"fontStyle,omitempty"`
// axis label font weight
FontWeight string `json:"fontWeight,omitempty"`
// axis label font family
FontFamily string `json:"fontFamily,omitempty"`
// axis label font size
FontSize string `json:"fontSize,omitempty"`
// Horizontal alignment of axis label
Align string `json:"align,omitempty"`
// Vertical alignment of axis label
VerticalAlign string `json:"verticalAlign,omitempty"`
// Line height of the axis label
LineHeight string `json:"lineHeight,omitempty"`
}
// XAxis is the option set for X axis.
// https://echarts.apache.org/en/option.html#xAxis
type XAxis struct {
// Name of axis.
Name string `json:"name,omitempty"`
// Type of axis.
// Option:
// * 'value': Numerical axis, suitable for continuous data.
// * 'category': Category axis, suitable for discrete category data.
// Category data can be auto retrieved from series.data or dataset.source,
// or can be specified via xAxis.data.
// * 'time' Time axis, suitable for continuous time series data. As compared to value axis,
// it has a better formatting for time and a different tick calculation method. For example,
// it decides to use month, week, day or hour for tick based on the range of span.
// * 'log' Log axis, suitable for log data.
Type string `json:"type,omitempty"`
// Set this to false to prevent the axis from showing.
Show bool `json:"show,omitempty"`
// Category data, available in type: 'category' axis.
Data interface{} `json:"data,omitempty"`
// Number of segments that the axis is split into. Note that this number serves only as a
// recommendation, and the true segments may be adjusted based on readability.
// This is unavailable for category axis.
SplitNumber int `json:"splitNumber,omitempty"`
// It is available only in numerical axis, i.e., type: 'value'.
// It specifies whether not to contain zero position of axis compulsively.
// When it is set to be true, the axis may not contain zero position,
// which is useful in the scatter chart for both value axes.
// This configuration item is unavailable when the min and max are set.
Scale bool `json:"scale,omitempty"`
// The minimum value of axis.
// It can be set to a special value 'dataMin' so that the minimum value on this axis is set to be the minimum label.
// It will be automatically computed to make sure axis tick is equally distributed when not set.
Min interface{} `json:"min,omitempty"`
// The maximum value of axis.
// It can be set to a special value 'dataMax' so that the minimum value on this axis is set to be the maximum label.
// It will be automatically computed to make sure axis tick is equally distributed when not set.
Max interface{} `json:"max,omitempty"`
// The index of grid which the x axis belongs to. Defaults to be in the first grid.
// default 0
GridIndex int `json:"gridIndex,omitempty"`
// Split area of X axis in grid area.
SplitArea *SplitArea `json:"splitArea,omitempty"`
// Split line of X axis in grid area.
SplitLine *SplitLine `json:"splitLine,omitempty"`
// Settings related to axis label.
AxisLabel *AxisLabel `json:"axisLabel,omitempty"`
}
// YAxis is the option set for Y axis.
// https://echarts.apache.org/en/option.html#yAxis
type YAxis struct {
// Name of axis.
Name string `json:"name,omitempty"`
// Type of axis.
// Option:
// * 'value': Numerical axis, suitable for continuous data.
// * 'category': Category axis, suitable for discrete category data.
// Category data can be auto retrieved from series.data or dataset.source,
// or can be specified via xAxis.data.
// * 'time' Time axis, suitable for continuous time series data. As compared to value axis,
// it has a better formatting for time and a different tick calculation method. For example,
// it decides to use month, week, day or hour for tick based on the range of span.
// * 'log' Log axis, suitable for log data.
Type string `json:"type,omitempty"`
// Set this to false to prevent the axis from showing.
Show bool `json:"show,omitempty"`
// Category data, available in type: 'category' axis.
Data interface{} `json:"data,omitempty"`
// Number of segments that the axis is split into. Note that this number serves only as a
// recommendation, and the true segments may be adjusted based on readability.
// This is unavailable for category axis.
SplitNumber int `json:"splitNumber,omitempty"`
// It is available only in numerical axis, i.e., type: 'value'.
// It specifies whether not to contain zero position of axis compulsively.
// When it is set to be true, the axis may not contain zero position,
// which is useful in the scatter chart for both value axes.
// This configuration item is unavailable when the min and max are set.
Scale bool `json:"scale,omitempty"`
// The minimum value of axis.
// It can be set to a special value 'dataMin' so that the minimum value on this axis is set to be the minimum label.
// It will be automatically computed to make sure axis tick is equally distributed when not set.
Min interface{} `json:"min,omitempty"`
// The maximum value of axis.
// It can be set to a special value 'dataMax' so that the minimum value on this axis is set to be the maximum label.
// It will be automatically computed to make sure axis tick is equally distributed when not set.
Max interface{} `json:"max,omitempty"`
// The index of grid which the Y axis belongs to. Defaults to be in the first grid.
// default 0
GridIndex int `json:"gridIndex,omitempty"`
// Split area of Y axis in grid area.
SplitArea *SplitArea `json:"splitArea,omitempty"`
// Split line of Y axis in grid area.
SplitLine *SplitLine `json:"splitLine,omitempty"`
// Settings related to axis label.
AxisLabel *AxisLabel `json:"axisLabel,omitempty"`
}
// TextStyle is the option set for a text style component.
type TextStyle struct {
// Font color
Color string `json:"color,omitempty"`
// Font style
// Options: 'normal', 'italic', 'oblique'
FontStyle string `json:"fontStyle,omitempty"`
// Font size
FontSize int `json:"fontSize,omitempty"`
// Font family the main title font family.
// Options: "sans-serif", 'serif' , 'monospace', 'Arial', 'Courier New', 'Microsoft YaHei', ...
FontFamily string `json:"fontFamily,omitempty"`
// Padding title space around content.
// The unit is px. Default values for each position are 5.
// And they can be set to different values with left, right, top, and bottom.
Padding interface{} `json:"padding,omitempty"`
// compatible for WordCloud
Normal *TextStyle `json:"normal,omitempty"`
}
// SplitArea is the option set for a split area.
type SplitArea struct {
// Set this to true to show the splitArea.
Show bool `json:"show"`
// Split area style.
AreaStyle *AreaStyle `json:"areaStyle,omitempty"`
}
// SplitLine is the option set for a split line.
type SplitLine struct {
// Set this to true to show the splitLine.
Show bool `json:"show"`
// Split line style.
LineStyle *LineStyle `json:"lineStyle,omitempty"`
}
// VisualMap is a type of component for visual encoding, which maps the data to visual channels.
// https://echarts.apache.org/en/option.html#visualMap
type VisualMap struct {
// Mapping type.
// Options: "continuous", "piecewise"
Type string `json:"type,omitempty" default:"continuous"`
// Whether show handles, which can be dragged to adjust "selected range".
Calculable bool `json:"calculable"`
// Specify the min dataValue for the visualMap component.
// [visualMap.min, visualMax.max] make up the domain of visual mapping.
Min float32 `json:"min,omitempty"`
// Specify the max dataValue for the visualMap component.
// [visualMap.min, visualMax.max] make up the domain of visual mapping.
Max float32 `json:"max,omitempty"`
// Specify selected range, that is, the dataValue corresponding to the two handles.
Range []float32 `json:"range,omitempty"`
// The label text on both ends, such as ['High', 'Low'].
Text []string `json:"text,omitempty"`
// Define visual channels that will mapped from dataValues that are in selected range.
InRange *VisualMapInRange `json:"inRange,omitempty"`
}
// VisualMapInRange is a visual map instance in a range.
type VisualMapInRange struct {
// Color
Color []string `json:"color,omitempty"`
// Symbol type at the two ends of the mark line. It can be an array for two ends, or assigned separately.
// Options: "circle", "rect", "roundRect", "triangle", "diamond", "pin", "arrow", "none"
Symbol string `json:"symbol,omitempty"`
// Symbol size.
SymbolSize float32 `json:"symbolSize,omitempty"`
}
// DataZoom is the option set for a zoom component.
// dataZoom component is used for zooming a specific area, which enables user to
// investigate data in detail, or get an overview of the data, or get rid of outlier points.
// https://echarts.apache.org/en/option.html#dataZoom
type DataZoom struct {
// Data zoom component of inside type, Options: "inside", "slider"
Type string `json:"type" default:"inside"`
// The start percentage of the window out of the data extent, in the range of 0 ~ 100.
// default 0
Start float32 `json:"start,omitempty"`
// The end percentage of the window out of the data extent, in the range of 0 ~ 100.
// default 100
End float32 `json:"end,omitempty"`
// Specify the frame rate of views refreshing, with unit millisecond (ms).
// If animation set as true and animationDurationUpdate set as bigger than 0,
// you can keep throttle as the default value 100 (or set it as a value bigger than 0),
// otherwise it might be not smooth when dragging.
// If animation set as false or animationDurationUpdate set as 0, and data size is not very large,
// and it seems to be not smooth when dragging, you can set throttle as 0 to improve that.
Throttle float32 `json:"throttle,omitempty"`
// Specify which xAxis is/are controlled by the dataZoom-inside when Cartesian coordinate system is used.
// By default the first xAxis that parallel to dataZoom are controlled when dataZoom-inside.
// Orient is set as 'horizontal'. But it is recommended to specify it explicitly but not use default value.
// If it is set as a single number, one axis is controlled, while if it is set as an Array ,
// multiple axes are controlled.
XAxisIndex interface{} `json:"xAxisIndex,omitempty"`
// Specify which yAxis is/are controlled by the dataZoom-inside when Cartesian coordinate system is used.
// By default the first yAxis that parallel to dataZoom are controlled when dataZoom-inside.
// Orient is set as 'vertical'. But it is recommended to specify it explicitly but not use default value.
// If it is set as a single number, one axis is controlled, while if it is set as an Array ,
// multiple axes are controlled.
YAxisIndex interface{} `json:"yAxisIndex,omitempty"`
}
// SingleAxis is the option set for single axis.
// https://echarts.apache.org/en/option.html#singleAxis
type SingleAxis struct {
// The minimum value of axis.
// It can be set to a special value 'dataMin' so that the minimum value on this axis is set to be the minimum label.
// It will be automatically computed to make sure axis tick is equally distributed when not set.
Min interface{} `json:"min,omitempty"`
// The maximum value of axis.
// It can be set to a special value 'dataMax' so that the minimum value on this axis is set to be the maximum label.
// It will be automatically computed to make sure axis tick is equally distributed when not set.
Max interface{} `json:"max,omitempty"`
// Type of axis.
// Option:
// * 'value': Numerical axis, suitable for continuous data.
// * 'category': Category axis, suitable for discrete category data.
// Category data can be auto retrieved from series.data or dataset.source,
// or can be specified via xAxis.data.
// * 'time' Time axis, suitable for continuous time series data. As compared to value axis,
// it has a better formatting for time and a different tick calculation method. For example,
// it decides to use month, week, day or hour for tick based on the range of span.
// * 'log' Log axis, suitable for log data.
Type string `json:"type,omitempty"`
// Distance between grid component and the left side of the container.
// left value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'; and it can also be 'left', 'center', or 'right'.
// If the left value is set to be 'left', 'center', or 'right',
// then the component will be aligned automatically based on position.
Left string `json:"left,omitempty"`
// Distance between grid component and the right side of the container.
//right value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'.
Right string `json:"right,omitempty"`
// Distance between grid component and the top side of the container.
// top value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'; and it can also be 'top', 'middle', or 'bottom'.
// If the left value is set to be 'top', 'middle', or 'bottom',
// then the component will be aligned automatically based on position.
Top string `json:"top,omitempty"`
// Distance between grid component and the bottom side of the container.
// bottom value can be instant pixel value like 20; it can also be a percentage
// value relative to container width like '20%'.
Bottom string `json:"bottom,omitempty"`
}
// Indicator is the option set for a radar chart.
type Indicator struct {
// Indicator name
Name string `json:"name,omitempty"`
// The maximum value of indicator. It is an optional configuration, but we recommend to set it manually.
Max float32 `json:"max,omitempty"`
// The minimum value of indicator. It it an optional configuration, with default value of 0.
Min float32 `json:"min,omitempty"`
// Specify a color the the indicator.
Color string `json:"color,omitempty"`
}
// RadarComponent is the option set for a radar component.
// https://echarts.apache.org/en/option.html#radar
type RadarComponent struct {
// Indicator of radar chart, which is used to assign multiple variables(dimensions) in radar chart.
Indicator []*Indicator `json:"indicator,omitempty"`
// Radar render type, in which 'polygon' and 'circle' are supported.
Shape string `json:"shape,omitempty"`
// Segments of indicator axis.
// default 5
SplitNumber int `json:"splitNumber,omitempty"`
// Center position of , the first of which is the horizontal position, and the second is the vertical position.
// Percentage is supported. When set in percentage, the item is relative to the container width and height.
Center interface{} `json:"center,omitempty"`
// Split area of axis in grid area.
SplitArea *SplitArea `json:"splitArea,omitempty"`
// Split line of axis in grid area.
SplitLine *SplitLine `json:"splitLine,omitempty"`
}
// GeoComponent is the option set for geo component.
// https://echarts.apache.org/en/option.html#geo
type GeoComponent struct {
// Map charts.
Map string `json:"map,omitempty"`
// Graphic style of Map Area Border, emphasis is the style when it is highlighted,
// like being hovered by mouse, or highlighted via legend connect.
ItemStyle *ItemStyle `json:"itemStyle,omitempty"`
// Set this to true, to prevent interaction with the axis.
Silent bool `json:"silent,omitempty"`
}
// ParallelComponent is the option set for parallel component.
type ParallelComponent struct {
// Distance between parallel component and the left side of the container.
// Left value can be instant pixel value like 20.
// It can also be a percentage value relative to container width like '20%';
// and it can also be 'left', 'center', or 'right'.
// If the left value is set to be 'left', 'center', or 'right',
// then the component will be aligned automatically based on position.
Left string `json:"left,omitempty"`
// Distance between parallel component and the top side of the container.
// Top value can be instant pixel value like 20.
// It can also be a percentage value relative to container width like '20%'.
// and it can also be 'top', 'middle', or 'bottom'.
// If the left value is set to be 'top', 'middle', or 'bottom',
// then the component will be aligned automatically based on position.
Top string `json:"top,omitempty"`
// Distance between parallel component and the right side of the container.
// Right value can be instant pixel value like 20.
// It can also be a percentage value relative to container width like '20%'.
Right string `json:"right,omitempty"`
// Distance between parallel component and the bottom side of the container.
// Bottom value can be instant pixel value like 20.
// It can also be a percentage value relative to container width like '20%'.
Bottom string `json:"bottom,omitempty"`
}
// ParallelAxis is the option set for a parallel axis.
type ParallelAxis struct {
// Dimension index of coordinate axis.
Dim int `json:"dim,omitempty"`
// Name of axis.
Name string `json:"name,omitempty"`
// The maximum value of axis.
// It can be set to a special value 'dataMax' so that the minimum value on this axis is set to be the maximum label.
// It will be automatically computed to make sure axis tick is equally distributed when not set.
// In category axis, it can also be set as the ordinal number.
Max interface{} `json:"max,omitempty"`
// Compulsively set segmentation interval for axis.
Inverse bool `json:"inverse,omitempty"`
// Location of axis name. Options: "start", "middle", "center", "end"
// default "end"
NameLocation string `json:"nameLocation,omitempty"`
// Type of axis.
// Options:
// "value":Numerical axis, suitable for continuous data.
// "category" Category axis, suitable for discrete category data. Category data can be auto retrieved from series.
// "log" Log axis, suitable for log data.
Type string `json:"type,omitempty"`
// Category data,works on (type: "category").
Data interface{} `json:"data,omitempty"`
}
// Polar Bar options
type Polar struct {
ID string `json:"id,omitempty"`
Zlevel int `json:"zlevel,omitempty"`
Z int `json:"z,omitempty"`
Center [2]string `json:"center,omitempty"`
Radius [2]string `json:"radius,omitempty"`
Tooltip Tooltip `json:"tooltip,omitempty"`
}
type PolarAxisBase struct {
ID string `json:"id,omitempty"`
PolarIndex int `json:"polarIndex,omitempty"`
StartAngle float64 `json:"startAngle,omitempty"`
Type string `json:"type,omitempty"`
BoundaryGap bool `json:"boundaryGap,omitempty"`
Min float64 `json:"min,omitempty"`
Max float64 `json:"max,omitempty"`
Scale bool `json:"scale,omitempty"`
SplitNumber int `json:"splitNumber,omitempty"`
MinInterval float64 `json:"minInterval,omitempty"`
MaxInterval float64 `json:"maxInterval,omitempty"`
Interval float64 `json:"interval,omitempty"`
LogBase float64 `json:"logBase,omitempty"`
Silent bool `json:"silent,omitempty"`
TriggerEvent bool `json:"triggerEvent,omitempty"`
}
type AngleAxis struct {
PolarAxisBase
Clockwise bool `json:"clockwise,omitempty"`
}
type RadiusAxis struct {
PolarAxisBase
Name string `json:"name,omitempty"`
NameLocation string `json:"nameLocation,omitempty"`
NameTextStyle TextStyle `json:"nameTextStyle,omitempty"`
NameGap float64 `json:"nameGap,omitempty"`
NameRadius float64 `json:"nameRotate,omitempty"`
Inverse bool `json:"inverse,omitempty"`
}
var funcPat = regexp.MustCompile(`\n|\t`)