Debian Codegraph @

charts/series.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/types"
6 "github.com/go-echarts/go-echarts/v2/util"
7 )
8
9 type SingleSeries struct {
10 Name string `json:"name,omitempty"`
11 Type string `json:"type,omitempty"`
12 Id string `json:"id,omitempty"`
13
14 // Rectangular charts
15 // Line | Bar
16 Stack string `json:"stack,omitempty"`
17 // Line | Bar | Scatter
18 XAxisIndex int `json:"xAxisIndex,omitempty"`
19 // Line | Bar | Scatter
20 YAxisIndex int `json:"yAxisIndex,omitempty"`
21
22 // Bar
23 BarGap string `json:"barGap,omitempty"`
24 // Bar
25 BarCategoryGap string `json:"barCategoryGap,omitempty"`
26 // Bar
27 ShowBackground types.Bool `json:"showBackground,omitempty"`
28 // Bar
29 RoundCap types.Bool `json:"roundCap,omitempty"`
30
31 // Bar3D
32 Shading string `json:"shading,omitempty"`
33
34 // Graph
35 Links interface{} `json:"links,omitempty"`
36 Layout string `json:"layout,omitempty"`
37 Force interface{} `json:"force,omitempty"`
38 Categories interface{} `json:"categories,omitempty"`
39 Roam types.Bool `json:"roam,omitempty"`
40 EdgeSymbol interface{} `json:"edgeSymbol,omitempty"`
41 EdgeSymbolSize interface{} `json:"edgeSymbolSize,omitempty"`
42 EdgeLabel interface{} `json:"edgeLabel,omitempty"`
43 Draggable types.Bool `json:"draggable,omitempty"`
44 FocusNodeAdjacency types.Bool `json:"focusNodeAdjacency,omitempty"`
45 // Line | Radar
46 SymbolKeepAspect types.Bool `json:"symbolKeepAspect,omitempty"`
47
48 // BarWidth The width options of the bar. Adaptive when not specified.
49 // Can be an absolute value like 40 or a percent value like '60%'.
50 // Configurable charts: bar | kline
51 BarWidth string `json:"barWidth,omitempty"`
52 BarMinWidth string `json:"barMinWidth,omitempty"`
53 BarMaxWidth string `json:"barMaxWidth,omitempty"`
54
55 // Line | Bar | Pie | Scatter | Radar
56 ColorBy string `json:"colorBy,omitempty"`
57 // Line | Bar
58 PolarIndex int `json:"polarIndex,omitempty"`
59 // Line
60 Step interface{} `json:"step,omitempty"`
61 // Line
62 Smooth types.Bool `json:"smooth,omitempty"`
63 // Line
64 ConnectNulls types.Bool `json:"connectNulls,omitempty"`
65 // Line
66 ShowSymbol types.Bool `json:"showSymbol,omitempty"`
67 // Line | Scatter | Radar
68 Symbol string `json:"symbol,omitempty"`
69 Color string `json:"color,omitempty"`
70
71 // Liquid
72 IsLiquidOutline types.Bool `json:"outline,omitempty"`
73 IsWaveAnimation types.Bool `json:"waveAnimation,omitempty"`
74
75 // Map
76 MapType string `json:"map,omitempty"`
77 // Map | Line | Bar | Pie | Scatter
78 CoordSystem string `json:"coordinateSystem,omitempty"`
79
80 // Pie
81 RoseType string `json:"roseType,omitempty"`
82 // Pie
83 Center interface{} `json:"center,omitempty"`
84 // Pie
85 Radius interface{} `json:"radius,omitempty"`
86 // Pie
87 PadAngle float64 `json:"padAngle,omitempty"`
88
89 // Line | Scatter | Radar
90 SymbolSize interface{} `json:"symbolSize,omitempty"`
91
92 // Tree
93 Orient string `json:"orient,omitempty"`
94 ExpandAndCollapse types.Bool `json:"expandAndCollapse,omitempty"`
95 InitialTreeDepth int `json:"initialTreeDepth,omitempty"`
96 Leaves interface{} `json:"leaves,omitempty"`
97 Left string `json:"left,omitempty"`
98 Right string `json:"right,omitempty"`
99 Top string `json:"top,omitempty"`
100 Bottom string `json:"bottom,omitempty"`
101
102 // Sankey
103 NodeWidth types.Int `json:"nodeWidth,omitempty"`
104 NodeGap types.Int `json:"nodeGap,omitempty"`
105 NodeAlign string `json:"nodeAlign,omitempty"`
106
107 // Radar
108 RadarIndex int `json:"radarIndex,omitempty"`
109
110 // TreeMap
111 LeafDepth int `json:"leafDepth,omitempty"`
112 Levels interface{} `json:"levels,omitempty"`
113 UpperLabel interface{} `json:"upperLabel,omitempty"`
114
115 // WordCloud
116 Shape string `json:"shape,omitempty"`
117 SizeRange []float32 `json:"sizeRange,omitempty"`
118 RotationRange []float32 `json:"rotationRange,omitempty"`
119
120 // Sunburst
121 NodeClick string `json:"nodeClick,omitempty"`
122 Sort string `json:"sort,omitempty"`
123
124 // Custom
125 RenderItem types.FuncStr `json:"renderItem,omitempty"`
126
127 // series data
128 Data interface{} `json:"data,omitempty"`
129 DatasetIndex int `json:"datasetIndex,omitempty"`
130
131 // Bar | Lines | Scatter | Heatmap | Parallel | Candlestick
132 // Progressive specifies the amount of graphic elements that can be rendered
133 // within a frame (about 16ms) if "progressive rendering" is enabled.
134 // "Progressive rendering" processes and renders data chunk by chunk on
135 // different canvas layers to avoid blocking the UI thread of the browser for
136 // series with many data points.
137 // Set progressive to 0 to disable progressive rendering.
138 Progressive types.Int `json:"progressive,omitempty"`
139 ProgressiveThreshold types.Int `json:"progressiveThreshold,omitempty"`
140
141 // Gauge
142 Progress *opts.Progress `json:"progress,omitempty"`
143 AxisTick *opts.AxisTick `json:"axisTick,omitempty"`
144 AxisLabel *opts.AxisLabel `json:"axisLabel,omitempty"`
145 AxisLine *opts.AxisLine `json:"axisLine,omitempty"`
146 Pointer *opts.Pointer `json:"pointer,omitempty"`
147 SplitLine *opts.SplitLine `json:"splitLine,omitempty"`
148 Detail *opts.Detail `json:"detail,omitempty"`
149 Title *opts.Title `json:"title,omitempty"`
150 Min int `json:"min,omitempty"`
151 Max int `json:"max,omitempty"`
152 StartAngle float64 `json:"startAngle,omitempty"`
153 EndAngle float64 `json:"endAngle,omitempty"`
154
155 Large types.Bool `json:"large,omitempty"`
156 LargeThreshold int `json:"largeThreshold,omitempty"`
157 HoverLayerThreshold int `json:"hoverLayerThreshold,omitempty"`
158 UseUTC types.Bool `json:"useUTC,omitempty"`
159
160 // Animation related configs
161 Animation types.Bool `json:"animation,omitempty"`
162 AnimationThreshold int `json:"animationThreshold,omitempty"`
163 AnimationDuration int `json:"animationDuration,omitempty"`
164 AnimationEasing string `json:"animationEasing,omitempty"`
165 AnimationDelay int `json:"animationDelay,omitempty"`
166 AnimationDurationUpdate int `json:"animationDurationUpdate,omitempty"`
167 AnimationEasingUpdate string `json:"animationEasingUpdate,omitempty"`
168 AnimationDelayUpdate int `json:"animationDelayUpdate,omitempty"`
169 RenderLabelForZeroData types.Bool `json:"renderLabelForZeroData,omitempty"`
170 SelectedMode types.Bool `json:"selectedMode,omitempty"`
171
172 // series options
173 *opts.Encode `json:"encode,omitempty"`
174 *opts.ItemStyle `json:"itemStyle,omitempty"`
175 *opts.Label `json:"label,omitempty"`
176 *opts.LabelLayout `json:"labelLayout,omitempty"`
177 *opts.LabelLine `json:"labelLine,omitempty"`
178 *opts.Emphasis `json:"emphasis,omitempty"`
179 *opts.MarkLines `json:"markLine,omitempty"`
180 *opts.MarkAreas `json:"markArea,omitempty"`
181 *opts.MarkPoints `json:"markPoint,omitempty"`
182 *opts.RippleEffect `json:"rippleEffect,omitempty"`
183 *opts.LineStyle `json:"lineStyle,omitempty"`
184 *opts.AreaStyle `json:"areaStyle,omitempty"`
185 *opts.TextStyle `json:"textStyle,omitempty"`
186 *opts.CircularStyle `json:"circular,omitempty"`
187 *opts.SeriesTooltip `json:"tooltip,omitempty"`
188
189 // Calendar
190 CalendarIndex int `json:"calendarIndex,omitempty"`
191 }
192
193 type SeriesOpts func(s *SingleSeries)
194
195 type SingleSeriesOptFunc func(s *SingleSeries)
196
197 // WithSeriesOpts If the WithXXX helper method is not good enough, use this directly!
198 func WithSeriesOpts(opf SingleSeriesOptFunc) SeriesOpts {
199 return func(s *SingleSeries) {
200 opf(s)
201 }
202 }
203
204 func WithSeriesId(id string) SeriesOpts {
205 return func(s *SingleSeries) {
206 s.Id = id
207 }
208 }
209
210 func WithCoordinateSystem(cs string) SeriesOpts {
211 return func(s *SingleSeries) {
212 s.CoordSystem = cs
213 }
214 }
215
216 func WithCalendarIndex(index int) SeriesOpts {
217 return func(s *SingleSeries) {
218 s.CalendarIndex = index
219 }
220 }
221
222 func WithSeriesAnimation(enable bool) SeriesOpts {
223 return func(s *SingleSeries) {
224 s.Animation = opts.Bool(enable)
225 }
226 }
227
228 func WithSeriesSymbolKeepAspect(enable bool) SeriesOpts {
229 return func(s *SingleSeries) {
230 s.SymbolKeepAspect = opts.Bool(enable)
231 }
232 }
233
234 func WithAnimationOpts(opt opts.Animation) SeriesOpts {
235 return func(s *SingleSeries) {
236 s.Animation = opt.Animation
237 s.AnimationThreshold = opt.AnimationThreshold
238 s.AnimationDuration = opt.AnimationDuration
239 s.AnimationEasing = opt.AnimationEasing
240 s.AnimationDelay = opt.AnimationDelay
241 s.AnimationDurationUpdate = opt.AnimationDurationUpdate
242 s.AnimationEasingUpdate = opt.AnimationEasingUpdate
243 s.AnimationDelayUpdate = opt.AnimationDelayUpdate
244 }
245 }
246
247 // WithLabelOpts sets the label.
248 func WithLabelOpts(opt opts.Label) SeriesOpts {
249 return func(s *SingleSeries) {
250 s.Label = &opt
251 }
252 }
253
254 // WithLabelLayoutOpts sets the label.
255 func WithLabelLayoutOpts(opt opts.LabelLayout) SeriesOpts {
256 return func(s *SingleSeries) {
257 s.LabelLayout = &opt
258 }
259 }
260
261 // WithLabelLineOpts sets the label.
262 func WithLabelLineOpts(opt opts.LabelLine) SeriesOpts {
263 return func(s *SingleSeries) {
264 s.LabelLine = &opt
265 }
266 }
267
268 // WithEmphasisOpts sets the emphasis.
269 func WithEmphasisOpts(opt opts.Emphasis) SeriesOpts {
270 return func(s *SingleSeries) {
271 s.Emphasis = &opt
272 }
273 }
274
275 // WithAreaStyleOpts sets the area style.
276 func WithAreaStyleOpts(opt opts.AreaStyle) SeriesOpts {
277 return func(s *SingleSeries) {
278 s.AreaStyle = &opt
279 }
280 }
281
282 // WithItemStyleOpts sets the item style.
283 func WithItemStyleOpts(opt opts.ItemStyle) SeriesOpts {
284 return func(s *SingleSeries) {
285 s.ItemStyle = &opt
286 }
287 }
288
289 // WithRippleEffectOpts sets the ripple effect.
290 func WithRippleEffectOpts(opt opts.RippleEffect) SeriesOpts {
291 return func(s *SingleSeries) {
292 s.RippleEffect = &opt
293 }
294 }
295
296 // WithLineStyleOpts sets the line style.
297 func WithLineStyleOpts(opt opts.LineStyle) SeriesOpts {
298 return func(s *SingleSeries) {
299 s.LineStyle = &opt
300 }
301 }
302
303 // WithCircularStyleOpts With CircularStyle Opts
304 func WithCircularStyleOpts(opt opts.CircularStyle) SeriesOpts {
305 return func(s *SingleSeries) {
306 s.CircularStyle = &opt
307 }
308 }
309
310 // WithSeriesTooltipOpts With Tooltip Opts
311 func WithSeriesTooltipOpts(opt opts.SeriesTooltip) SeriesOpts {
312 return func(s *SingleSeries) {
313 s.SeriesTooltip = &opt
314 }
315 }
316
317 /* Chart Options */
318
319 // WithBarChartOpts sets the BarChart option.
320 func WithBarChartOpts(opt opts.BarChart) SeriesOpts {
321 return func(s *SingleSeries) {
322 s.ColorBy = opt.ColorBy
323 s.CoordSystem = opt.CoordSystem
324 s.XAxisIndex = opt.XAxisIndex
325 s.YAxisIndex = opt.YAxisIndex
326 s.PolarIndex = opt.PolarIndex
327 s.RoundCap = opt.RoundCap
328 s.ShowBackground = opt.ShowBackground
329 s.Stack = opt.Stack
330 s.BarGap = opt.BarGap
331 s.BarCategoryGap = opt.BarCategoryGap
332 s.BarWidth = opt.BarWidth
333 }
334 }
335
336 // WithSunburstOpts sets the SunburstChart option.
337 func WithSunburstOpts(opt opts.SunburstChart) SeriesOpts {
338 return func(s *SingleSeries) {
339 s.NodeClick = opt.NodeClick
340 s.Sort = opt.Sort
341 s.RenderLabelForZeroData = opt.RenderLabelForZeroData
342 s.SelectedMode = opt.SelectedMode
343 s.Animation = opt.Animation
344 s.AnimationThreshold = opt.AnimationThreshold
345 s.AnimationDuration = opt.AnimationDuration
346 s.AnimationEasing = opt.AnimationEasing
347 s.AnimationDelay = opt.AnimationDelay
348 s.AnimationDurationUpdate = opt.AnimationDurationUpdate
349 s.AnimationEasingUpdate = opt.AnimationEasingUpdate
350 s.AnimationDelayUpdate = opt.AnimationDelayUpdate
351 }
352 }
353
354 // WithGraphChartOpts sets the GraphChart option.
355 func WithGraphChartOpts(opt opts.GraphChart) SeriesOpts {
356 return func(s *SingleSeries) {
357 s.Layout = opt.Layout
358 s.Force = opt.Force
359 s.Roam = opt.Roam
360 s.EdgeSymbol = opt.EdgeSymbol
361 s.EdgeSymbolSize = opt.EdgeSymbolSize
362 s.Draggable = opt.Draggable
363 s.FocusNodeAdjacency = opt.FocusNodeAdjacency
364 s.Categories = opt.Categories
365 s.EdgeLabel = opt.EdgeLabel
366 s.SymbolKeepAspect = opt.SymbolKeepAspect
367 }
368 }
369
370 // WithHeatMapChartOpts sets the HeatMapChart option.
371 func WithHeatMapChartOpts(opt opts.HeatMapChart) SeriesOpts {
372 return func(s *SingleSeries) {
373 s.XAxisIndex = opt.XAxisIndex
374 s.YAxisIndex = opt.YAxisIndex
375 }
376 }
377
378 // WithLineChartOpts sets the LineChart option.
379 func WithLineChartOpts(opt opts.LineChart) SeriesOpts {
380 return func(s *SingleSeries) {
381 s.ColorBy = opt.ColorBy
382 s.CoordSystem = opt.CoordSystem
383 s.XAxisIndex = opt.XAxisIndex
384 s.YAxisIndex = opt.YAxisIndex
385 s.PolarIndex = opt.PolarIndex
386 s.Symbol = opt.Symbol
387 s.SymbolSize = opt.SymbolSize
388 s.SymbolKeepAspect = opt.SymbolKeepAspect
389 s.ShowSymbol = opt.ShowSymbol
390 s.Stack = opt.Stack
391 s.Smooth = opt.Smooth
392 s.ConnectNulls = opt.ConnectNulls
393 s.Step = opt.Step
394 }
395 }
396
397 // WithLineChartOpts sets the LineChart option.
398 func WithKlineChartOpts(opt opts.KlineChart) SeriesOpts {
399 return func(s *SingleSeries) {
400 s.BarWidth = opt.BarWidth
401 s.BarMinWidth = opt.BarMinWidth
402 s.BarMaxWidth = opt.BarMaxWidth
403 }
404 }
405
406 // WithPieChartOpts sets the PieChart option.
407 func WithPieChartOpts(opt opts.PieChart) SeriesOpts {
408 return func(s *SingleSeries) {
409 s.ColorBy = opt.ColorBy
410 s.CoordSystem = opt.CoordSystem
411 s.RoseType = opt.RoseType
412 s.Center = opt.Center
413 s.Radius = opt.Radius
414 s.PadAngle = opt.PadAngle
415 }
416 }
417
418 // WithScatterChartOpts sets the ScatterChart option.
419 func WithScatterChartOpts(opt opts.ScatterChart) SeriesOpts {
420 return func(s *SingleSeries) {
421 s.ColorBy = opt.ColorBy
422 s.CoordSystem = opt.CoordSystem
423 s.XAxisIndex = opt.XAxisIndex
424 s.YAxisIndex = opt.YAxisIndex
425 s.Symbol = opt.Symbol
426 s.SymbolSize = opt.SymbolSize
427 s.SymbolKeepAspect = opt.SymbolKeepAspect
428 }
429 }
430
431 // WithEffectScatterChartOpts sets the ScatterChart option.
432 func WithEffectScatterChartOpts(opt opts.EffectScatterChart) SeriesOpts {
433 return func(s *SingleSeries) {
434 s.ColorBy = opt.ColorBy
435 s.CoordSystem = opt.CoordSystem
436 s.XAxisIndex = opt.XAxisIndex
437 s.YAxisIndex = opt.YAxisIndex
438 s.Symbol = opt.Symbol
439 s.SymbolSize = opt.SymbolSize
440 s.SymbolKeepAspect = opt.SymbolKeepAspect
441 }
442 }
443
444 // WithRadarChartOpts sets the RadarChart option.
445 func WithRadarChartOpts(opt opts.RadarChart) SeriesOpts {
446 return func(s *SingleSeries) {
447 s.ColorBy = opt.ColorBy
448 s.RadarIndex = opt.RadarIndex
449 s.Symbol = opt.Symbol
450 s.SymbolSize = opt.SymbolSize
451 s.SymbolKeepAspect = opt.SymbolKeepAspect
452 }
453 }
454
455 // WithLiquidChartOpts sets the LiquidChart option.
456 func WithLiquidChartOpts(opt opts.LiquidChart) SeriesOpts {
457 return func(s *SingleSeries) {
458 s.Shape = opt.Shape
459 s.IsLiquidOutline = opt.IsShowOutline
460 s.IsWaveAnimation = opt.IsWaveAnimation
461 }
462 }
463
464 // WithBar3DChartOpts sets the Bar3DChart option.
465 func WithBar3DChartOpts(opt opts.Bar3DChart) SeriesOpts {
466 return func(s *SingleSeries) {
467 s.Shading = opt.Shading
468 }
469 }
470
471 // WithTreeOpts sets the TreeChart option.
472 func WithTreeOpts(opt opts.TreeChart) SeriesOpts {
473 return func(s *SingleSeries) {
474 s.Layout = opt.Layout
475 s.Orient = opt.Orient
476 s.ExpandAndCollapse = opt.ExpandAndCollapse
477 s.InitialTreeDepth = opt.InitialTreeDepth
478 s.Roam = opt.Roam
479 s.Label = opt.Label
480 s.Leaves = opt.Leaves
481 s.Right = opt.Right
482 s.Left = opt.Left
483 s.Top = opt.Top
484 s.Bottom = opt.Bottom
485 s.SymbolKeepAspect = opt.SymbolKeepAspect
486 }
487 }
488
489 // WithTreeMapOpts sets the TreeMapChart options.
490 func WithTreeMapOpts(opt opts.TreeMapChart) SeriesOpts {
491 return func(s *SingleSeries) {
492 s.Animation = opt.Animation
493 s.LeafDepth = opt.LeafDepth
494 s.Roam = opt.Roam
495 s.Levels = opt.Levels
496 s.UpperLabel = opt.UpperLabel
497 s.Right = opt.Right
498 s.Left = opt.Left
499 s.Top = opt.Top
500 s.Bottom = opt.Bottom
501 }
502 }
503
504 // WithWorldCloudChartOpts sets the WorldCloudChart option.
505 func WithWorldCloudChartOpts(opt opts.WordCloudChart) SeriesOpts {
506 return func(s *SingleSeries) {
507 s.Shape = opt.Shape
508 s.SizeRange = opt.SizeRange
509 s.RotationRange = opt.RotationRange
510 }
511 }
512
513 // WithMarkLineNameTypeItemOpts sets the type of the MarkLine.
514 func WithMarkLineNameTypeItemOpts(opt ...opts.MarkLineNameTypeItem) SeriesOpts {
515 return func(s *SingleSeries) {
516 if s.MarkLines == nil {
517 s.MarkLines = &opts.MarkLines{}
518 }
519 for _, o := range opt {
520 s.MarkLines.Data = append(s.MarkLines.Data, o)
521 }
522 }
523 }
524
525 // WithMarkLineStyleOpts sets the style of the MarkLine.
526 func WithMarkLineStyleOpts(opt opts.MarkLineStyle) SeriesOpts {
527 return func(s *SingleSeries) {
528 if s.MarkLines == nil {
529 s.MarkLines = &opts.MarkLines{}
530 }
531
532 s.MarkLines.MarkLineStyle = opt
533 }
534 }
535
536 // WithMarkLineNameCoordItemOpts sets the coordinates of the MarkLine.
537 func WithMarkLineNameCoordItemOpts(opt ...opts.MarkLineNameCoordItem) SeriesOpts {
538 type MLNameCoord struct {
539 Name string `json:"name,omitempty"`
540 Coord []interface{} `json:"coord"`
541 }
542 return func(s *SingleSeries) {
543 if s.MarkLines == nil {
544 s.MarkLines = &opts.MarkLines{}
545 }
546 for _, o := range opt {
547 s.MarkLines.Data = append(
548 s.MarkLines.Data,
549 []MLNameCoord{{Name: o.Name, Coord: o.Coordinate0}, {Coord: o.Coordinate1}},
550 )
551 }
552 }
553 }
554
555 // WithMarkLineNameXAxisItemOpts sets the X axis of the MarkLine.
556 func WithMarkLineNameXAxisItemOpts(opt ...opts.MarkLineNameXAxisItem) SeriesOpts {
557 return func(s *SingleSeries) {
558 if s.MarkLines == nil {
559 s.MarkLines = &opts.MarkLines{}
560 }
561 for _, o := range opt {
562 s.MarkLines.Data = append(s.MarkLines.Data, o)
563 }
564 }
565 }
566
567 // WithMarkLineNameYAxisItemOpts sets the Y axis of the MarkLine.
568 func WithMarkLineNameYAxisItemOpts(opt ...opts.MarkLineNameYAxisItem) SeriesOpts {
569 return func(s *SingleSeries) {
570 if s.MarkLines == nil {
571 s.MarkLines = &opts.MarkLines{}
572 }
573 for _, o := range opt {
574 s.MarkLines.Data = append(s.MarkLines.Data, o)
575 }
576 }
577 }
578
579 // WithMarkAreaNameTypeItemOpts sets the type of the MarkArea.
580 func WithMarkAreaNameTypeItemOpts(opt ...opts.MarkAreaNameTypeItem) SeriesOpts {
581 return func(s *SingleSeries) {
582 if s.MarkAreas == nil {
583 s.MarkAreas = &opts.MarkAreas{}
584 }
585 for _, o := range opt {
586 s.MarkAreas.Data = append(s.MarkAreas.Data, o)
587 }
588 }
589 }
590
591 // WithMarkAreaStyleOpts sets the style of the MarkArea.
592 func WithMarkAreaStyleOpts(opt opts.MarkAreaStyle) SeriesOpts {
593 return func(s *SingleSeries) {
594 if s.MarkAreas == nil {
595 s.MarkAreas = &opts.MarkAreas{}
596 }
597
598 s.MarkAreas.MarkAreaStyle = opt
599 }
600 }
601
602 // WithMarkAreaNameCoordItemOpts sets the coordinates of the MarkLine.
603 func WithMarkAreaNameCoordItemOpts(opt ...opts.MarkAreaNameCoordItem) SeriesOpts {
604 type MANameCoord struct {
605 Name string `json:"name,omitempty"`
606 ItemStyle *opts.ItemStyle `json:"itemStyle"`
607 Coord []interface{} `json:"coord"`
608 }
609 return func(s *SingleSeries) {
610 if s.MarkAreas == nil {
611 s.MarkAreas = &opts.MarkAreas{}
612 }
613 for _, o := range opt {
614 s.MarkAreas.Data = append(
615 s.MarkAreas.Data,
616 []MANameCoord{
617 {Name: o.Name, ItemStyle: o.ItemStyle, Coord: o.Coordinate0},
618 {Coord: o.Coordinate1},
619 },
620 )
621 }
622 }
623 }
624
625 // WithMarkAreaData0 sets the markArea.data.0
626 func WithMarkAreaData0(data0 opts.MarkAreaData0) SeriesOpts {
627 return func(s *SingleSeries) {
628 if s.MarkAreas == nil {
629 s.MarkAreas = &opts.MarkAreas{}
630 }
631 s.MarkAreas.Data = append(s.MarkAreas.Data, data0)
632 }
633 }
634
635 // WithMarkAreaData1 sets the markArea.data.1
636 func WithMarkAreaData1(data1 opts.MarkAreaData1) SeriesOpts {
637 return func(s *SingleSeries) {
638 if s.MarkAreas == nil {
639 s.MarkAreas = &opts.MarkAreas{}
640 }
641 s.MarkAreas.Data = append(s.MarkAreas.Data, data1)
642 }
643 }
644
645 // WithMarkAreaData sets the markArea.data each item as array
646 // See https://echarts.apache.org/en/option.html#series-candlestick.markArea.data
647 func WithMarkAreaData(datas ...[]opts.MarkAreaData) SeriesOpts {
648 return func(s *SingleSeries) {
649 if s.MarkAreas == nil {
650 s.MarkAreas = &opts.MarkAreas{}
651 }
652 for _, d := range datas {
653 s.MarkAreas.Data = append(s.MarkAreas.Data, d)
654 }
655 }
656 }
657
658 // WithMarkAreaNameXAxisItemOpts sets the X axis of the MarkLine.
659 func WithMarkAreaNameXAxisItemOpts(opt ...opts.MarkAreaNameXAxisItem) SeriesOpts {
660 return func(s *SingleSeries) {
661 if s.MarkAreas == nil {
662 s.MarkAreas = &opts.MarkAreas{}
663 }
664 for _, o := range opt {
665 s.MarkAreas.Data = append(s.MarkAreas.Data, o)
666 }
667 }
668 }
669
670 // WithMarkAreaNameYAxisItemOpts sets the Y axis of the MarkLine.
671 func WithMarkAreaNameYAxisItemOpts(opt ...opts.MarkAreaNameYAxisItem) SeriesOpts {
672 return func(s *SingleSeries) {
673 if s.MarkAreas == nil {
674 s.MarkAreas = &opts.MarkAreas{}
675 }
676 for _, o := range opt {
677 s.MarkAreas.Data = append(s.MarkAreas.Data, o)
678 }
679 }
680 }
681
682 // WithMarkPointNameTypeItemOpts sets the type of the MarkPoint.
683 func WithMarkPointNameTypeItemOpts(opt ...opts.MarkPointNameTypeItem) SeriesOpts {
684 return func(s *SingleSeries) {
685 if s.MarkPoints == nil {
686 s.MarkPoints = &opts.MarkPoints{}
687 }
688 for _, o := range opt {
689 s.MarkPoints.Data = append(s.MarkPoints.Data, o)
690 }
691 }
692 }
693
694 // WithMarkPointStyleOpts sets the style of the MarkPoint.
695 func WithMarkPointStyleOpts(opt opts.MarkPointStyle) SeriesOpts {
696 return func(s *SingleSeries) {
697 if s.MarkPoints == nil {
698 s.MarkPoints = &opts.MarkPoints{}
699 }
700
701 s.MarkPoints.MarkPointStyle = opt
702 }
703 }
704
705 // WithMarkPointNameCoordItemOpts sets the coordinated of the MarkPoint.
706 func WithMarkPointNameCoordItemOpts(opt ...opts.MarkPointNameCoordItem) SeriesOpts {
707 return func(s *SingleSeries) {
708 if s.MarkPoints == nil {
709 s.MarkPoints = &opts.MarkPoints{}
710 }
711 for _, o := range opt {
712 s.MarkPoints.Data = append(s.MarkPoints.Data, o)
713 }
714 }
715 }
716
717 func (s *SingleSeries) InitSeriesDefaultOpts(c BaseConfiguration) {
718 util.SetDefaultValue(s)
719 // some special inherited options from BaseConfiguration
720 s.Animation = c.Animation
721 }
722
723 func (s *SingleSeries) ConfigureSeriesOpts(options ...SeriesOpts) {
724 for _, opt := range options {
725 opt(s)
726 }
727 }
728
729 // MultiSeries represents multiple series.
730 type MultiSeries []SingleSeries
731
732 // SetSeriesOptions sets options for all the series.
733 // NOTE:
734 // It should be called after AddSeries, otherwise, the Options is no place to add on.
735 // Previous options will be overwritten every time hence setting them on the `AddSeries` if you want
736 // to customize each series individually
737 //
738 // here -> ↓ <-
739 //
740 // func (c *Bar) AddSeries(name string, data []opts.BarData, options ...SeriesOpts)
741 func (ms *MultiSeries) SetSeriesOptions(opts ...SeriesOpts) {
742 s := *ms
743 for i := 0; i < len(s); i++ {
744 s[i].ConfigureSeriesOpts(opts...)
745 }
746 }
747
748 // WithEncodeOpts Set encodes for dataSets
749 func WithEncodeOpts(opt opts.Encode) SeriesOpts {
750 return func(s *SingleSeries) {
751 s.Encode = &opt
752 }
753 }
754
755 // WithDatasetIndex sets the datasetIndex option.
756 func WithDatasetIndex(index int) SeriesOpts {
757 return func(s *SingleSeries) {
758 s.DatasetIndex = index
759 }
760 }
761
762 // WithCustomChartOpts sets the CustomChart option.
763 func WithCustomChartOpts(opt opts.CustomChart) SeriesOpts {
764 return func(s *SingleSeries) {
765 s.XAxisIndex = opt.XAxisIndex
766 s.YAxisIndex = opt.YAxisIndex
767 s.RenderItem = opt.RenderItem
768 }
769 }