Skip to main content

euv_chart/option/
impl.rs

1use super::*;
2
3/// Inherent implementation of [`DataValue`].
4impl DataValue {
5    /// Returns the numeric value, when the value is a number.
6    ///
7    /// # Returns
8    ///
9    /// - `Option<f64>` - `Some(...)` on success, `None` otherwise.
10    pub fn as_number(&self) -> Option<f64> {
11        match self {
12            DataValue::Number(value) => Some(*value),
13            _ => None,
14        }
15    }
16
17    /// Returns the numeric value, parsing a text value when needed.
18    ///
19    /// # Returns
20    ///
21    /// - `Option<f64>` - `Some(...)` on success, `None` otherwise.
22    pub fn to_number(&self) -> Option<f64> {
23        match self {
24            DataValue::Number(value) => Some(*value),
25            DataValue::Text(text) => text.trim().parse::<f64>().ok(),
26            DataValue::Bool(value) => Some(if *value { 1.0 } else { 0.0 }),
27            _ => None,
28        }
29    }
30
31    /// Returns the text value, when the value is text.
32    ///
33    /// # Returns
34    ///
35    /// - `Option<&str>` - `Some(...)` on success, `None` otherwise.
36    pub fn as_text(&self) -> Option<&str> {
37        match self {
38            DataValue::Text(text) => Some(text.as_str()),
39            _ => None,
40        }
41    }
42
43    /// Returns the list value, when the value is a list.
44    ///
45    /// # Returns
46    ///
47    /// - `Option<&[DataValue]>` - `Some(...)` on success, `None` otherwise.
48    pub fn as_list(&self) -> Option<&[DataValue]> {
49        match self {
50            DataValue::List(values) => Some(values.as_slice()),
51            _ => None,
52        }
53    }
54
55    /// Returns the object value, when the value is an object.
56    ///
57    /// # Returns
58    ///
59    /// - `Option<&[(String, DataValue)]>` - `Some(...)` on success, `None` otherwise.
60    pub fn as_object(&self) -> Option<&[(String, DataValue)]> {
61        match self {
62            DataValue::Object(fields) => Some(fields.as_slice()),
63            _ => None,
64        }
65    }
66
67    /// Looks up a named field of an object value.
68    ///
69    /// # Arguments
70    ///
71    /// - `&str` - Shared reference to a `str`.
72    ///
73    /// # Returns
74    ///
75    /// - `Option<&DataValue>` - `Some(...)` on success, `None` otherwise.
76    pub fn get(&self, name: &str) -> Option<&DataValue> {
77        self.as_object()?
78            .iter()
79            .find(|(key, _): &&(String, DataValue)| key == name)
80            .map(|(_, value): &(String, DataValue)| value)
81    }
82
83    /// Looks up a named field of an object value, mutably.
84    ///
85    /// # Arguments
86    ///
87    /// - `&str` - Shared reference to a `str`.
88    ///
89    /// # Returns
90    ///
91    /// - `Option<&mut DataValue>` - `Some(...)` on success, `None` otherwise.
92    pub fn get_mut(&mut self, name: &str) -> Option<&mut DataValue> {
93        self.as_object_mut()?
94            .iter_mut()
95            .find(|(key, _): &&mut (String, DataValue)| key == name)
96            .map(|(_, value): &mut (String, DataValue)| value)
97    }
98
99    /// Returns the object value, mutably, when the value is an object.
100    ///
101    /// # Returns
102    ///
103    /// - `Option<&mut [(String, DataValue)]>` - `Some(...)` on success, `None` otherwise.
104    pub fn as_object_mut(&mut self) -> Option<&mut [(String, DataValue)]> {
105        match self {
106            DataValue::Object(fields) => Some(fields.as_mut_slice()),
107            _ => None,
108        }
109    }
110
111    /// Returns `true` when the value carries no data.
112    ///
113    /// # Returns
114    ///
115    /// - `bool` - A boolean.
116    pub fn is_null(&self) -> bool {
117        matches!(self, DataValue::Null)
118    }
119}
120
121/// `From` conversion into [`DataValue`].
122impl From<f64> for DataValue {
123    /// Converts a `f64` into [`DataValue`].
124    ///
125    /// # Arguments
126    ///
127    /// - `f64` - Input value to convert from.
128    fn from(value: f64) -> Self {
129        DataValue::Number(value)
130    }
131}
132
133/// `From` conversion into [`DataValue`].
134impl From<i32> for DataValue {
135    /// Converts a `i32` into [`DataValue`].
136    ///
137    /// # Arguments
138    ///
139    /// - `i32` - Input value to convert from.
140    fn from(value: i32) -> Self {
141        DataValue::Number(value as f64)
142    }
143}
144
145/// `From` conversion into [`DataValue`].
146impl From<bool> for DataValue {
147    /// Converts a `bool` into [`DataValue`].
148    ///
149    /// # Arguments
150    ///
151    /// - `bool` - Input value to convert from.
152    fn from(value: bool) -> Self {
153        DataValue::Bool(value)
154    }
155}
156
157/// `From` conversion into [`DataValue`].
158impl From<&str> for DataValue {
159    /// Converts a `&str` into [`DataValue`].
160    ///
161    /// # Arguments
162    ///
163    /// - `&str` - Input value to convert from.
164    fn from(value: &str) -> Self {
165        DataValue::Text(value.to_string())
166    }
167}
168
169/// `From` conversion into [`DataValue`].
170impl From<String> for DataValue {
171    /// Converts a `String` into [`DataValue`].
172    ///
173    /// # Arguments
174    ///
175    /// - `String` - Input value to convert from.
176    fn from(value: String) -> Self {
177        DataValue::Text(value)
178    }
179}
180
181/// `From` conversion into [`DataValue`].
182impl From<Vec<DataValue>> for DataValue {
183    /// Lifts a `Vec<DataValue>` into [`DataValue`].
184    ///
185    /// # Arguments
186    ///
187    /// - `Vec<DataValue>` - Input value to convert from.
188    fn from(value: Vec<DataValue>) -> Self {
189        DataValue::List(value)
190    }
191}
192
193/// Inherent implementation of [`SeriesType`].
194impl SeriesType {
195    /// Returns the ECharts name of the series type.
196    ///
197    /// # Returns
198    ///
199    /// - `&'static str` - A `'static str` value.
200    pub fn name(&self) -> &'static str {
201        match self {
202            SeriesType::Line => SERIES_TYPE_LINE,
203            SeriesType::Bar => SERIES_TYPE_BAR,
204            SeriesType::Pie => SERIES_TYPE_PIE,
205            SeriesType::Scatter => SERIES_TYPE_SCATTER,
206            SeriesType::EffectScatter => SERIES_TYPE_EFFECT_SCATTER,
207            SeriesType::Radar => SERIES_TYPE_RADAR,
208            SeriesType::Gauge => SERIES_TYPE_GAUGE,
209            SeriesType::Funnel => SERIES_TYPE_FUNNEL,
210            SeriesType::Heatmap => SERIES_TYPE_HEATMAP,
211            SeriesType::Graph => SERIES_TYPE_GRAPH,
212            SeriesType::Treemap => SERIES_TYPE_TREEMAP,
213            SeriesType::Sunburst => SERIES_TYPE_SUNBURST,
214            SeriesType::Boxplot => SERIES_TYPE_BOXPLOT,
215            SeriesType::Candlestick => SERIES_TYPE_CANDLESTICK,
216            SeriesType::ThemeRiver => SERIES_TYPE_THEME_RIVER,
217            SeriesType::Sankey => SERIES_TYPE_SANKEY,
218            SeriesType::Parallel => SERIES_TYPE_PARALLEL,
219            SeriesType::PictorialBar => SERIES_TYPE_PICTORIAL_BAR,
220            SeriesType::Lines => SERIES_TYPE_LINES,
221            SeriesType::Map => SERIES_TYPE_MAP,
222            SeriesType::Custom => SERIES_TYPE_CUSTOM,
223        }
224    }
225
226    /// Parses an ECharts series type name.
227    ///
228    /// # Arguments
229    ///
230    /// - `&str` - Shared reference to a `str`.
231    ///
232    /// # Returns
233    ///
234    /// - `Option<Self>` - `Some(...)` on success, `None` otherwise.
235    pub fn parse(name: &str) -> Option<Self> {
236        Some(match name {
237            SERIES_TYPE_LINE => SeriesType::Line,
238            SERIES_TYPE_BAR => SeriesType::Bar,
239            SERIES_TYPE_PIE => SeriesType::Pie,
240            SERIES_TYPE_SCATTER => SeriesType::Scatter,
241            SERIES_TYPE_EFFECT_SCATTER => SeriesType::EffectScatter,
242            SERIES_TYPE_RADAR => SeriesType::Radar,
243            SERIES_TYPE_GAUGE => SeriesType::Gauge,
244            SERIES_TYPE_FUNNEL => SeriesType::Funnel,
245            SERIES_TYPE_HEATMAP => SeriesType::Heatmap,
246            SERIES_TYPE_GRAPH => SeriesType::Graph,
247            SERIES_TYPE_TREEMAP => SeriesType::Treemap,
248            SERIES_TYPE_SUNBURST => SeriesType::Sunburst,
249            SERIES_TYPE_BOXPLOT => SeriesType::Boxplot,
250            SERIES_TYPE_CANDLESTICK => SeriesType::Candlestick,
251            SERIES_TYPE_THEME_RIVER => SeriesType::ThemeRiver,
252            SERIES_TYPE_SANKEY => SeriesType::Sankey,
253            SERIES_TYPE_PARALLEL => SeriesType::Parallel,
254            SERIES_TYPE_PICTORIAL_BAR => SeriesType::PictorialBar,
255            SERIES_TYPE_LINES => SeriesType::Lines,
256            SERIES_TYPE_MAP => SeriesType::Map,
257            SERIES_TYPE_CUSTOM => SeriesType::Custom,
258            _ => return None,
259        })
260    }
261}
262
263/// Inherent implementation of [`ChartOption`].
264impl ChartOption {
265    /// Returns an empty configuration.
266    pub fn new() -> Self {
267        Self {
268            animation: true,
269            ..Self::default()
270        }
271    }
272
273    /// Sets the title.
274    ///
275    /// # Arguments
276    ///
277    /// - `TitleOption` - A `TitleOption` parameter.
278    pub fn title(mut self, title: TitleOption) -> Self {
279        self.set_title(Some(title));
280        self
281    }
282
283    /// Sets the legend.
284    ///
285    /// # Arguments
286    ///
287    /// - `LegendOption` - A `LegendOption` parameter.
288    pub fn legend(mut self, legend: LegendOption) -> Self {
289        self.set_legend(Some(legend));
290        self
291    }
292
293    /// Sets the cartesian grid.
294    ///
295    /// # Arguments
296    ///
297    /// - `GridOption` - A `GridOption` parameter.
298    pub fn grid(mut self, grid: GridOption) -> Self {
299        self.set_grid(Some(grid));
300        self
301    }
302
303    /// Adds an x-axis.
304    ///
305    /// # Arguments
306    ///
307    /// - `AxisOption` - A `AxisOption` parameter.
308    pub fn x_axis(mut self, axis: AxisOption) -> Self {
309        self.get_mut_x_axis().push(axis);
310        self
311    }
312
313    /// Adds a y-axis.
314    ///
315    /// # Arguments
316    ///
317    /// - `AxisOption` - A `AxisOption` parameter.
318    pub fn y_axis(mut self, axis: AxisOption) -> Self {
319        self.get_mut_y_axis().push(axis);
320        self
321    }
322
323    /// Adds a polar coordinate system.
324    ///
325    /// # Arguments
326    ///
327    /// - `PolarOption` - A `PolarOption` parameter.
328    pub fn polar(mut self, polar: PolarOption) -> Self {
329        self.get_mut_polar().push(polar);
330        self
331    }
332
333    /// Adds a radar coordinate system.
334    ///
335    /// # Arguments
336    ///
337    /// - `RadarOption` - A `RadarOption` parameter.
338    pub fn radar(mut self, radar: RadarOption) -> Self {
339        self.get_mut_radar().push(radar);
340        self
341    }
342
343    /// Adds a geo component.
344    ///
345    /// # Arguments
346    ///
347    /// - `GeoOption` - A `GeoOption` parameter.
348    pub fn geo(mut self, geo: GeoOption) -> Self {
349        self.get_mut_geo().push(geo);
350        self
351    }
352
353    /// Adds a calendar component.
354    ///
355    /// # Arguments
356    ///
357    /// - `CalendarOption` - A `CalendarOption` parameter.
358    pub fn calendar(mut self, calendar: CalendarOption) -> Self {
359        self.get_mut_calendar().push(calendar);
360        self
361    }
362
363    /// Sets the dataset.
364    ///
365    /// # Arguments
366    ///
367    /// - `DatasetOption` - A `DatasetOption` parameter.
368    pub fn dataset(mut self, dataset: DatasetOption) -> Self {
369        self.set_dataset(Some(dataset));
370        self
371    }
372
373    /// Adds a series.
374    ///
375    /// # Arguments
376    ///
377    /// - `SeriesOption` - A `SeriesOption` parameter.
378    pub fn series(mut self, series: SeriesOption) -> Self {
379        self.get_mut_series().push(series);
380        self
381    }
382
383    /// Sets the tooltip.
384    ///
385    /// # Arguments
386    ///
387    /// - `TooltipOption` - A `TooltipOption` parameter.
388    pub fn tooltip(mut self, tooltip: TooltipOption) -> Self {
389        self.set_tooltip(Some(tooltip));
390        self
391    }
392
393    /// Sets the toolbox.
394    ///
395    /// # Arguments
396    ///
397    /// - `ToolboxOption` - A `ToolboxOption` parameter.
398    pub fn toolbox(mut self, toolbox: ToolboxOption) -> Self {
399        self.set_toolbox(Some(toolbox));
400        self
401    }
402
403    /// Adds a data-zoom control.
404    ///
405    /// # Arguments
406    ///
407    /// - `DataZoomOption` - A `DataZoomOption` parameter.
408    pub fn data_zoom(mut self, data_zoom: DataZoomOption) -> Self {
409        self.get_mut_data_zoom().push(data_zoom);
410        self
411    }
412
413    /// Adds a visual map.
414    ///
415    /// # Arguments
416    ///
417    /// - `VisualMapOption` - A `VisualMapOption` parameter.
418    pub fn visual_map(mut self, visual_map: VisualMapOption) -> Self {
419        self.get_mut_visual_map().push(visual_map);
420        self
421    }
422
423    /// Adds a graphic element.
424    ///
425    /// # Arguments
426    ///
427    /// - `GraphicOption` - A `GraphicOption` parameter.
428    pub fn graphic(mut self, graphic: GraphicOption) -> Self {
429        self.get_mut_graphic().push(graphic);
430        self
431    }
432
433    /// Sets the brush.
434    ///
435    /// # Arguments
436    ///
437    /// - `BrushOption` - A `BrushOption` parameter.
438    pub fn brush(mut self, brush: BrushOption) -> Self {
439        self.set_brush(Some(brush));
440        self
441    }
442
443    /// Sets the axis pointer.
444    ///
445    /// # Arguments
446    ///
447    /// - `AxisPointerOption` - A `AxisPointerOption` parameter.
448    pub fn axis_pointer(mut self, axis_pointer: AxisPointerOption) -> Self {
449        self.set_axis_pointer(Some(axis_pointer));
450        self
451    }
452
453    /// Sets the palette the series take their colours from.
454    ///
455    /// # Arguments
456    ///
457    /// - `Vec<String>` - A `Vec<String>` parameter.
458    pub fn color(mut self, color: Vec<String>) -> Self {
459        self.set_color(color);
460        self
461    }
462
463    /// Adds one colour to the palette.
464    ///
465    /// # Arguments
466    ///
467    /// - `&str` - Shared reference to a `str`.
468    pub fn add_color(mut self, color: &str) -> Self {
469        self.get_mut_color().push(color.to_string());
470        self
471    }
472
473    /// Sets the background colour of the chart.
474    ///
475    /// # Arguments
476    ///
477    /// - `&str` - Shared reference to a `str`.
478    pub fn background_color(mut self, color: &str) -> Self {
479        self.set_background_color(Some(color.to_string()));
480        self
481    }
482
483    /// Sets the default text style of the chart.
484    ///
485    /// # Arguments
486    ///
487    /// - `LabelOption` - A `LabelOption` parameter.
488    pub fn text_style(mut self, text_style: LabelOption) -> Self {
489        self.set_text_style(Some(text_style));
490        self
491    }
492
493    /// Sets whether the chart animates.
494    ///
495    /// # Arguments
496    ///
497    /// - `bool` - A boolean (`bool`).
498    pub fn animation(mut self, animation: bool) -> Self {
499        self.set_animation(animation);
500        self
501    }
502
503    /// Sets the duration of the chart's animation, in milliseconds.
504    ///
505    /// # Arguments
506    ///
507    /// - `f64` - A 64-bit float (`f64`).
508    pub fn animation_duration(mut self, duration: f64) -> Self {
509        self.set_animation_duration(Some(duration));
510        self
511    }
512}
513
514/// Inherent implementation of [`SeriesOption`].
515impl SeriesOption {
516    /// Returns a line series.
517    pub fn line() -> Self {
518        Self {
519            kind: SeriesType::Line,
520            show: true,
521            ..Self::default()
522        }
523    }
524
525    /// Returns a bar series.
526    pub fn bar() -> Self {
527        Self {
528            kind: SeriesType::Bar,
529            show: true,
530            ..Self::default()
531        }
532    }
533
534    /// Returns a pie series.
535    pub fn pie() -> Self {
536        Self {
537            kind: SeriesType::Pie,
538            show: true,
539            ..Self::default()
540        }
541    }
542
543    /// Returns a scatter series.
544    pub fn scatter() -> Self {
545        Self {
546            kind: SeriesType::Scatter,
547            show: true,
548            ..Self::default()
549        }
550    }
551
552    /// Returns an effect-scatter series.
553    pub fn effect_scatter() -> Self {
554        Self {
555            kind: SeriesType::EffectScatter,
556            show: true,
557            ..Self::default()
558        }
559    }
560
561    /// Returns a radar series.
562    pub fn radar() -> Self {
563        Self {
564            kind: SeriesType::Radar,
565            show: true,
566            ..Self::default()
567        }
568    }
569
570    /// Returns a gauge series.
571    pub fn gauge() -> Self {
572        Self {
573            kind: SeriesType::Gauge,
574            show: true,
575            ..Self::default()
576        }
577    }
578
579    /// Returns a funnel series.
580    pub fn funnel() -> Self {
581        Self {
582            kind: SeriesType::Funnel,
583            show: true,
584            ..Self::default()
585        }
586    }
587
588    /// Returns a heatmap series.
589    pub fn heatmap() -> Self {
590        Self {
591            kind: SeriesType::Heatmap,
592            show: true,
593            ..Self::default()
594        }
595    }
596
597    /// Returns a graph series.
598    pub fn graph() -> Self {
599        Self {
600            kind: SeriesType::Graph,
601            show: true,
602            ..Self::default()
603        }
604    }
605
606    /// Returns a treemap series.
607    pub fn treemap() -> Self {
608        Self {
609            kind: SeriesType::Treemap,
610            show: true,
611            ..Self::default()
612        }
613    }
614
615    /// Returns a sunburst series.
616    pub fn sunburst() -> Self {
617        Self {
618            kind: SeriesType::Sunburst,
619            show: true,
620            ..Self::default()
621        }
622    }
623
624    /// Returns a boxplot series.
625    pub fn boxplot() -> Self {
626        Self {
627            kind: SeriesType::Boxplot,
628            show: true,
629            ..Self::default()
630        }
631    }
632
633    /// Returns a candlestick series.
634    pub fn candlestick() -> Self {
635        Self {
636            kind: SeriesType::Candlestick,
637            show: true,
638            ..Self::default()
639        }
640    }
641
642    /// Returns a theme-river series.
643    pub fn theme_river() -> Self {
644        Self {
645            kind: SeriesType::ThemeRiver,
646            show: true,
647            ..Self::default()
648        }
649    }
650
651    /// Returns a sankey series.
652    pub fn sankey() -> Self {
653        Self {
654            kind: SeriesType::Sankey,
655            show: true,
656            ..Self::default()
657        }
658    }
659
660    /// Returns a parallel-coordinates series.
661    pub fn parallel() -> Self {
662        Self {
663            kind: SeriesType::Parallel,
664            show: true,
665            ..Self::default()
666        }
667    }
668
669    /// Returns a pictorial-bar series.
670    pub fn pictorial_bar() -> Self {
671        Self {
672            kind: SeriesType::PictorialBar,
673            show: true,
674            ..Self::default()
675        }
676    }
677
678    /// Returns a lines series.
679    pub fn lines() -> Self {
680        Self {
681            kind: SeriesType::Lines,
682            show: true,
683            ..Self::default()
684        }
685    }
686
687    /// Returns a map series.
688    pub fn map() -> Self {
689        Self {
690            kind: SeriesType::Map,
691            show: true,
692            ..Self::default()
693        }
694    }
695
696    /// Returns a custom series.
697    pub fn custom() -> Self {
698        Self {
699            kind: SeriesType::Custom,
700            show: true,
701            ..Self::default()
702        }
703    }
704
705    /// Sets the name of the series.
706    ///
707    /// # Arguments
708    ///
709    /// - `&str` - Shared reference to a `str`.
710    pub fn name(mut self, name: &str) -> Self {
711        self.set_name(name.to_string());
712        self
713    }
714
715    /// Sets the data of the series.
716    ///
717    /// # Arguments
718    ///
719    /// - `Vec<DataValue>` - A `Vec<DataValue>` parameter.
720    pub fn data(mut self, data: Vec<DataValue>) -> Self {
721        self.set_data(data);
722        self
723    }
724
725    /// Adds one data point to the series.
726    ///
727    /// The method borrows the series instead of consuming it, so that a
728    /// long series can be built in a loop without moving the data
729    /// around on every step.
730    ///
731    /// # Arguments
732    ///
733    /// - `DataValue` - A `DataValue` parameter.
734    ///
735    /// # Returns
736    ///
737    /// - `&mut Self` - A `mut Self` value.
738    pub fn add_data(&mut self, value: DataValue) -> &mut Self {
739        self.get_mut_data().push(value);
740        self
741    }
742
743    /// Sets the stack the series is stacked in.
744    ///
745    /// # Arguments
746    ///
747    /// - `&str` - Shared reference to a `str`.
748    pub fn stack(mut self, stack: &str) -> Self {
749        self.set_stack(Some(stack.to_string()));
750        self
751    }
752
753    /// Binds the series to an x-axis.
754    ///
755    /// # Arguments
756    ///
757    /// - `usize` - A non-negative integer (`usize`).
758    pub fn x_axis_index(mut self, index: usize) -> Self {
759        self.set_x_axis_index(Some(index));
760        self
761    }
762
763    /// Binds the series to a y-axis.
764    ///
765    /// # Arguments
766    ///
767    /// - `usize` - A non-negative integer (`usize`).
768    pub fn y_axis_index(mut self, index: usize) -> Self {
769        self.set_y_axis_index(Some(index));
770        self
771    }
772
773    /// Sets the fill of the series' shapes.
774    ///
775    /// # Arguments
776    ///
777    /// - `ItemStyleOption` - A `ItemStyleOption` parameter.
778    pub fn item_style(mut self, item_style: ItemStyleOption) -> Self {
779        self.set_item_style(Some(item_style));
780        self
781    }
782
783    /// Sets the stroke of the series' shapes.
784    ///
785    /// # Arguments
786    ///
787    /// - `LineStyleOption` - A `LineStyleOption` parameter.
788    pub fn line_style(mut self, line_style: LineStyleOption) -> Self {
789        self.set_line_style(Some(line_style));
790        self
791    }
792
793    /// Sets the label of the series' data points.
794    ///
795    /// # Arguments
796    ///
797    /// - `LabelOption` - A `LabelOption` parameter.
798    pub fn label(mut self, label: LabelOption) -> Self {
799        self.set_label(Some(label));
800        self
801    }
802
803    /// Sets the style applied when a data point is highlighted.
804    ///
805    /// # Arguments
806    ///
807    /// - `EmphasisOption` - A `EmphasisOption` parameter.
808    pub fn emphasis(mut self, emphasis: EmphasisOption) -> Self {
809        self.set_emphasis(Some(emphasis));
810        self
811    }
812
813    /// Sets the options specific to a bar series.
814    ///
815    /// # Arguments
816    ///
817    /// - `BarOptions` - A `BarOptions` parameter.
818    pub fn bar_options(mut self, options: BarOptions) -> Self {
819        self.set_bar(Some(options));
820        self
821    }
822
823    /// Sets the options specific to a line series.
824    ///
825    /// # Arguments
826    ///
827    /// - `LineOptions` - A `LineOptions` parameter.
828    pub fn line_options(mut self, options: LineOptions) -> Self {
829        self.set_line(Some(options));
830        self
831    }
832
833    /// Sets the options specific to a pie series.
834    ///
835    /// # Arguments
836    ///
837    /// - `PieOptions` - A `PieOptions` parameter.
838    pub fn pie_options(mut self, options: PieOptions) -> Self {
839        self.set_pie(Some(options));
840        self
841    }
842
843    /// Sets the options specific to a scatter series.
844    ///
845    /// # Arguments
846    ///
847    /// - `ScatterOptions` - A `ScatterOptions` parameter.
848    pub fn scatter_options(mut self, options: ScatterOptions) -> Self {
849        self.set_scatter(Some(options));
850        self
851    }
852
853    /// Sets the options specific to a radar series.
854    ///
855    /// # Arguments
856    ///
857    /// - `RadarOptions` - A `RadarOptions` parameter.
858    pub fn radar_options(mut self, options: RadarOptions) -> Self {
859        self.set_radar(Some(options));
860        self
861    }
862
863    /// Sets the options specific to a gauge series.
864    ///
865    /// # Arguments
866    ///
867    /// - `GaugeOptions` - A `GaugeOptions` parameter.
868    pub fn gauge_options(mut self, options: GaugeOptions) -> Self {
869        self.set_gauge(Some(options));
870        self
871    }
872
873    /// Sets the options specific to a funnel series.
874    ///
875    /// # Arguments
876    ///
877    /// - `FunnelOptions` - A `FunnelOptions` parameter.
878    pub fn funnel_options(mut self, options: FunnelOptions) -> Self {
879        self.set_funnel(Some(options));
880        self
881    }
882
883    /// Sets the options specific to a heatmap series.
884    ///
885    /// # Arguments
886    ///
887    /// - `HeatmapOptions` - A `HeatmapOptions` parameter.
888    pub fn heatmap_options(mut self, options: HeatmapOptions) -> Self {
889        self.set_heatmap(Some(options));
890        self
891    }
892
893    /// Returns `true` when the series draws a line between its points.
894    ///
895    /// # Returns
896    ///
897    /// - `bool` - A boolean.
898    pub fn is_line_like(&self) -> bool {
899        matches!(
900            self.get_kind(),
901            SeriesType::Line | SeriesType::EffectScatter | SeriesType::ThemeRiver
902        )
903    }
904
905    /// Returns `true` when the series draws an area under its points.
906    ///
907    /// # Returns
908    ///
909    /// - `bool` - A boolean.
910    pub fn has_area(&self) -> bool {
911        self.get_line()
912            .as_ref()
913            .and_then(|line: &LineOptions| line.area_style.as_ref())
914            .is_some()
915    }
916}
917
918/// Inherent implementation of [`AxisOption`].
919impl AxisOption {
920    /// Returns a category axis.
921    pub fn category() -> Self {
922        Self {
923            axis_type: AxisType::Category,
924            show: true,
925            ..Self::default()
926        }
927    }
928
929    /// Returns a value axis.
930    pub fn value() -> Self {
931        Self {
932            axis_type: AxisType::Value,
933            show: true,
934            ..Self::default()
935        }
936    }
937
938    /// Returns a time axis.
939    pub fn time() -> Self {
940        Self {
941            axis_type: AxisType::Time,
942            show: true,
943            ..Self::default()
944        }
945    }
946
947    /// Returns a logarithmic axis.
948    pub fn log() -> Self {
949        Self {
950            axis_type: AxisType::Log,
951            show: true,
952            ..Self::default()
953        }
954    }
955
956    /// Sets the categories or the tick values of the axis.
957    ///
958    /// # Arguments
959    ///
960    /// - `Vec<DataValue>` - A `Vec<DataValue>` parameter.
961    pub fn data(mut self, data: Vec<DataValue>) -> Self {
962        self.set_data(data);
963        self
964    }
965
966    /// Sets the name of the axis.
967    ///
968    /// # Arguments
969    ///
970    /// - `&str` - Shared reference to a `str`.
971    pub fn name(mut self, name: &str) -> Self {
972        self.set_name(Some(name.to_string()));
973        self
974    }
975
976    /// Sets the labels of the axis.
977    ///
978    /// # Arguments
979    ///
980    /// - `LabelOption` - A `LabelOption` parameter.
981    pub fn axis_label(mut self, label: LabelOption) -> Self {
982        self.set_axis_label(Some(label));
983        self
984    }
985
986    /// Sets the line of the axis.
987    ///
988    /// # Arguments
989    ///
990    /// - `AxisLineOption` - A `AxisLineOption` parameter.
991    pub fn axis_line(mut self, line: AxisLineOption) -> Self {
992        self.set_axis_line(Some(line));
993        self
994    }
995
996    /// Sets the tick marks of the axis.
997    ///
998    /// # Arguments
999    ///
1000    /// - `AxisTickOption` - A `AxisTickOption` parameter.
1001    pub fn axis_tick(mut self, tick: AxisTickOption) -> Self {
1002        self.set_axis_tick(Some(tick));
1003        self
1004    }
1005
1006    /// Sets the split lines of the axis.
1007    ///
1008    /// # Arguments
1009    ///
1010    /// - `SplitLineOption` - A `SplitLineOption` parameter.
1011    pub fn split_line(mut self, line: SplitLineOption) -> Self {
1012        self.set_split_line(Some(line));
1013        self
1014    }
1015
1016    /// Sets the minimum value of the axis.
1017    ///
1018    /// # Arguments
1019    ///
1020    /// - `f64` - A 64-bit float (`f64`).
1021    pub fn min(mut self, min: f64) -> Self {
1022        self.set_min(Some(min));
1023        self
1024    }
1025
1026    /// Sets the maximum value of the axis.
1027    ///
1028    /// # Arguments
1029    ///
1030    /// - `f64` - A 64-bit float (`f64`).
1031    pub fn max(mut self, max: f64) -> Self {
1032        self.set_max(Some(max));
1033        self
1034    }
1035}
1036
1037/// Inherent implementation of [`TitleOption`].
1038impl TitleOption {
1039    /// Returns a title with the given text.
1040    ///
1041    /// # Arguments
1042    ///
1043    /// - `&str` - Shared reference to a `str`.
1044    pub fn new(text: &str) -> Self {
1045        Self {
1046            text: text.to_string(),
1047            show: true,
1048            ..Self::default()
1049        }
1050    }
1051
1052    /// Sets the subtitle.
1053    ///
1054    /// # Arguments
1055    ///
1056    /// - `&str` - Shared reference to a `str`.
1057    pub fn subtext(mut self, subtext: &str) -> Self {
1058        self.set_subtext(subtext.to_string());
1059        self
1060    }
1061}
1062
1063/// Inherent implementation of [`LegendOption`].
1064impl LegendOption {
1065    /// Returns a legend showing the given series names.
1066    ///
1067    /// # Arguments
1068    ///
1069    /// - `Vec<String>` - A `Vec<String>` parameter.
1070    pub fn new(data: Vec<String>) -> Self {
1071        Self {
1072            data,
1073            show: true,
1074            ..Self::default()
1075        }
1076    }
1077}
1078
1079/// Inherent implementation of [`GridOption`].
1080impl GridOption {
1081    /// Returns a visible grid.
1082    pub fn new() -> Self {
1083        Self {
1084            show: true,
1085            ..Self::default()
1086        }
1087    }
1088}
1089
1090/// Inherent implementation of [`TooltipOption`].
1091impl TooltipOption {
1092    /// Returns a visible tooltip.
1093    pub fn new() -> Self {
1094        Self {
1095            show: true,
1096            ..Self::default()
1097        }
1098    }
1099
1100    /// Sets what the tooltip describes.
1101    ///
1102    /// # Arguments
1103    ///
1104    /// - `TriggerType` - A `TriggerType` parameter.
1105    pub fn trigger(mut self, trigger: TriggerType) -> Self {
1106        self.set_trigger(trigger);
1107        self
1108    }
1109}
1110
1111/// Inherent implementation of [`LabelOption`].
1112impl LabelOption {
1113    /// Returns a visible label.
1114    pub fn new() -> Self {
1115        Self {
1116            show: true,
1117            ..Self::default()
1118        }
1119    }
1120
1121    /// Sets the colour of the label.
1122    ///
1123    /// # Arguments
1124    ///
1125    /// - `&str` - Shared reference to a `str`.
1126    pub fn color(mut self, color: &str) -> Self {
1127        self.set_color(Some(color.to_string()));
1128        self
1129    }
1130
1131    /// Sets the font size of the label.
1132    ///
1133    /// # Arguments
1134    ///
1135    /// - `f64` - A 64-bit float (`f64`).
1136    pub fn font_size(mut self, size: f64) -> Self {
1137        self.set_font_size(Some(size));
1138        self
1139    }
1140
1141    /// Sets the font family of the label.
1142    ///
1143    /// # Arguments
1144    ///
1145    /// - `&str` - Shared reference to a `str`.
1146    pub fn font_family(mut self, family: &str) -> Self {
1147        self.set_font_family(Some(family.to_string()));
1148        self
1149    }
1150}
1151
1152/// Inherent implementation of [`ItemStyleOption`].
1153impl ItemStyleOption {
1154    /// Returns a style filled with the given colour.
1155    ///
1156    /// # Arguments
1157    ///
1158    /// - `&str` - Shared reference to a `str`.
1159    pub fn filled(color: &str) -> Self {
1160        Self {
1161            color: Some(color.to_string()),
1162            ..Self::default()
1163        }
1164    }
1165}
1166
1167/// Inherent implementation of [`LineStyleOption`].
1168impl LineStyleOption {
1169    /// Returns a line style of the given colour and width.
1170    ///
1171    /// # Arguments
1172    ///
1173    /// - `&str` - Shared reference to a `str`.
1174    /// - `f64` - A 64-bit float (`f64`).
1175    pub fn new(color: &str, width: f64) -> Self {
1176        Self {
1177            color: Some(color.to_string()),
1178            width: Some(width),
1179            ..Self::default()
1180        }
1181    }
1182}