euv_ui/component/chart/model/impl.rs
1use super::*;
2
3/// Default legend configuration positioned at the top edge.
4impl Default for EuvChartLegend {
5 /// Creates a visible top-docked legend.
6 ///
7 /// # Returns
8 ///
9 /// - `Self` - Default legend configuration.
10 fn default() -> Self {
11 Self {
12 show: true,
13 position: EuvChartPosition::Top,
14 items: Vec::new(),
15 }
16 }
17}
18
19/// Default Cartesian grid margins and label containment.
20impl Default for EuvChartGrid {
21 /// Creates a standard padded Cartesian grid.
22 ///
23 /// # Returns
24 ///
25 /// - `Self` - Default grid margins.
26 fn default() -> Self {
27 Self {
28 left: ECHART_GRID_DEFAULT_LEFT,
29 right: ECHART_GRID_DEFAULT_RIGHT,
30 top: ECHART_GRID_DEFAULT_TOP,
31 bottom: ECHART_GRID_DEFAULT_BOTTOM,
32 contain_label: true,
33 show_border: false,
34 }
35 }
36}
37
38/// Default continuous numeric value axis configuration.
39impl Default for EuvChartAxis {
40 /// Creates a default `Value` axis with ticks, labels, and subtle grid split lines.
41 ///
42 /// # Returns
43 ///
44 /// - `Self` - Default axis configuration.
45 fn default() -> Self {
46 Self {
47 axis_type: EuvChartAxisType::Value,
48 name: String::new(),
49 unit_suffix: String::new(),
50 categories: Vec::new(),
51 grid_index: 0,
52 min: None,
53 max: None,
54 inverse: false,
55 split_number: ECHART_DEFAULT_SPLIT_NUMBER,
56 show_axis_line: true,
57 show_axis_tick: true,
58 show_axis_label: true,
59 show_split_line: true,
60 show_split_area: false,
61 position: None,
62 }
63 }
64}
65
66/// Default polar coordinate system.
67impl Default for EuvChartPolar {
68 /// Creates a centered polar coordinate system with category angle axis and value radius axis.
69 ///
70 /// # Returns
71 ///
72 /// - `Self` - Default polar configuration.
73 fn default() -> Self {
74 Self {
75 angle_axis: EuvChartAxis::category(Vec::new()),
76 radius_axis: EuvChartAxis::value(),
77 radius_ratio: 0.72,
78 center_x_ratio: 0.5,
79 center_y_ratio: 0.5,
80 }
81 }
82}
83
84/// Default radar coordinate system.
85impl Default for EuvChartRadar {
86 /// Creates a polygon radar web with four concentric rings.
87 ///
88 /// # Returns
89 ///
90 /// - `Self` - Default radar configuration.
91 fn default() -> Self {
92 Self {
93 indicators: Vec::new(),
94 shape: EuvChartRadarShape::Polygon,
95 split_number: 4,
96 radius_ratio: 0.72,
97 }
98 }
99}
100
101/// Default single-axis coordinate system.
102impl Default for EuvChartSingleAxis {
103 /// Creates a centered horizontal single-axis track.
104 ///
105 /// # Returns
106 ///
107 /// - `Self` - Default single-axis configuration.
108 fn default() -> Self {
109 Self {
110 axis: EuvChartAxis::category(Vec::new()),
111 center_y_ratio: 0.54,
112 }
113 }
114}
115
116/// Default calendar coordinate system.
117impl Default for EuvChartCalendar {
118 /// Creates a horizontal 26-week calendar matrix.
119 ///
120 /// # Returns
121 ///
122 /// - `Self` - Default calendar configuration.
123 fn default() -> Self {
124 Self {
125 year: 2026,
126 weeks: ECHART_CALENDAR_DEFAULT_WEEKS,
127 month_labels: Vec::new(),
128 cell_gap: 3.0,
129 orient: EuvChartOrient::Horizontal,
130 }
131 }
132}
133
134/// Default geographic coordinate system.
135impl Default for EuvChartGeo {
136 /// Creates a built-in stylized world map coordinate system.
137 ///
138 /// # Returns
139 ///
140 /// - `Self` - Default geo configuration.
141 fn default() -> Self {
142 Self {
143 preset: EuvChartGeoMapPreset::World,
144 regions: Vec::new(),
145 show_labels: true,
146 roam: false,
147 }
148 }
149}
150
151/// Default interactive hover tooltip configuration.
152impl Default for EuvChartTooltip {
153 /// Creates an axis-triggered tooltip with a vertical hairline crosshair.
154 ///
155 /// # Returns
156 ///
157 /// - `Self` - Default tooltip configuration.
158 fn default() -> Self {
159 Self {
160 show: true,
161 trigger: EuvChartTooltipTrigger::Axis,
162 axis_pointer: EuvChartAxisPointerType::Line,
163 }
164 }
165}
166
167/// Default interactive data-zoom slider configuration.
168impl Default for EuvChartDataZoom {
169 /// Creates a full-range slider data-zoom controller spanning `0%..=100%`.
170 ///
171 /// # Returns
172 ///
173 /// - `Self` - Default data-zoom controller.
174 fn default() -> Self {
175 Self {
176 kind: EuvChartDataZoomKind::Slider,
177 start_pct: 0.0,
178 end_pct: 100.0,
179 min_span_pct: ECHART_ZOOM_DEFAULT_MIN_SPAN,
180 show_preview: true,
181 }
182 }
183}
184
185/// Default visual-map gradient configuration.
186impl Default for EuvChartVisualMap {
187 /// Creates a visible continuous visual-map spanning `0.0..=100.0`.
188 ///
189 /// # Returns
190 ///
191 /// - `Self` - Default visual-map configuration.
192 fn default() -> Self {
193 Self {
194 show: true,
195 kind: EuvChartVisualMapKind::Continuous,
196 min: 0.0,
197 max: 100.0,
198 in_range_colors: Vec::new(),
199 pieces: Vec::new(),
200 orient: EuvChartOrient::Horizontal,
201 position: EuvChartPosition::Bottom,
202 }
203 }
204}
205
206/// Default compact icon-only toolbox configuration.
207impl Default for EuvChartToolbox {
208 /// Creates a toolbox with Restore, MagicType, DataView, and Fullscreen icons enabled.
209 ///
210 /// # Returns
211 ///
212 /// - `Self` - Default toolbox configuration.
213 fn default() -> Self {
214 Self {
215 show: true,
216 restore: true,
217 magic_type: true,
218 data_view: true,
219 fullscreen: true,
220 }
221 }
222}
223
224/// Default line series configuration.
225impl Default for EuvChartLineSeries {
226 /// Creates a crisp solid line series with circular point markers.
227 ///
228 /// # Returns
229 ///
230 /// - `Self` - Default line series.
231 fn default() -> Self {
232 Self {
233 values: Vec::new(),
234 xy_points: Vec::new(),
235 smooth: false,
236 step: EuvChartStepMode::None,
237 area_opacity: 0.0,
238 area_gradient: true,
239 stack: None,
240 dashed: false,
241 line_width: 2.2,
242 symbol: EuvChartSymbol::Circle,
243 symbol_size: 3.5,
244 connect_nulls: false,
245 show_labels: false,
246 coordinate_system: EuvChartCoordinateSystem::Cartesian2d,
247 x_axis_index: 0,
248 y_axis_index: 0,
249 annotations: EuvChartAnnotations::default(),
250 encode: None,
251 }
252 }
253}
254
255/// Default bar series configuration.
256impl Default for EuvChartBarSeries {
257 /// Creates a vertical grouped bar series with gently rounded caps.
258 ///
259 /// # Returns
260 ///
261 /// - `Self` - Default bar series.
262 fn default() -> Self {
263 Self {
264 values: Vec::new(),
265 stack: None,
266 bar_radius: 4.0,
267 bar_width_ratio: 0.62,
268 show_background: false,
269 show_labels: false,
270 coordinate_system: EuvChartCoordinateSystem::Cartesian2d,
271 x_axis_index: 0,
272 y_axis_index: 0,
273 annotations: EuvChartAnnotations::default(),
274 encode: None,
275 }
276 }
277}
278
279/// Default pie series configuration.
280impl Default for EuvChartPieSeries {
281 /// Creates a standard pie chart with external leader lines and labels.
282 ///
283 /// # Returns
284 ///
285 /// - `Self` - Default pie series.
286 fn default() -> Self {
287 Self {
288 slices: Vec::new(),
289 inner_radius_ratio: 0.0,
290 outer_radius_ratio: ECHART_PIE_DEFAULT_OUTER_RATIO,
291 rose_type: EuvChartRoseType::None,
292 pad_angle_deg: 1.5,
293 start_angle_deg: ECHART_PIE_DEFAULT_START_ANGLE,
294 show_labels: true,
295 show_leader_lines: true,
296 selected_offset: ECHART_PIE_DEFAULT_POPOUT,
297 center_x_ratio: 0.5,
298 center_y_ratio: 0.52,
299 }
300 }
301}
302
303/// Default scatter series configuration.
304impl Default for EuvChartScatterSeries {
305 /// Creates a Cartesian circular scatter series.
306 ///
307 /// # Returns
308 ///
309 /// - `Self` - Default scatter series.
310 fn default() -> Self {
311 Self {
312 points: Vec::new(),
313 symbol: EuvChartSymbol::Circle,
314 default_size: 6.0,
315 ripple_rings: 3,
316 ripple_scale: 2.6,
317 show_labels: false,
318 coordinate_system: EuvChartCoordinateSystem::Cartesian2d,
319 x_axis_index: 0,
320 y_axis_index: 0,
321 annotations: EuvChartAnnotations::default(),
322 encode: None,
323 }
324 }
325}
326
327/// Default radar series configuration.
328impl Default for EuvChartRadarSeries {
329 /// Creates a semi-transparent filled radar polygon series with vertex dots.
330 ///
331 /// # Returns
332 ///
333 /// - `Self` - Default radar series.
334 fn default() -> Self {
335 Self {
336 items: Vec::new(),
337 area_opacity: 0.24,
338 line_width: 2.0,
339 show_vertices: true,
340 }
341 }
342}
343
344/// Default candlestick series configuration.
345impl Default for EuvChartCandlestickSeries {
346 /// Creates an empty OHLC candlestick series on axis 0.
347 ///
348 /// # Returns
349 ///
350 /// - `Self` - Default candlestick series.
351 fn default() -> Self {
352 Self {
353 candles: Vec::new(),
354 bull_color: None,
355 bear_color: None,
356 x_axis_index: 0,
357 y_axis_index: 0,
358 annotations: EuvChartAnnotations::default(),
359 }
360 }
361}
362
363/// Default boxplot series configuration.
364impl Default for EuvChartBoxplotSeries {
365 /// Creates an empty five-number boxplot series on axis 0.
366 ///
367 /// # Returns
368 ///
369 /// - `Self` - Default boxplot series.
370 fn default() -> Self {
371 Self {
372 items: Vec::new(),
373 x_axis_index: 0,
374 y_axis_index: 0,
375 annotations: EuvChartAnnotations::default(),
376 }
377 }
378}
379
380/// Default heatmap series configuration.
381impl Default for EuvChartHeatmapSeries {
382 /// Creates a Cartesian matrix heatmap with cell labels enabled.
383 ///
384 /// # Returns
385 ///
386 /// - `Self` - Default heatmap series.
387 fn default() -> Self {
388 Self {
389 cells: Vec::new(),
390 show_labels: true,
391 cell_gap: 2.0,
392 coordinate_system: EuvChartCoordinateSystem::Cartesian2d,
393 x_axis_index: 0,
394 y_axis_index: 0,
395 }
396 }
397}
398
399/// Default treemap series configuration.
400impl Default for EuvChartTreemapSeries {
401 /// Creates a squarified treemap with group headers and subtle rounded corners.
402 ///
403 /// # Returns
404 ///
405 /// - `Self` - Default treemap series.
406 fn default() -> Self {
407 Self {
408 nodes: Vec::new(),
409 show_headers: true,
410 cell_gap: 3.0,
411 corner_radius: 4.0,
412 }
413 }
414}
415
416/// Default sunburst series configuration.
417impl Default for EuvChartSunburstSeries {
418 /// Creates a concentric hierarchical sunburst series.
419 ///
420 /// # Returns
421 ///
422 /// - `Self` - Default sunburst series.
423 fn default() -> Self {
424 Self {
425 nodes: Vec::new(),
426 inner_radius_ratio: 0.16,
427 outer_radius_ratio: 0.84,
428 pad_angle_deg: 1.0,
429 show_labels: true,
430 }
431 }
432}
433
434/// Default Sankey flow diagram configuration.
435impl Default for EuvChartSankeySeries {
436 /// Creates a layered Sankey series with translucent flow ribbons.
437 ///
438 /// # Returns
439 ///
440 /// - `Self` - Default Sankey series.
441 fn default() -> Self {
442 Self {
443 nodes: Vec::new(),
444 links: Vec::new(),
445 node_width: 14.0,
446 node_gap: 10.0,
447 ribbon_opacity: 0.36,
448 }
449 }
450}
451
452/// Default conversion funnel configuration.
453impl Default for EuvChartFunnelSeries {
454 /// Creates a descending conversion funnel with percentage labels.
455 ///
456 /// # Returns
457 ///
458 /// - `Self` - Default funnel series.
459 fn default() -> Self {
460 Self {
461 stages: Vec::new(),
462 sort: EuvChartFunnelSort::Descending,
463 gap: 3.0,
464 show_labels: true,
465 show_percent: true,
466 }
467 }
468}
469
470/// Default circular dial gauge configuration.
471impl Default for EuvChartGaugeSeries {
472 /// Creates a 270-degree dial gauge spanning `0..=100` with progress arc and pointer needle.
473 ///
474 /// # Returns
475 ///
476 /// - `Self` - Default gauge series.
477 fn default() -> Self {
478 Self {
479 value: 0.0,
480 min: 0.0,
481 max: 100.0,
482 unit: String::new(),
483 title: String::new(),
484 start_angle_deg: ECHART_GAUGE_DEFAULT_START_ANGLE,
485 end_angle_deg: ECHART_GAUGE_DEFAULT_END_ANGLE,
486 split_number: 5,
487 show_progress: true,
488 show_pointer: true,
489 segments: vec![
490 EuvChartGaugeSegment::new(0.35, Color::hex(ECHART_GAUGE_LOW_HEX)),
491 EuvChartGaugeSegment::new(0.75, Color::hex(ECHART_GAUGE_MID_HEX)),
492 EuvChartGaugeSegment::new(1.0, Color::hex(ECHART_GAUGE_HIGH_HEX)),
493 ],
494 }
495 }
496}
497
498/// Default relational network graph configuration.
499impl Default for EuvChartGraphSeries {
500 /// Creates a force-directed graph series with labels enabled.
501 ///
502 /// # Returns
503 ///
504 /// - `Self` - Default graph series.
505 fn default() -> Self {
506 Self {
507 nodes: Vec::new(),
508 edges: Vec::new(),
509 categories: Vec::new(),
510 layout: EuvChartGraphLayout::Force,
511 directed: true,
512 show_labels: true,
513 iterations: ECHART_GRAPH_DEFAULT_ITERS,
514 }
515 }
516}
517
518/// Default hierarchical tree series configuration.
519impl Default for EuvChartTreeSeries {
520 /// Creates a left-to-right orthogonal tree series.
521 ///
522 /// # Returns
523 ///
524 /// - `Self` - Default tree series.
525 fn default() -> Self {
526 Self {
527 root: EuvChartHierarchyNode::leaf(String::new(), 1.0),
528 layout: EuvChartTreeLayout::OrthogonalLeftRight,
529 symbol_size: 5.5,
530 show_labels: true,
531 }
532 }
533}
534
535/// Default parallel coordinates series configuration.
536impl Default for EuvChartParallelSeries {
537 /// Creates a parallel coordinates series with semi-transparent polylines.
538 ///
539 /// # Returns
540 ///
541 /// - `Self` - Default parallel series.
542 fn default() -> Self {
543 Self {
544 axes: Vec::new(),
545 rows: Vec::new(),
546 line_width: 1.8,
547 line_opacity: 0.72,
548 }
549 }
550}
551
552/// Default curved directional flow arcs configuration.
553impl Default for EuvChartLinesSeries {
554 /// Creates a Cartesian curved lines series with arrowheads enabled.
555 ///
556 /// # Returns
557 ///
558 /// - `Self` - Default lines series.
559 fn default() -> Self {
560 Self {
561 arcs: Vec::new(),
562 curveness: 0.22,
563 line_width: 2.0,
564 show_arrows: true,
565 coordinate_system: EuvChartCoordinateSystem::Cartesian2d,
566 x_axis_index: 0,
567 y_axis_index: 0,
568 }
569 }
570}
571
572/// Default ThemeRiver streamgraph configuration.
573impl Default for EuvChartThemeRiverSeries {
574 /// Creates a smooth centered ThemeRiver streamgraph with labels enabled.
575 ///
576 /// # Returns
577 ///
578 /// - `Self` - Default ThemeRiver series.
579 fn default() -> Self {
580 Self {
581 points: Vec::new(),
582 show_labels: true,
583 smooth: true,
584 }
585 }
586}
587
588/// Default pictorial bar series configuration.
589impl Default for EuvChartPictorialBarSeries {
590 /// Creates a repeated rounded-capsule pictorial bar series.
591 ///
592 /// # Returns
593 ///
594 /// - `Self` - Default pictorial bar series.
595 fn default() -> Self {
596 Self {
597 values: Vec::new(),
598 symbol: EuvChartSymbol::RoundRect,
599 symbol_repeat: true,
600 symbol_size: 10.0,
601 x_axis_index: 0,
602 y_axis_index: 0,
603 }
604 }
605}
606
607/// Default custom series configuration.
608impl Default for EuvChartCustomSeries {
609 /// Creates an empty custom painter series on axis 0.
610 ///
611 /// # Returns
612 ///
613 /// - `Self` - Default custom series.
614 fn default() -> Self {
615 Self {
616 values: Vec::new(),
617 painter: None,
618 x_axis_index: 0,
619 y_axis_index: 0,
620 }
621 }
622}
623
624/// Default geographic choropleth map series configuration.
625impl Default for EuvChartGeoMapSeries {
626 /// Creates a GeoMap series with labels and crisp borders enabled.
627 ///
628 /// # Returns
629 ///
630 /// - `Self` - Default GeoMap series.
631 fn default() -> Self {
632 Self {
633 data: Vec::new(),
634 show_labels: true,
635 border_width: 1.0,
636 }
637 }
638}
639
640/// Constructors and fluent builders for `EuvChartTitle`.
641impl EuvChartTitle {
642 /// Constructs a chart title with left alignment.
643 ///
644 /// # Arguments
645 ///
646 /// - `S` - Primary chart title string.
647 ///
648 /// # Returns
649 ///
650 /// - `Self` - Constructed title block.
651 #[must_use]
652 pub fn new<S>(text: S) -> Self
653 where
654 S: Into<String>,
655 {
656 Self {
657 text: text.into(),
658 subtext: String::new(),
659 align: EuvChartAlign::Left,
660 }
661 }
662
663 /// Sets an optional subtitle line fluently.
664 ///
665 /// # Arguments
666 ///
667 /// - `Self` - Source title block.
668 /// - `S` - Subtitle copy.
669 ///
670 /// # Returns
671 ///
672 /// - `Self` - Updated title block.
673 #[must_use]
674 pub fn subtext<S>(mut self, subtext: S) -> Self
675 where
676 S: Into<String>,
677 {
678 self.set_subtext(subtext.into());
679 self
680 }
681
682 /// Sets horizontal alignment fluently.
683 ///
684 /// # Arguments
685 ///
686 /// - `Self` - Source title block.
687 /// - `EuvChartAlign` - Title horizontal alignment.
688 ///
689 /// # Returns
690 ///
691 /// - `Self` - Updated title block.
692 #[must_use]
693 pub fn align(mut self, align: EuvChartAlign) -> Self {
694 self.set_align(align);
695 self
696 }
697}
698
699/// Fluent builders for `EuvChartLegend`.
700impl EuvChartLegend {
701 /// Creates a legend docked at `position`.
702 ///
703 /// # Arguments
704 ///
705 /// - `EuvChartPosition` - Docked legend edge.
706 ///
707 /// # Returns
708 ///
709 /// - `Self` - Configured legend.
710 #[must_use]
711 pub fn at(position: EuvChartPosition) -> Self {
712 let mut legend: Self = Self::default();
713 legend.set_position(position);
714 legend
715 }
716
717 /// Controls whether the legend strip is shown.
718 ///
719 /// # Arguments
720 ///
721 /// - `Self` - Source legend.
722 /// - `bool` - Visibility flag.
723 ///
724 /// # Returns
725 ///
726 /// - `Self` - Updated legend.
727 #[must_use]
728 pub fn show(mut self, show: bool) -> Self {
729 self.set_show(show);
730 self
731 }
732
733 /// Sets custom explicit legend item labels.
734 ///
735 /// # Arguments
736 ///
737 /// - `Self` - Source legend.
738 /// - `Vec<String>` - Explicit item labels.
739 ///
740 /// # Returns
741 ///
742 /// - `Self` - Updated legend.
743 #[must_use]
744 pub fn items(mut self, items: Vec<String>) -> Self {
745 self.set_items(items);
746 self
747 }
748}
749
750/// Fluent builders for `EuvChartGrid`.
751impl EuvChartGrid {
752 /// Creates a Cartesian subplot grid with explicit logical margins.
753 ///
754 /// # Arguments
755 ///
756 /// - `f32` - Left margin.
757 /// - `f32` - Right margin.
758 /// - `f32` - Top margin.
759 /// - `f32` - Bottom margin.
760 ///
761 /// # Returns
762 ///
763 /// - `Self` - Configured grid.
764 #[must_use]
765 pub fn margins(left: f32, right: f32, top: f32, bottom: f32) -> Self {
766 Self {
767 left,
768 right,
769 top,
770 bottom,
771 contain_label: true,
772 show_border: false,
773 }
774 }
775
776 /// Sets whether axis labels expand the grid margin automatically.
777 ///
778 /// # Arguments
779 ///
780 /// - `Self` - Source grid.
781 /// - `bool` - Label containment flag.
782 ///
783 /// # Returns
784 ///
785 /// - `Self` - Updated grid.
786 #[must_use]
787 pub fn contain_label(mut self, contain_label: bool) -> Self {
788 self.set_contain_label(contain_label);
789 self
790 }
791
792 /// Sets whether a frame border is drawn around the plot area.
793 ///
794 /// # Arguments
795 ///
796 /// - `Self` - Source grid.
797 /// - `bool` - Border visibility flag.
798 ///
799 /// # Returns
800 ///
801 /// - `Self` - Updated grid.
802 #[must_use]
803 pub fn show_border(mut self, show_border: bool) -> Self {
804 self.set_show_border(show_border);
805 self
806 }
807}
808
809/// Constructors, fluent builders, and safe option accessors for `EuvChartAxis`.
810impl EuvChartAxis {
811 /// Creates a discrete `Category` axis with the provided labels.
812 ///
813 /// # Arguments
814 ///
815 /// - `Vec<String>` - Ordered category labels.
816 ///
817 /// # Returns
818 ///
819 /// - `Self` - Category axis configuration.
820 #[must_use]
821 pub fn category(categories: Vec<String>) -> Self {
822 let mut axis: Self = Self::default();
823 axis.set_axis_type(EuvChartAxisType::Category);
824 axis.set_categories(categories);
825 axis.set_show_split_line(false);
826 axis
827 }
828
829 /// Creates a continuous linear `Value` axis.
830 ///
831 /// # Returns
832 ///
833 /// - `Self` - Value axis configuration.
834 #[must_use]
835 pub fn value() -> Self {
836 Self::default()
837 }
838
839 /// Creates a continuous `Time` axis formatting numeric timestamps.
840 ///
841 /// # Returns
842 ///
843 /// - `Self` - Time axis configuration.
844 #[must_use]
845 pub fn time() -> Self {
846 let mut axis: Self = Self::default();
847 axis.set_axis_type(EuvChartAxisType::Time);
848 axis
849 }
850
851 /// Creates a base-10 logarithmic `Log` axis.
852 ///
853 /// # Returns
854 ///
855 /// - `Self` - Logarithmic axis configuration.
856 #[must_use]
857 pub fn log() -> Self {
858 let mut axis: Self = Self::default();
859 axis.set_axis_type(EuvChartAxisType::Log);
860 axis
861 }
862
863 /// Sets the axis caption name fluently.
864 ///
865 /// # Arguments
866 ///
867 /// - `Self` - Source axis.
868 /// - `S` - Axis name text.
869 ///
870 /// # Returns
871 ///
872 /// - `Self` - Updated axis.
873 #[must_use]
874 pub fn name<S>(mut self, name: S) -> Self
875 where
876 S: Into<String>,
877 {
878 self.set_name(name.into());
879 self
880 }
881
882 /// Sets a unit suffix appended to numeric tick labels.
883 ///
884 /// # Arguments
885 ///
886 /// - `Self` - Source axis.
887 /// - `S` - Unit suffix (e.g. `"%"` or `"ms"`).
888 ///
889 /// # Returns
890 ///
891 /// - `Self` - Updated axis.
892 #[must_use]
893 pub fn unit_suffix<S>(mut self, suffix: S) -> Self
894 where
895 S: Into<String>,
896 {
897 self.set_unit_suffix(suffix.into());
898 self
899 }
900
901 /// Sets an explicit lower domain bound.
902 ///
903 /// # Arguments
904 ///
905 /// - `Self` - Source axis.
906 /// - `f32` - Explicit minimum domain value.
907 ///
908 /// # Returns
909 ///
910 /// - `Self` - Updated axis.
911 #[must_use]
912 pub fn min(mut self, min: f32) -> Self {
913 self.set_min(Some(min));
914 self
915 }
916
917 /// Sets an explicit upper domain bound.
918 ///
919 /// # Arguments
920 ///
921 /// - `Self` - Source axis.
922 /// - `f32` - Explicit maximum domain value.
923 ///
924 /// # Returns
925 ///
926 /// - `Self` - Updated axis.
927 #[must_use]
928 pub fn max(mut self, max: f32) -> Self {
929 self.set_max(Some(max));
930 self
931 }
932
933 /// Reverses axis direction when `inverse` is `true`.
934 ///
935 /// # Arguments
936 ///
937 /// - `Self` - Source axis.
938 /// - `bool` - Inverse direction flag.
939 ///
940 /// # Returns
941 ///
942 /// - `Self` - Updated axis.
943 #[must_use]
944 pub fn inverse(mut self, inverse: bool) -> Self {
945 self.set_inverse(inverse);
946 self
947 }
948
949 /// Sets the target tick split count.
950 ///
951 /// # Arguments
952 ///
953 /// - `Self` - Source axis.
954 /// - `usize` - Split interval count.
955 ///
956 /// # Returns
957 ///
958 /// - `Self` - Updated axis.
959 #[must_use]
960 pub fn split_number(mut self, count: usize) -> Self {
961 self.set_split_number(count.max(1));
962 self
963 }
964
965 /// Sets whether grid split lines are rendered.
966 ///
967 /// # Arguments
968 ///
969 /// - `Self` - Source axis.
970 /// - `bool` - Split line visibility flag.
971 ///
972 /// # Returns
973 ///
974 /// - `Self` - Updated axis.
975 #[must_use]
976 pub fn show_split_line(mut self, show: bool) -> Self {
977 self.set_show_split_line(show);
978 self
979 }
980
981 /// Sets whether alternating split background bands are rendered.
982 ///
983 /// # Arguments
984 ///
985 /// - `Self` - Source axis.
986 /// - `bool` - Split area visibility flag.
987 ///
988 /// # Returns
989 ///
990 /// - `Self` - Updated axis.
991 #[must_use]
992 pub fn show_split_area(mut self, show: bool) -> Self {
993 self.set_show_split_area(show);
994 self
995 }
996
997 /// Assigns this axis to a specific subplot grid index.
998 ///
999 /// # Arguments
1000 ///
1001 /// - `Self` - Source axis.
1002 /// - `usize` - Subplot grid index.
1003 ///
1004 /// # Returns
1005 ///
1006 /// - `Self` - Updated axis.
1007 #[must_use]
1008 pub fn grid_index(mut self, idx: usize) -> Self {
1009 self.set_grid_index(idx);
1010 self
1011 }
1012
1013 /// Overrides the axis side placement for dual-axis layouts.
1014 ///
1015 /// # Arguments
1016 ///
1017 /// - `Self` - Source axis.
1018 /// - `EuvChartPosition` - Explicit axis side.
1019 ///
1020 /// # Returns
1021 ///
1022 /// - `Self` - Updated axis.
1023 #[must_use]
1024 pub fn position(mut self, pos: EuvChartPosition) -> Self {
1025 self.set_position(Some(pos));
1026 self
1027 }
1028
1029 /// Returns the optional explicit minimum domain bound.
1030 ///
1031 /// # Arguments
1032 ///
1033 /// - `&Self` - Axis configuration.
1034 ///
1035 /// # Returns
1036 ///
1037 /// - `Option<f32>` - Explicit lower bound when configured.
1038 #[must_use]
1039 pub fn min_opt(&self) -> Option<f32> {
1040 let Self { min, .. } = *self;
1041 min
1042 }
1043
1044 /// Returns the optional explicit maximum domain bound.
1045 ///
1046 /// # Arguments
1047 ///
1048 /// - `&Self` - Axis configuration.
1049 ///
1050 /// # Returns
1051 ///
1052 /// - `Option<f32>` - Explicit upper bound when configured.
1053 #[must_use]
1054 pub fn max_opt(&self) -> Option<f32> {
1055 let Self { max, .. } = *self;
1056 max
1057 }
1058
1059 /// Returns the optional explicit side override.
1060 ///
1061 /// # Arguments
1062 ///
1063 /// - `&Self` - Axis configuration.
1064 ///
1065 /// # Returns
1066 ///
1067 /// - `Option<EuvChartPosition>` - Explicit side when set.
1068 #[must_use]
1069 pub fn position_opt(&self) -> Option<EuvChartPosition> {
1070 let Self { position, .. } = *self;
1071 position
1072 }
1073}
1074
1075/// Fluent constructors for `EuvChartPolar`.
1076impl EuvChartPolar {
1077 /// Creates a polar coordinate system from angle and radius axes.
1078 ///
1079 /// # Arguments
1080 ///
1081 /// - `EuvChartAxis` - Angular axis definition.
1082 /// - `EuvChartAxis` - Radial axis definition.
1083 ///
1084 /// # Returns
1085 ///
1086 /// - `Self` - Polar coordinate system.
1087 #[must_use]
1088 pub fn new(angle_axis: EuvChartAxis, radius_axis: EuvChartAxis) -> Self {
1089 Self {
1090 angle_axis,
1091 radius_axis,
1092 radius_ratio: 0.72,
1093 center_x_ratio: 0.5,
1094 center_y_ratio: 0.52,
1095 }
1096 }
1097}
1098
1099/// Fluent constructors for `EuvChartRadar`.
1100impl EuvChartRadar {
1101 /// Creates a radar web from ordered indicator definitions.
1102 ///
1103 /// # Arguments
1104 ///
1105 /// - `Vec<EuvChartRadarIndicator>` - Multivariate indicator spokes.
1106 ///
1107 /// # Returns
1108 ///
1109 /// - `Self` - Radar coordinate system.
1110 #[must_use]
1111 pub fn new(indicators: Vec<EuvChartRadarIndicator>) -> Self {
1112 let mut radar: Self = Self::default();
1113 radar.set_indicators(indicators);
1114 radar
1115 }
1116
1117 /// Sets polygon or circular web ring geometry.
1118 ///
1119 /// # Arguments
1120 ///
1121 /// - `Self` - Source radar configuration.
1122 /// - `EuvChartRadarShape` - Web ring geometry.
1123 ///
1124 /// # Returns
1125 ///
1126 /// - `Self` - Updated radar configuration.
1127 #[must_use]
1128 pub fn shape(mut self, shape: EuvChartRadarShape) -> Self {
1129 self.set_shape(shape);
1130 self
1131 }
1132
1133 /// Sets the number of concentric split rings.
1134 ///
1135 /// # Arguments
1136 ///
1137 /// - `Self` - Source radar configuration.
1138 /// - `usize` - Ring count.
1139 ///
1140 /// # Returns
1141 ///
1142 /// - `Self` - Updated radar configuration.
1143 #[must_use]
1144 pub fn split_number(mut self, split_number: usize) -> Self {
1145 self.set_split_number(split_number.max(1));
1146 self
1147 }
1148}
1149
1150/// Fluent constructors for `EuvChartSingleAxis`.
1151impl EuvChartSingleAxis {
1152 /// Creates a single-axis coordinate system wrapping `axis`.
1153 ///
1154 /// # Arguments
1155 ///
1156 /// - `EuvChartAxis` - Underlying 1D axis definition.
1157 ///
1158 /// # Returns
1159 ///
1160 /// - `Self` - Single-axis coordinate system.
1161 #[must_use]
1162 pub fn new(axis: EuvChartAxis) -> Self {
1163 Self {
1164 axis,
1165 center_y_ratio: 0.54,
1166 }
1167 }
1168}
1169
1170/// Fluent constructors for `EuvChartCalendar`.
1171impl EuvChartCalendar {
1172 /// Creates a calendar coordinate system for `year` and `weeks`.
1173 ///
1174 /// # Arguments
1175 ///
1176 /// - `u32` - Calendar year.
1177 /// - `usize` - Number of week columns.
1178 ///
1179 /// # Returns
1180 ///
1181 /// - `Self` - Calendar coordinate system.
1182 #[must_use]
1183 pub fn new(year: u32, weeks: usize) -> Self {
1184 let mut cal: Self = Self::default();
1185 cal.set_year(year);
1186 cal.set_weeks(weeks.max(1));
1187 cal
1188 }
1189
1190 /// Sets custom month header labels along the week span.
1191 ///
1192 /// # Arguments
1193 ///
1194 /// - `Self` - Source calendar.
1195 /// - `Vec<String>` - Ordered month labels.
1196 ///
1197 /// # Returns
1198 ///
1199 /// - `Self` - Updated calendar.
1200 #[must_use]
1201 pub fn month_labels(mut self, labels: Vec<String>) -> Self {
1202 self.set_month_labels(labels);
1203 self
1204 }
1205}
1206
1207/// Constructors and accessors for `EuvChartGeoRegion` and `EuvChartGeo`.
1208impl EuvChartGeoRegion {
1209 /// Creates a geographic polygon region from `(lon, lat)` rings.
1210 ///
1211 /// # Arguments
1212 ///
1213 /// - `S` - Region name.
1214 /// - `C` - Region ISO or short code.
1215 /// - `Vec<Vec<(f32, f32)>>` - Closed exterior polygon rings.
1216 ///
1217 /// # Returns
1218 ///
1219 /// - `Self` - Constructed region.
1220 #[must_use]
1221 pub fn new<S, C>(name: S, code: C, polygons: Vec<Vec<(f32, f32)>>) -> Self
1222 where
1223 S: Into<String>,
1224 C: Into<String>,
1225 {
1226 Self {
1227 name: name.into(),
1228 code: code.into(),
1229 polygons,
1230 label_center: None,
1231 }
1232 }
1233
1234 /// Sets an explicit `(lon, lat)` label anchor point.
1235 ///
1236 /// # Arguments
1237 ///
1238 /// - `Self` - Source region.
1239 /// - `(f32, f32)` - Label `(longitude, latitude)` coordinate.
1240 ///
1241 /// # Returns
1242 ///
1243 /// - `Self` - Updated region.
1244 #[must_use]
1245 pub fn label_center(mut self, center: (f32, f32)) -> Self {
1246 self.set_label_center(Some(center));
1247 self
1248 }
1249
1250 /// Returns the optional explicit label anchor.
1251 ///
1252 /// # Arguments
1253 ///
1254 /// - `&Self` - Source region.
1255 ///
1256 /// # Returns
1257 ///
1258 /// - `Option<(f32, f32)>` - Explicit `(lon, lat)` label anchor.
1259 #[must_use]
1260 pub fn label_center_opt(&self) -> Option<(f32, f32)> {
1261 let Self { label_center, .. } = *self;
1262 label_center
1263 }
1264}
1265
1266/// Fluent builders for `EuvChartGeo`.
1267impl EuvChartGeo {
1268 /// Creates a built-in stylized world map coordinate system.
1269 ///
1270 /// # Returns
1271 ///
1272 /// - `Self` - World geo coordinate system.
1273 #[must_use]
1274 pub fn world() -> Self {
1275 Self::default()
1276 }
1277
1278 /// Creates a custom geo coordinate system from caller-supplied regions.
1279 ///
1280 /// # Arguments
1281 ///
1282 /// - `Vec<EuvChartGeoRegion>` - Custom vector polygon regions.
1283 ///
1284 /// # Returns
1285 ///
1286 /// - `Self` - Custom geo coordinate system.
1287 #[must_use]
1288 pub fn custom(regions: Vec<EuvChartGeoRegion>) -> Self {
1289 Self {
1290 preset: EuvChartGeoMapPreset::Custom,
1291 regions,
1292 show_labels: true,
1293 roam: false,
1294 }
1295 }
1296
1297 /// Toggles region caption visibility on the map.
1298 ///
1299 /// # Arguments
1300 ///
1301 /// - `Self` - Source geo coordinate system.
1302 /// - `bool` - Label visibility flag.
1303 ///
1304 /// # Returns
1305 ///
1306 /// - `Self` - Updated geo coordinate system.
1307 #[must_use]
1308 pub fn show_labels(mut self, show: bool) -> Self {
1309 self.set_show_labels(show);
1310 self
1311 }
1312}
1313
1314/// Fluent constructors for `EuvChartTooltip`.
1315impl EuvChartTooltip {
1316 /// Creates a tooltip with `trigger` and `axis_pointer`.
1317 ///
1318 /// # Arguments
1319 ///
1320 /// - `EuvChartTooltipTrigger` - Tooltip trigger mode.
1321 /// - `EuvChartAxisPointerType` - Crosshair axis pointer style.
1322 ///
1323 /// # Returns
1324 ///
1325 /// - `Self` - Configured tooltip.
1326 #[must_use]
1327 pub fn new(trigger: EuvChartTooltipTrigger, axis_pointer: EuvChartAxisPointerType) -> Self {
1328 Self {
1329 show: trigger != EuvChartTooltipTrigger::None,
1330 trigger,
1331 axis_pointer,
1332 }
1333 }
1334
1335 /// Creates an item-snapping tooltip without crosshair bars.
1336 ///
1337 /// # Returns
1338 ///
1339 /// - `Self` - Item tooltip configuration.
1340 #[must_use]
1341 pub fn item() -> Self {
1342 Self::new(EuvChartTooltipTrigger::Item, EuvChartAxisPointerType::None)
1343 }
1344
1345 /// Creates an axis-snapping tooltip with a chosen crosshair style.
1346 ///
1347 /// # Arguments
1348 ///
1349 /// - `EuvChartAxisPointerType` - Crosshair pointer style.
1350 ///
1351 /// # Returns
1352 ///
1353 /// - `Self` - Axis tooltip configuration.
1354 #[must_use]
1355 pub fn axis(pointer: EuvChartAxisPointerType) -> Self {
1356 Self::new(EuvChartTooltipTrigger::Axis, pointer)
1357 }
1358}
1359
1360/// Fluent constructors for `EuvChartDataZoom`.
1361impl EuvChartDataZoom {
1362 /// Creates an `Inside` wheel-zoom and drag-pan controller.
1363 ///
1364 /// # Returns
1365 ///
1366 /// - `Self` - Inside data-zoom controller.
1367 #[must_use]
1368 pub fn inside() -> Self {
1369 let mut dz: Self = Self::default();
1370 dz.set_kind(EuvChartDataZoomKind::Inside);
1371 dz
1372 }
1373
1374 /// Creates a bottom interactive `Slider` range scrubber.
1375 ///
1376 /// # Returns
1377 ///
1378 /// - `Self` - Slider data-zoom controller.
1379 #[must_use]
1380 pub fn slider() -> Self {
1381 Self::default()
1382 }
1383
1384 /// Sets the initial percentage window `(start_pct, end_pct)`.
1385 ///
1386 /// # Arguments
1387 ///
1388 /// - `Self` - Source data-zoom controller.
1389 /// - `f32` - Start percentage in `[0.0, 100.0]`.
1390 /// - `f32` - End percentage in `[0.0, 100.0]`.
1391 ///
1392 /// # Returns
1393 ///
1394 /// - `Self` - Updated data-zoom controller.
1395 #[must_use]
1396 pub fn range(mut self, start_pct: f32, end_pct: f32) -> Self {
1397 let lo: f32 = start_pct.clamp(0.0, 99.0);
1398 let hi: f32 = end_pct.clamp(lo + 1.0, 100.0);
1399 self.set_start_pct(lo);
1400 self.set_end_pct(hi);
1401 self
1402 }
1403}
1404
1405/// Constructors and accessors for `EuvChartVisualPiece`.
1406impl EuvChartVisualPiece {
1407 /// Creates a discrete piecewise color bucket.
1408 ///
1409 /// # Arguments
1410 ///
1411 /// - `Option<f32>` - Optional inclusive lower threshold.
1412 /// - `Option<f32>` - Optional inclusive upper threshold.
1413 /// - `S` - Display label.
1414 /// - `Color` - Bucket fill color.
1415 ///
1416 /// # Returns
1417 ///
1418 /// - `Self` - Visual-map piece.
1419 #[must_use]
1420 pub fn new<S>(min: Option<f32>, max: Option<f32>, label: S, color: Color) -> Self
1421 where
1422 S: Into<String>,
1423 {
1424 Self {
1425 min,
1426 max,
1427 label: label.into(),
1428 color,
1429 }
1430 }
1431
1432 /// Returns the optional lower bound.
1433 ///
1434 /// # Arguments
1435 ///
1436 /// - `&Self` - Piece definition.
1437 ///
1438 /// # Returns
1439 ///
1440 /// - `Option<f32>` - Lower threshold.
1441 #[must_use]
1442 pub fn min_opt(&self) -> Option<f32> {
1443 let Self { min, .. } = *self;
1444 min
1445 }
1446
1447 /// Returns the optional upper bound.
1448 ///
1449 /// # Arguments
1450 ///
1451 /// - `&Self` - Piece definition.
1452 ///
1453 /// # Returns
1454 ///
1455 /// - `Option<f32>` - Upper threshold.
1456 #[must_use]
1457 pub fn max_opt(&self) -> Option<f32> {
1458 let Self { max, .. } = *self;
1459 max
1460 }
1461}
1462
1463/// Fluent constructors for `EuvChartVisualMap`.
1464impl EuvChartVisualMap {
1465 /// Creates a continuous gradient visual-map spanning `[min, max]`.
1466 ///
1467 /// # Arguments
1468 ///
1469 /// - `f32` - Minimum mapped value.
1470 /// - `f32` - Maximum mapped value.
1471 ///
1472 /// # Returns
1473 ///
1474 /// - `Self` - Continuous visual-map.
1475 #[must_use]
1476 pub fn continuous(min: f32, max: f32) -> Self {
1477 let mut vm: Self = Self::default();
1478 vm.set_kind(EuvChartVisualMapKind::Continuous);
1479 vm.set_min(min);
1480 vm.set_max(max);
1481 vm
1482 }
1483
1484 /// Creates a piecewise discrete range visual-map.
1485 ///
1486 /// # Arguments
1487 ///
1488 /// - `Vec<EuvChartVisualPiece>` - Ordered discrete buckets.
1489 ///
1490 /// # Returns
1491 ///
1492 /// - `Self` - Piecewise visual-map.
1493 #[must_use]
1494 pub fn piecewise(pieces: Vec<EuvChartVisualPiece>) -> Self {
1495 let mut vm: Self = Self::default();
1496 vm.set_kind(EuvChartVisualMapKind::Piecewise);
1497 vm.set_pieces(pieces);
1498 vm
1499 }
1500
1501 /// Overrides the ordered color stops used by continuous interpolation.
1502 ///
1503 /// # Arguments
1504 ///
1505 /// - `Self` - Source visual-map.
1506 /// - `Vec<Color>` - Ordered gradient color stops.
1507 ///
1508 /// # Returns
1509 ///
1510 /// - `Self` - Updated visual-map.
1511 #[must_use]
1512 pub fn colors(mut self, colors: Vec<Color>) -> Self {
1513 self.set_in_range_colors(colors);
1514 self
1515 }
1516
1517 /// Sets the visual-map bar dock position.
1518 ///
1519 /// # Arguments
1520 ///
1521 /// - `Self` - Source visual-map.
1522 /// - `EuvChartPosition` - Docked edge.
1523 ///
1524 /// # Returns
1525 ///
1526 /// - `Self` - Updated visual-map.
1527 #[must_use]
1528 pub fn position(mut self, position: EuvChartPosition) -> Self {
1529 self.set_position(position);
1530 self
1531 }
1532}
1533
1534/// Fluent builders for `EuvChartToolbox`.
1535impl EuvChartToolbox {
1536 /// Creates a toolbox with all standard actions enabled.
1537 ///
1538 /// # Returns
1539 ///
1540 /// - `Self` - Full toolbox configuration.
1541 #[must_use]
1542 pub fn full() -> Self {
1543 Self::default()
1544 }
1545
1546 /// Toggles MagicType switcher availability.
1547 ///
1548 /// # Arguments
1549 ///
1550 /// - `Self` - Source toolbox.
1551 /// - `bool` - Enabled flag.
1552 ///
1553 /// # Returns
1554 ///
1555 /// - `Self` - Updated toolbox.
1556 #[must_use]
1557 pub fn magic_type(mut self, enabled: bool) -> Self {
1558 self.set_magic_type(enabled);
1559 self
1560 }
1561
1562 /// Toggles DataView tabular inspection availability.
1563 ///
1564 /// # Arguments
1565 ///
1566 /// - `Self` - Source toolbox.
1567 /// - `bool` - Enabled flag.
1568 ///
1569 /// # Returns
1570 ///
1571 /// - `Self` - Updated toolbox.
1572 #[must_use]
1573 pub fn data_view(mut self, enabled: bool) -> Self {
1574 self.set_data_view(enabled);
1575 self
1576 }
1577
1578 /// Toggles Fullscreen modal availability.
1579 ///
1580 /// # Arguments
1581 ///
1582 /// - `Self` - Source toolbox.
1583 /// - `bool` - Enabled flag.
1584 ///
1585 /// # Returns
1586 ///
1587 /// - `Self` - Updated toolbox.
1588 #[must_use]
1589 pub fn fullscreen(mut self, enabled: bool) -> Self {
1590 self.set_fullscreen(enabled);
1591 self
1592 }
1593}
1594
1595/// Constructors and helpers for `EuvChartDataset` and `EuvChartEncode`.
1596impl EuvChartDataset {
1597 /// Constructs a tabular dataset from column names and rows.
1598 ///
1599 /// # Arguments
1600 ///
1601 /// - `Vec<String>` - Dimension column names.
1602 /// - `Vec<Vec<EuvChartCell>>` - Ordered data rows.
1603 ///
1604 /// # Returns
1605 ///
1606 /// - `Self` - Constructed dataset.
1607 #[must_use]
1608 pub fn new(dimensions: Vec<String>, rows: Vec<Vec<EuvChartCell>>) -> Self {
1609 Self { dimensions, rows }
1610 }
1611
1612 /// Resolves a dimension name (or decimal column index string) to its column index.
1613 ///
1614 /// # Arguments
1615 ///
1616 /// - `&Self` - Source dataset.
1617 /// - `&str` - Dimension name or numeric column index.
1618 ///
1619 /// # Returns
1620 ///
1621 /// - `Option<usize>` - Matched column index.
1622 #[must_use]
1623 pub fn column_index(&self, dim: &str) -> Option<usize> {
1624 if let Some(pos) = self
1625 .get_dimensions()
1626 .iter()
1627 .position(|d: &String| d.as_str() == dim)
1628 {
1629 return Some(pos);
1630 }
1631 dim.parse::<usize>().ok()
1632 }
1633}
1634
1635/// Fluent builders and accessors for `EuvChartEncode`.
1636impl EuvChartEncode {
1637 /// Maps the X channel to dimension `dim`.
1638 ///
1639 /// # Arguments
1640 ///
1641 /// - `Self` - Source encode mapping.
1642 /// - `S` - Dimension name or column index.
1643 ///
1644 /// # Returns
1645 ///
1646 /// - `Self` - Updated encode mapping.
1647 #[must_use]
1648 pub fn x<S>(mut self, dim: S) -> Self
1649 where
1650 S: Into<String>,
1651 {
1652 self.set_x(Some(dim.into()));
1653 self
1654 }
1655
1656 /// Maps the Y channel to dimension `dim`.
1657 ///
1658 /// # Arguments
1659 ///
1660 /// - `Self` - Source encode mapping.
1661 /// - `S` - Dimension name or column index.
1662 ///
1663 /// # Returns
1664 ///
1665 /// - `Self` - Updated encode mapping.
1666 #[must_use]
1667 pub fn y<S>(mut self, dim: S) -> Self
1668 where
1669 S: Into<String>,
1670 {
1671 self.set_y(Some(dim.into()));
1672 self
1673 }
1674
1675 /// Maps the scalar value channel to dimension `dim`.
1676 ///
1677 /// # Arguments
1678 ///
1679 /// - `Self` - Source encode mapping.
1680 /// - `S` - Dimension name or column index.
1681 ///
1682 /// # Returns
1683 ///
1684 /// - `Self` - Updated encode mapping.
1685 #[must_use]
1686 pub fn value<S>(mut self, dim: S) -> Self
1687 where
1688 S: Into<String>,
1689 {
1690 self.set_value(Some(dim.into()));
1691 self
1692 }
1693
1694 /// Maps the bubble size channel to dimension `dim`.
1695 ///
1696 /// # Arguments
1697 ///
1698 /// - `Self` - Source encode mapping.
1699 /// - `S` - Dimension name or column index.
1700 ///
1701 /// # Returns
1702 ///
1703 /// - `Self` - Updated encode mapping.
1704 #[must_use]
1705 pub fn size<S>(mut self, dim: S) -> Self
1706 where
1707 S: Into<String>,
1708 {
1709 self.set_size(Some(dim.into()));
1710 self
1711 }
1712
1713 /// Maps the item caption channel to dimension `dim`.
1714 ///
1715 /// # Arguments
1716 ///
1717 /// - `Self` - Source encode mapping.
1718 /// - `S` - Dimension name or column index.
1719 ///
1720 /// # Returns
1721 ///
1722 /// - `Self` - Updated encode mapping.
1723 #[must_use]
1724 pub fn item_name<S>(mut self, dim: S) -> Self
1725 where
1726 S: Into<String>,
1727 {
1728 self.set_item_name(Some(dim.into()));
1729 self
1730 }
1731
1732 /// Returns the X dimension name if mapped.
1733 ///
1734 /// # Arguments
1735 ///
1736 /// - `&Self` - Encode mapping.
1737 ///
1738 /// # Returns
1739 ///
1740 /// - `Option<&str>` - Mapped X dimension.
1741 #[must_use]
1742 pub fn x_opt(&self) -> Option<&str> {
1743 let Self { x, .. } = self;
1744 x.as_deref()
1745 }
1746
1747 /// Returns the Y dimension name if mapped.
1748 ///
1749 /// # Arguments
1750 ///
1751 /// - `&Self` - Encode mapping.
1752 ///
1753 /// # Returns
1754 ///
1755 /// - `Option<&str>` - Mapped Y dimension.
1756 #[must_use]
1757 pub fn y_opt(&self) -> Option<&str> {
1758 let Self { y, .. } = self;
1759 y.as_deref()
1760 }
1761
1762 /// Returns the value dimension name if mapped.
1763 ///
1764 /// # Arguments
1765 ///
1766 /// - `&Self` - Encode mapping.
1767 ///
1768 /// # Returns
1769 ///
1770 /// - `Option<&str>` - Mapped value dimension.
1771 #[must_use]
1772 pub fn value_opt(&self) -> Option<&str> {
1773 let Self { value, .. } = self;
1774 value.as_deref()
1775 }
1776
1777 /// Returns the size dimension name if mapped.
1778 ///
1779 /// # Arguments
1780 ///
1781 /// - `&Self` - Encode mapping.
1782 ///
1783 /// # Returns
1784 ///
1785 /// - `Option<&str>` - Mapped size dimension.
1786 #[must_use]
1787 pub fn size_opt(&self) -> Option<&str> {
1788 let Self { size, .. } = self;
1789 size.as_deref()
1790 }
1791
1792 /// Returns the item name dimension if mapped.
1793 ///
1794 /// # Arguments
1795 ///
1796 /// - `&Self` - Encode mapping.
1797 ///
1798 /// # Returns
1799 ///
1800 /// - `Option<&str>` - Mapped item name dimension.
1801 #[must_use]
1802 pub fn item_name_opt(&self) -> Option<&str> {
1803 let Self { item_name, .. } = self;
1804 item_name.as_deref()
1805 }
1806}
1807
1808/// Constructors and accessors for `EuvChartMarkPoint`, `EuvChartMarkLine`, and `EuvChartMarkArea`.
1809impl EuvChartMarkPoint {
1810 /// Creates a mark-point annotation pin.
1811 ///
1812 /// # Arguments
1813 ///
1814 /// - `EuvChartMarkPointKind` - Target datum rule.
1815 /// - `S` - Callout label.
1816 ///
1817 /// # Returns
1818 ///
1819 /// - `Self` - Constructed mark point.
1820 #[must_use]
1821 pub fn new<S>(kind: EuvChartMarkPointKind, name: S) -> Self
1822 where
1823 S: Into<String>,
1824 {
1825 Self {
1826 kind,
1827 name: name.into(),
1828 color: None,
1829 }
1830 }
1831
1832 /// Overrides the pin tint color.
1833 ///
1834 /// # Arguments
1835 ///
1836 /// - `Self` - Source mark point.
1837 /// - `Color` - Pin fill color.
1838 ///
1839 /// # Returns
1840 ///
1841 /// - `Self` - Updated mark point.
1842 #[must_use]
1843 pub fn color(mut self, color: Color) -> Self {
1844 self.set_color(Some(color));
1845 self
1846 }
1847
1848 /// Returns the optional color override.
1849 ///
1850 /// # Arguments
1851 ///
1852 /// - `&Self` - Source mark point.
1853 ///
1854 /// # Returns
1855 ///
1856 /// - `Option<Color>` - Explicit pin color.
1857 #[must_use]
1858 pub fn color_opt(&self) -> Option<Color> {
1859 let Self { color, .. } = *self;
1860 color
1861 }
1862}
1863
1864/// Constructors and accessors for `EuvChartMarkLine`.
1865impl EuvChartMarkLine {
1866 /// Creates a dashed reference mark line.
1867 ///
1868 /// # Arguments
1869 ///
1870 /// - `EuvChartMarkLineKind` - Target reference rule.
1871 /// - `S` - Reference label text.
1872 ///
1873 /// # Returns
1874 ///
1875 /// - `Self` - Constructed mark line.
1876 #[must_use]
1877 pub fn new<S>(kind: EuvChartMarkLineKind, name: S) -> Self
1878 where
1879 S: Into<String>,
1880 {
1881 Self {
1882 kind,
1883 name: name.into(),
1884 color: None,
1885 dashed: true,
1886 }
1887 }
1888
1889 /// Overrides the mark line stroke color.
1890 ///
1891 /// # Arguments
1892 ///
1893 /// - `Self` - Source mark line.
1894 /// - `Color` - Stroke color.
1895 ///
1896 /// # Returns
1897 ///
1898 /// - `Self` - Updated mark line.
1899 #[must_use]
1900 pub fn color(mut self, color: Color) -> Self {
1901 self.set_color(Some(color));
1902 self
1903 }
1904
1905 /// Returns the optional color override.
1906 ///
1907 /// # Arguments
1908 ///
1909 /// - `&Self` - Source mark line.
1910 ///
1911 /// # Returns
1912 ///
1913 /// - `Option<Color>` - Explicit stroke color.
1914 #[must_use]
1915 pub fn color_opt(&self) -> Option<Color> {
1916 let Self { color, .. } = *self;
1917 color
1918 }
1919}
1920
1921/// Constructors and accessors for `EuvChartMarkArea`.
1922impl EuvChartMarkArea {
1923 /// Creates a vertical highlight band spanning `start_x..=end_x`.
1924 ///
1925 /// # Arguments
1926 ///
1927 /// - `f32` - Lower X bound or category index.
1928 /// - `f32` - Upper X bound or category index.
1929 /// - `S` - Band caption.
1930 ///
1931 /// # Returns
1932 ///
1933 /// - `Self` - Vertical mark area.
1934 #[must_use]
1935 pub fn x_range<S>(start_x: f32, end_x: f32, name: S) -> Self
1936 where
1937 S: Into<String>,
1938 {
1939 Self {
1940 start_x: Some(start_x),
1941 end_x: Some(end_x),
1942 start_y: None,
1943 end_y: None,
1944 name: name.into(),
1945 color: None,
1946 }
1947 }
1948
1949 /// Creates a horizontal highlight band spanning `start_y..=end_y`.
1950 ///
1951 /// # Arguments
1952 ///
1953 /// - `f32` - Lower Y value.
1954 /// - `f32` - Upper Y value.
1955 /// - `S` - Band caption.
1956 ///
1957 /// # Returns
1958 ///
1959 /// - `Self` - Horizontal mark area.
1960 #[must_use]
1961 pub fn y_range<S>(start_y: f32, end_y: f32, name: S) -> Self
1962 where
1963 S: Into<String>,
1964 {
1965 Self {
1966 start_x: None,
1967 end_x: None,
1968 start_y: Some(start_y),
1969 end_y: Some(end_y),
1970 name: name.into(),
1971 color: None,
1972 }
1973 }
1974
1975 /// Overrides the highlight band tint color.
1976 ///
1977 /// # Arguments
1978 ///
1979 /// - `Self` - Source mark area.
1980 /// - `Color` - Band tint color.
1981 ///
1982 /// # Returns
1983 ///
1984 /// - `Self` - Updated mark area.
1985 #[must_use]
1986 pub fn color(mut self, color: Color) -> Self {
1987 self.set_color(Some(color));
1988 self
1989 }
1990
1991 /// Returns `(start_x, end_x, start_y, end_y)` bounds.
1992 ///
1993 /// # Arguments
1994 ///
1995 /// - `&Self` - Source mark area.
1996 ///
1997 /// # Returns
1998 ///
1999 /// - `(Option<f32>, Option<f32>, Option<f32>, Option<f32>)` - Optional data bounds.
2000 #[must_use]
2001 pub fn bounds_opt(&self) -> (Option<f32>, Option<f32>, Option<f32>, Option<f32>) {
2002 let Self {
2003 start_x,
2004 end_x,
2005 start_y,
2006 end_y,
2007 ..
2008 } = *self;
2009 (start_x, end_x, start_y, end_y)
2010 }
2011
2012 /// Returns the optional tint override.
2013 ///
2014 /// # Arguments
2015 ///
2016 /// - `&Self` - Source mark area.
2017 ///
2018 /// # Returns
2019 ///
2020 /// - `Option<Color>` - Explicit band tint.
2021 #[must_use]
2022 pub fn color_opt(&self) -> Option<Color> {
2023 let Self { color, .. } = *self;
2024 color
2025 }
2026}
2027
2028/// Fluent builders and accessors for `EuvChartLineSeries`.
2029impl EuvChartLineSeries {
2030 /// Creates a line series from dense numeric values.
2031 ///
2032 /// # Arguments
2033 ///
2034 /// - `Vec<f32>` - Ordered Y values.
2035 ///
2036 /// # Returns
2037 ///
2038 /// - `Self` - Line series.
2039 #[must_use]
2040 pub fn from_values(values: Vec<f32>) -> Self {
2041 let mut s: Self = Self::default();
2042 let mapped: Vec<Option<f32>> = values.into_iter().map(Some).collect();
2043 s.set_values(mapped);
2044 s
2045 }
2046
2047 /// Creates a line series supporting `None` null gaps.
2048 ///
2049 /// # Arguments
2050 ///
2051 /// - `Vec<Option<f32>>` - Nullable Y values.
2052 ///
2053 /// # Returns
2054 ///
2055 /// - `Self` - Line series.
2056 #[must_use]
2057 pub fn from_nullable(values: Vec<Option<f32>>) -> Self {
2058 let mut s: Self = Self::default();
2059 s.set_values(values);
2060 s
2061 }
2062
2063 /// Creates a line series from explicit `(x, y)` coordinate pairs.
2064 ///
2065 /// # Arguments
2066 ///
2067 /// - `Vec<(f32, f32)>` - Explicit `(x, y)` coordinates.
2068 ///
2069 /// # Returns
2070 ///
2071 /// - `Self` - Line series.
2072 #[must_use]
2073 pub fn from_xy(points: Vec<(f32, f32)>) -> Self {
2074 let mut s: Self = Self::default();
2075 s.set_xy_points(points);
2076 s
2077 }
2078
2079 /// Enables or disables smooth Catmull-Rom curve interpolation.
2080 ///
2081 /// # Arguments
2082 ///
2083 /// - `Self` - Source line series.
2084 /// - `bool` - Smooth curve flag.
2085 ///
2086 /// # Returns
2087 ///
2088 /// - `Self` - Updated line series.
2089 #[must_use]
2090 pub fn smooth(mut self, smooth: bool) -> Self {
2091 self.set_smooth(smooth);
2092 self
2093 }
2094
2095 /// Sets step-line interpolation mode.
2096 ///
2097 /// # Arguments
2098 ///
2099 /// - `Self` - Source line series.
2100 /// - `EuvChartStepMode` - Step mode.
2101 ///
2102 /// # Returns
2103 ///
2104 /// - `Self` - Updated line series.
2105 #[must_use]
2106 pub fn step(mut self, step: EuvChartStepMode) -> Self {
2107 self.set_step(step);
2108 self
2109 }
2110
2111 /// Enables translucent area shading under the line.
2112 ///
2113 /// # Arguments
2114 ///
2115 /// - `Self` - Source line series.
2116 /// - `f32` - Area fill opacity in `[0.0, 1.0]`.
2117 ///
2118 /// # Returns
2119 ///
2120 /// - `Self` - Updated line series.
2121 #[must_use]
2122 pub fn area(mut self, opacity: f32) -> Self {
2123 self.set_area_opacity(opacity.clamp(0.0, 1.0));
2124 self
2125 }
2126
2127 /// Assigns a stack group name for stacked line/area rendering.
2128 ///
2129 /// # Arguments
2130 ///
2131 /// - `Self` - Source line series.
2132 /// - `S` - Stack group key.
2133 ///
2134 /// # Returns
2135 ///
2136 /// - `Self` - Updated line series.
2137 #[must_use]
2138 pub fn stack<S>(mut self, stack: S) -> Self
2139 where
2140 S: Into<String>,
2141 {
2142 self.set_stack(Some(stack.into()));
2143 self
2144 }
2145
2146 /// Enables dashed stroke rendering.
2147 ///
2148 /// # Arguments
2149 ///
2150 /// - `Self` - Source line series.
2151 /// - `bool` - Dashed stroke flag.
2152 ///
2153 /// # Returns
2154 ///
2155 /// - `Self` - Updated line series.
2156 #[must_use]
2157 pub fn dashed(mut self, dashed: bool) -> Self {
2158 self.set_dashed(dashed);
2159 self
2160 }
2161
2162 /// Configures vertex symbol shape and radius.
2163 ///
2164 /// # Arguments
2165 ///
2166 /// - `Self` - Source line series.
2167 /// - `EuvChartSymbol` - Symbol shape.
2168 /// - `f32` - Symbol radius in logical pixels.
2169 ///
2170 /// # Returns
2171 ///
2172 /// - `Self` - Updated line series.
2173 #[must_use]
2174 pub fn symbol(mut self, symbol: EuvChartSymbol, size: f32) -> Self {
2175 self.set_symbol(symbol);
2176 self.set_symbol_size(size);
2177 self
2178 }
2179
2180 /// Controls whether `None` gaps are bridged continuously.
2181 ///
2182 /// # Arguments
2183 ///
2184 /// - `Self` - Source line series.
2185 /// - `bool` - Connect-nulls flag.
2186 ///
2187 /// # Returns
2188 ///
2189 /// - `Self` - Updated line series.
2190 #[must_use]
2191 pub fn connect_nulls(mut self, connect: bool) -> Self {
2192 self.set_connect_nulls(connect);
2193 self
2194 }
2195
2196 /// Binds the series to a specific `(x_axis_index, y_axis_index)` pair.
2197 ///
2198 /// # Arguments
2199 ///
2200 /// - `Self` - Source line series.
2201 /// - `usize` - X axis index.
2202 /// - `usize` - Y axis index.
2203 ///
2204 /// # Returns
2205 ///
2206 /// - `Self` - Updated line series.
2207 #[must_use]
2208 pub fn axes(mut self, x_axis_index: usize, y_axis_index: usize) -> Self {
2209 self.set_x_axis_index(x_axis_index);
2210 self.set_y_axis_index(y_axis_index);
2211 self
2212 }
2213
2214 /// Binds this line series to a non-default coordinate system (e.g. `Polar`).
2215 ///
2216 /// # Arguments
2217 ///
2218 /// - `Self` - Source line series.
2219 /// - `EuvChartCoordinateSystem` - Target coordinate system.
2220 ///
2221 /// # Returns
2222 ///
2223 /// - `Self` - Updated line series.
2224 #[must_use]
2225 pub fn coordinate_system(mut self, coord: EuvChartCoordinateSystem) -> Self {
2226 self.set_coordinate_system(coord);
2227 self
2228 }
2229
2230 /// Attaches a `MarkPoint` annotation.
2231 ///
2232 /// # Arguments
2233 ///
2234 /// - `Self` - Source line series.
2235 /// - `EuvChartMarkPoint` - Mark point descriptor.
2236 ///
2237 /// # Returns
2238 ///
2239 /// - `Self` - Updated line series.
2240 #[must_use]
2241 pub fn mark_point(mut self, mark: EuvChartMarkPoint) -> Self {
2242 self.get_mut_annotations().get_mut_mark_points().push(mark);
2243 self
2244 }
2245
2246 /// Attaches a `MarkLine` annotation.
2247 ///
2248 /// # Arguments
2249 ///
2250 /// - `Self` - Source line series.
2251 /// - `EuvChartMarkLine` - Mark line descriptor.
2252 ///
2253 /// # Returns
2254 ///
2255 /// - `Self` - Updated line series.
2256 #[must_use]
2257 pub fn mark_line(mut self, mark: EuvChartMarkLine) -> Self {
2258 self.get_mut_annotations().get_mut_mark_lines().push(mark);
2259 self
2260 }
2261
2262 /// Attaches a `MarkArea` annotation.
2263 ///
2264 /// # Arguments
2265 ///
2266 /// - `Self` - Source line series.
2267 /// - `EuvChartMarkArea` - Mark area descriptor.
2268 ///
2269 /// # Returns
2270 ///
2271 /// - `Self` - Updated line series.
2272 #[must_use]
2273 pub fn mark_area(mut self, mark: EuvChartMarkArea) -> Self {
2274 self.get_mut_annotations().get_mut_mark_areas().push(mark);
2275 self
2276 }
2277
2278 /// Attaches a `Dataset` column encoding mapping.
2279 ///
2280 /// # Arguments
2281 ///
2282 /// - `Self` - Source line series.
2283 /// - `EuvChartEncode` - Column mapping.
2284 ///
2285 /// # Returns
2286 ///
2287 /// - `Self` - Updated line series.
2288 #[must_use]
2289 pub fn encode(mut self, encode: EuvChartEncode) -> Self {
2290 self.set_encode(Some(encode));
2291 self
2292 }
2293
2294 /// Returns the optional stack group identifier.
2295 ///
2296 /// # Arguments
2297 ///
2298 /// - `&Self` - Line series.
2299 ///
2300 /// # Returns
2301 ///
2302 /// - `Option<&str>` - Stack group key.
2303 #[must_use]
2304 pub fn stack_opt(&self) -> Option<&str> {
2305 let Self { stack, .. } = self;
2306 stack.as_deref()
2307 }
2308
2309 /// Returns the optional dataset encode mapping.
2310 ///
2311 /// # Arguments
2312 ///
2313 /// - `&Self` - Line series.
2314 ///
2315 /// # Returns
2316 ///
2317 /// - `Option<&EuvChartEncode>` - Dataset column mapping.
2318 #[must_use]
2319 pub fn encode_opt(&self) -> Option<&EuvChartEncode> {
2320 let Self { encode, .. } = self;
2321 encode.as_ref()
2322 }
2323}
2324
2325/// Fluent builders and accessors for `EuvChartBarSeries`.
2326impl EuvChartBarSeries {
2327 /// Creates a bar series from numeric values.
2328 ///
2329 /// # Arguments
2330 ///
2331 /// - `Vec<f32>` - Ordered bar magnitudes.
2332 ///
2333 /// # Returns
2334 ///
2335 /// - `Self` - Bar series.
2336 #[must_use]
2337 pub fn from_values(values: Vec<f32>) -> Self {
2338 let mut s: Self = Self::default();
2339 let mapped: Vec<Option<f32>> = values.into_iter().map(Some).collect();
2340 s.set_values(mapped);
2341 s
2342 }
2343
2344 /// Assigns a stack group key for stacked bars.
2345 ///
2346 /// # Arguments
2347 ///
2348 /// - `Self` - Source bar series.
2349 /// - `S` - Stack group key.
2350 ///
2351 /// # Returns
2352 ///
2353 /// - `Self` - Updated bar series.
2354 #[must_use]
2355 pub fn stack<S>(mut self, stack: S) -> Self
2356 where
2357 S: Into<String>,
2358 {
2359 self.set_stack(Some(stack.into()));
2360 self
2361 }
2362
2363 /// Sets the bar cap corner radius.
2364 ///
2365 /// # Arguments
2366 ///
2367 /// - `Self` - Source bar series.
2368 /// - `f32` - Corner radius in logical pixels.
2369 ///
2370 /// # Returns
2371 ///
2372 /// - `Self` - Updated bar series.
2373 #[must_use]
2374 pub fn bar_radius(mut self, radius: f32) -> Self {
2375 self.set_bar_radius(radius.max(0.0));
2376 self
2377 }
2378
2379 /// Enables subtle background tracks behind each bar.
2380 ///
2381 /// # Arguments
2382 ///
2383 /// - `Self` - Source bar series.
2384 /// - `bool` - Background track flag.
2385 ///
2386 /// # Returns
2387 ///
2388 /// - `Self` - Updated bar series.
2389 #[must_use]
2390 pub fn show_background(mut self, show: bool) -> Self {
2391 self.set_show_background(show);
2392 self
2393 }
2394
2395 /// Enables numeric value labels on bars.
2396 ///
2397 /// # Arguments
2398 ///
2399 /// - `Self` - Source bar series.
2400 /// - `bool` - Value label flag.
2401 ///
2402 /// # Returns
2403 ///
2404 /// - `Self` - Updated bar series.
2405 #[must_use]
2406 pub fn show_labels(mut self, show: bool) -> Self {
2407 self.set_show_labels(show);
2408 self
2409 }
2410
2411 /// Binds this bar series to a coordinate system (`Cartesian2d` or `Polar`).
2412 ///
2413 /// # Arguments
2414 ///
2415 /// - `Self` - Source bar series.
2416 /// - `EuvChartCoordinateSystem` - Coordinate system.
2417 ///
2418 /// # Returns
2419 ///
2420 /// - `Self` - Updated bar series.
2421 #[must_use]
2422 pub fn coordinate_system(mut self, coord: EuvChartCoordinateSystem) -> Self {
2423 self.set_coordinate_system(coord);
2424 self
2425 }
2426
2427 /// Binds the series to a specific `(x_axis_index, y_axis_index)` pair.
2428 ///
2429 /// # Arguments
2430 ///
2431 /// - `Self` - Source bar series.
2432 /// - `usize` - X axis index.
2433 /// - `usize` - Y axis index.
2434 ///
2435 /// # Returns
2436 ///
2437 /// - `Self` - Updated bar series.
2438 #[must_use]
2439 pub fn axes(mut self, x_axis_index: usize, y_axis_index: usize) -> Self {
2440 self.set_x_axis_index(x_axis_index);
2441 self.set_y_axis_index(y_axis_index);
2442 self
2443 }
2444
2445 /// Attaches a `MarkLine` annotation.
2446 ///
2447 /// # Arguments
2448 ///
2449 /// - `Self` - Source bar series.
2450 /// - `EuvChartMarkLine` - Mark line descriptor.
2451 ///
2452 /// # Returns
2453 ///
2454 /// - `Self` - Updated bar series.
2455 #[must_use]
2456 pub fn mark_line(mut self, mark: EuvChartMarkLine) -> Self {
2457 self.get_mut_annotations().get_mut_mark_lines().push(mark);
2458 self
2459 }
2460
2461 /// Attaches a `Dataset` encode mapping.
2462 ///
2463 /// # Arguments
2464 ///
2465 /// - `Self` - Source bar series.
2466 /// - `EuvChartEncode` - Column mapping.
2467 ///
2468 /// # Returns
2469 ///
2470 /// - `Self` - Updated bar series.
2471 #[must_use]
2472 pub fn encode(mut self, encode: EuvChartEncode) -> Self {
2473 self.set_encode(Some(encode));
2474 self
2475 }
2476
2477 /// Returns the optional stack group key.
2478 ///
2479 /// # Arguments
2480 ///
2481 /// - `&Self` - Bar series.
2482 ///
2483 /// # Returns
2484 ///
2485 /// - `Option<&str>` - Stack group key.
2486 #[must_use]
2487 pub fn stack_opt(&self) -> Option<&str> {
2488 let Self { stack, .. } = self;
2489 stack.as_deref()
2490 }
2491
2492 /// Returns the optional dataset encode mapping.
2493 ///
2494 /// # Arguments
2495 ///
2496 /// - `&Self` - Bar series.
2497 ///
2498 /// # Returns
2499 ///
2500 /// - `Option<&EuvChartEncode>` - Dataset column mapping.
2501 #[must_use]
2502 pub fn encode_opt(&self) -> Option<&EuvChartEncode> {
2503 let Self { encode, .. } = self;
2504 encode.as_ref()
2505 }
2506}
2507
2508/// Constructors and accessors for `EuvChartPieSlice` and `EuvChartPieSeries`.
2509impl EuvChartPieSlice {
2510 /// Creates a labeled pie slice.
2511 ///
2512 /// # Arguments
2513 ///
2514 /// - `S` - Slice label.
2515 /// - `f32` - Positive numeric weight.
2516 ///
2517 /// # Returns
2518 ///
2519 /// - `Self` - Pie slice.
2520 #[must_use]
2521 pub fn new<S>(name: S, value: f32) -> Self
2522 where
2523 S: Into<String>,
2524 {
2525 Self {
2526 name: name.into(),
2527 value,
2528 color: None,
2529 selected: false,
2530 }
2531 }
2532
2533 /// Sets an explicit fill color for this slice.
2534 ///
2535 /// # Arguments
2536 ///
2537 /// - `Self` - Source slice.
2538 /// - `Color` - Fill color.
2539 ///
2540 /// # Returns
2541 ///
2542 /// - `Self` - Updated slice.
2543 #[must_use]
2544 pub fn color(mut self, color: Color) -> Self {
2545 self.set_color(Some(color));
2546 self
2547 }
2548
2549 /// Marks this slice as popped out radially.
2550 ///
2551 /// # Arguments
2552 ///
2553 /// - `Self` - Source slice.
2554 /// - `bool` - Selected pop-out state.
2555 ///
2556 /// # Returns
2557 ///
2558 /// - `Self` - Updated slice.
2559 #[must_use]
2560 pub fn selected(mut self, selected: bool) -> Self {
2561 self.set_selected(selected);
2562 self
2563 }
2564
2565 /// Returns the optional explicit slice color.
2566 ///
2567 /// # Arguments
2568 ///
2569 /// - `&Self` - Source slice.
2570 ///
2571 /// # Returns
2572 ///
2573 /// - `Option<Color>` - Explicit fill color.
2574 #[must_use]
2575 pub fn color_opt(&self) -> Option<Color> {
2576 let Self { color, .. } = *self;
2577 color
2578 }
2579}
2580
2581/// Fluent builders for `EuvChartPieSeries`.
2582impl EuvChartPieSeries {
2583 /// Creates a pie series from slices.
2584 ///
2585 /// # Arguments
2586 ///
2587 /// - `Vec<EuvChartPieSlice>` - Ordered pie slices.
2588 ///
2589 /// # Returns
2590 ///
2591 /// - `Self` - Pie series.
2592 #[must_use]
2593 pub fn new(slices: Vec<EuvChartPieSlice>) -> Self {
2594 let mut s: Self = Self::default();
2595 s.set_slices(slices);
2596 s
2597 }
2598
2599 /// Converts the pie into a donut chart with the given inner cutout ratio.
2600 ///
2601 /// # Arguments
2602 ///
2603 /// - `Self` - Source pie series.
2604 /// - `f32` - Inner radius ratio in `[0.0, 0.85]`.
2605 ///
2606 /// # Returns
2607 ///
2608 /// - `Self` - Updated pie series.
2609 #[must_use]
2610 pub fn donut(mut self, inner_ratio: f32) -> Self {
2611 self.set_inner_radius_ratio(inner_ratio.clamp(0.0, 0.85));
2612 self
2613 }
2614
2615 /// Sets Nightingale Rose mode (`Radius` or `Area`).
2616 ///
2617 /// # Arguments
2618 ///
2619 /// - `Self` - Source pie series.
2620 /// - `EuvChartRoseType` - Rose variation mode.
2621 ///
2622 /// # Returns
2623 ///
2624 /// - `Self` - Updated pie series.
2625 #[must_use]
2626 pub fn rose(mut self, rose_type: EuvChartRoseType) -> Self {
2627 self.set_rose_type(rose_type);
2628 self
2629 }
2630
2631 /// Sets angular gap between adjacent wedges in degrees.
2632 ///
2633 /// # Arguments
2634 ///
2635 /// - `Self` - Source pie series.
2636 /// - `f32` - Pad angle in degrees.
2637 ///
2638 /// # Returns
2639 ///
2640 /// - `Self` - Updated pie series.
2641 #[must_use]
2642 pub fn pad_angle(mut self, deg: f32) -> Self {
2643 self.set_pad_angle_deg(deg.clamp(0.0, 15.0));
2644 self
2645 }
2646}
2647
2648/// Constructors and accessors for `EuvChartScatterPoint` and `EuvChartScatterSeries`.
2649impl EuvChartScatterPoint {
2650 /// Creates a 2D scatter point `(x, y)` using the series default size.
2651 ///
2652 /// # Arguments
2653 ///
2654 /// - `f32` - X coordinate.
2655 /// - `f32` - Y coordinate.
2656 ///
2657 /// # Returns
2658 ///
2659 /// - `Self` - Scatter point.
2660 #[must_use]
2661 pub fn new(x: f32, y: f32) -> Self {
2662 Self {
2663 x,
2664 y,
2665 size: 0.0,
2666 value: None,
2667 label: String::new(),
2668 }
2669 }
2670
2671 /// Sets an explicit bubble radius in logical pixels.
2672 ///
2673 /// # Arguments
2674 ///
2675 /// - `Self` - Source scatter point.
2676 /// - `f32` - Bubble radius.
2677 ///
2678 /// # Returns
2679 ///
2680 /// - `Self` - Updated scatter point.
2681 #[must_use]
2682 pub fn size(mut self, size: f32) -> Self {
2683 self.set_size(size);
2684 self
2685 }
2686
2687 /// Sets a scalar value for `VisualMap` coloring.
2688 ///
2689 /// # Arguments
2690 ///
2691 /// - `Self` - Source scatter point.
2692 /// - `f32` - Mapped numeric value.
2693 ///
2694 /// # Returns
2695 ///
2696 /// - `Self` - Updated scatter point.
2697 #[must_use]
2698 pub fn value(mut self, value: f32) -> Self {
2699 self.set_value(Some(value));
2700 self
2701 }
2702
2703 /// Sets a point caption label.
2704 ///
2705 /// # Arguments
2706 ///
2707 /// - `Self` - Source scatter point.
2708 /// - `S` - Caption text.
2709 ///
2710 /// # Returns
2711 ///
2712 /// - `Self` - Updated scatter point.
2713 #[must_use]
2714 pub fn label<S>(mut self, label: S) -> Self
2715 where
2716 S: Into<String>,
2717 {
2718 self.set_label(label.into());
2719 self
2720 }
2721
2722 /// Returns the optional visual-map scalar value.
2723 ///
2724 /// # Arguments
2725 ///
2726 /// - `&Self` - Source scatter point.
2727 ///
2728 /// # Returns
2729 ///
2730 /// - `Option<f32>` - Mapped numeric value.
2731 #[must_use]
2732 pub fn value_opt(&self) -> Option<f32> {
2733 let Self { value, .. } = *self;
2734 value
2735 }
2736}
2737
2738/// Fluent builders for `EuvChartScatterSeries`.
2739impl EuvChartScatterSeries {
2740 /// Creates a scatter series from `(x, y)` points.
2741 ///
2742 /// # Arguments
2743 ///
2744 /// - `Vec<EuvChartScatterPoint>` - Scatter points.
2745 ///
2746 /// # Returns
2747 ///
2748 /// - `Self` - Scatter series.
2749 #[must_use]
2750 pub fn new(points: Vec<EuvChartScatterPoint>) -> Self {
2751 let mut s: Self = Self::default();
2752 s.set_points(points);
2753 s
2754 }
2755
2756 /// Sets marker glyph shape and default radius.
2757 ///
2758 /// # Arguments
2759 ///
2760 /// - `Self` - Source scatter series.
2761 /// - `EuvChartSymbol` - Symbol shape.
2762 /// - `f32` - Default radius in logical pixels.
2763 ///
2764 /// # Returns
2765 ///
2766 /// - `Self` - Updated scatter series.
2767 #[must_use]
2768 pub fn symbol(mut self, symbol: EuvChartSymbol, size: f32) -> Self {
2769 self.set_symbol(symbol);
2770 self.set_default_size(size.max(1.0));
2771 self
2772 }
2773
2774 /// Binds this scatter series to a coordinate system (`Cartesian2d`, `Polar`, `SingleAxis`, or `Geo`).
2775 ///
2776 /// # Arguments
2777 ///
2778 /// - `Self` - Source scatter series.
2779 /// - `EuvChartCoordinateSystem` - Hosting coordinate system.
2780 ///
2781 /// # Returns
2782 ///
2783 /// - `Self` - Updated scatter series.
2784 #[must_use]
2785 pub fn coordinate_system(mut self, coord: EuvChartCoordinateSystem) -> Self {
2786 self.set_coordinate_system(coord);
2787 self
2788 }
2789
2790 /// Enables point caption labels.
2791 ///
2792 /// # Arguments
2793 ///
2794 /// - `Self` - Source scatter series.
2795 /// - `bool` - Label visibility flag.
2796 ///
2797 /// # Returns
2798 ///
2799 /// - `Self` - Updated scatter series.
2800 #[must_use]
2801 pub fn show_labels(mut self, show: bool) -> Self {
2802 self.set_show_labels(show);
2803 self
2804 }
2805
2806 /// Attaches a dataset column encoding mapping.
2807 ///
2808 /// # Arguments
2809 ///
2810 /// - `Self` - Source scatter series.
2811 /// - `EuvChartEncode` - Column mapping.
2812 ///
2813 /// # Returns
2814 ///
2815 /// - `Self` - Updated scatter series.
2816 #[must_use]
2817 pub fn encode(mut self, encode: EuvChartEncode) -> Self {
2818 self.set_encode(Some(encode));
2819 self
2820 }
2821
2822 /// Returns the optional dataset encode mapping.
2823 ///
2824 /// # Arguments
2825 ///
2826 /// - `&Self` - Source scatter series.
2827 ///
2828 /// # Returns
2829 ///
2830 /// - `Option<&EuvChartEncode>` - Dataset column mapping.
2831 #[must_use]
2832 pub fn encode_opt(&self) -> Option<&EuvChartEncode> {
2833 let Self { encode, .. } = self;
2834 encode.as_ref()
2835 }
2836}
2837
2838/// Constructors and accessors for `EuvChartRadarItem` and `EuvChartRadarSeries`.
2839impl EuvChartRadarItem {
2840 /// Creates a radar polygon record.
2841 ///
2842 /// # Arguments
2843 ///
2844 /// - `S` - Item display name.
2845 /// - `Vec<f32>` - Values aligned to radar indicators.
2846 ///
2847 /// # Returns
2848 ///
2849 /// - `Self` - Radar item.
2850 #[must_use]
2851 pub fn new<S>(name: S, values: Vec<f32>) -> Self
2852 where
2853 S: Into<String>,
2854 {
2855 Self {
2856 name: name.into(),
2857 values,
2858 color: None,
2859 }
2860 }
2861
2862 /// Sets an explicit polygon color.
2863 ///
2864 /// # Arguments
2865 ///
2866 /// - `Self` - Source radar item.
2867 /// - `Color` - Stroke and tint color.
2868 ///
2869 /// # Returns
2870 ///
2871 /// - `Self` - Updated radar item.
2872 #[must_use]
2873 pub fn color(mut self, color: Color) -> Self {
2874 self.set_color(Some(color));
2875 self
2876 }
2877
2878 /// Returns the optional explicit color.
2879 ///
2880 /// # Arguments
2881 ///
2882 /// - `&Self` - Source radar item.
2883 ///
2884 /// # Returns
2885 ///
2886 /// - `Option<Color>` - Explicit polygon color.
2887 #[must_use]
2888 pub fn color_opt(&self) -> Option<Color> {
2889 let Self { color, .. } = *self;
2890 color
2891 }
2892}
2893
2894/// Fluent constructors for `EuvChartRadarSeries`.
2895impl EuvChartRadarSeries {
2896 /// Creates a radar series from multivariate items.
2897 ///
2898 /// # Arguments
2899 ///
2900 /// - `Vec<EuvChartRadarItem>` - Radar polygon records.
2901 ///
2902 /// # Returns
2903 ///
2904 /// - `Self` - Radar series.
2905 #[must_use]
2906 pub fn new(items: Vec<EuvChartRadarItem>) -> Self {
2907 let mut s: Self = Self::default();
2908 s.set_items(items);
2909 s
2910 }
2911}
2912
2913/// Fluent builders and accessors for `EuvChartCandlestickSeries`.
2914impl EuvChartCandlestickSeries {
2915 /// Creates a candlestick series from OHLC records.
2916 ///
2917 /// # Arguments
2918 ///
2919 /// - `Vec<EuvChartOhlcPoint>` - Ordered OHLC candles.
2920 ///
2921 /// # Returns
2922 ///
2923 /// - `Self` - Candlestick series.
2924 #[must_use]
2925 pub fn new(candles: Vec<EuvChartOhlcPoint>) -> Self {
2926 let mut s: Self = Self::default();
2927 s.set_candles(candles);
2928 s
2929 }
2930
2931 /// Overrides the bullish and bearish candle fill colors.
2932 ///
2933 /// # Arguments
2934 ///
2935 /// - `Self` - Source candlestick series.
2936 /// - `Color` - Bullish color (`close >= open`).
2937 /// - `Color` - Bearish color (`close < open`).
2938 ///
2939 /// # Returns
2940 ///
2941 /// - `Self` - Updated candlestick series.
2942 #[must_use]
2943 pub fn colors(mut self, bull: Color, bear: Color) -> Self {
2944 self.set_bull_color(Some(bull));
2945 self.set_bear_color(Some(bear));
2946 self
2947 }
2948
2949 /// Returns the resolved bullish candle color.
2950 ///
2951 /// # Arguments
2952 ///
2953 /// - `&Self` - Candlestick series.
2954 ///
2955 /// # Returns
2956 ///
2957 /// - `Color` - Bullish fill color.
2958 #[must_use]
2959 pub fn resolved_bull_color(&self) -> Color {
2960 let Self { bull_color, .. } = *self;
2961 bull_color.unwrap_or_else(|| Color::hex(ECHART_CANDLE_BULL_HEX))
2962 }
2963
2964 /// Returns the resolved bearish candle color.
2965 ///
2966 /// # Arguments
2967 ///
2968 /// - `&Self` - Candlestick series.
2969 ///
2970 /// # Returns
2971 ///
2972 /// - `Color` - Bearish fill color.
2973 #[must_use]
2974 pub fn resolved_bear_color(&self) -> Color {
2975 let Self { bear_color, .. } = *self;
2976 bear_color.unwrap_or_else(|| Color::hex(ECHART_CANDLE_BEAR_HEX))
2977 }
2978}
2979
2980/// Constructors for `EuvChartBoxplotItem` and `EuvChartBoxplotSeries`.
2981impl EuvChartBoxplotItem {
2982 /// Creates a five-number boxplot summary without outliers.
2983 ///
2984 /// # Arguments
2985 ///
2986 /// - `f32` - Lower whisker minimum.
2987 /// - `f32` - First quartile.
2988 /// - `f32` - Median value.
2989 /// - `f32` - Third quartile.
2990 /// - `f32` - Upper whisker maximum.
2991 ///
2992 /// # Returns
2993 ///
2994 /// - `Self` - Boxplot summary item.
2995 #[must_use]
2996 pub fn new(min: f32, q1: f32, median: f32, q3: f32, max: f32) -> Self {
2997 Self {
2998 min,
2999 q1,
3000 median,
3001 q3,
3002 max,
3003 outliers: Vec::new(),
3004 }
3005 }
3006
3007 /// Attaches outlier scalar values plotted above/below the whiskers.
3008 ///
3009 /// # Arguments
3010 ///
3011 /// - `Self` - Source boxplot item.
3012 /// - `Vec<f32>` - Outlier observations.
3013 ///
3014 /// # Returns
3015 ///
3016 /// - `Self` - Updated boxplot item.
3017 #[must_use]
3018 pub fn outliers(mut self, outliers: Vec<f32>) -> Self {
3019 self.set_outliers(outliers);
3020 self
3021 }
3022}
3023
3024/// Constructors for `EuvChartBoxplotSeries`.
3025impl EuvChartBoxplotSeries {
3026 /// Creates a boxplot series from summary items.
3027 ///
3028 /// # Arguments
3029 ///
3030 /// - `Vec<EuvChartBoxplotItem>` - Ordered boxplot summaries.
3031 ///
3032 /// # Returns
3033 ///
3034 /// - `Self` - Boxplot series.
3035 #[must_use]
3036 pub fn new(items: Vec<EuvChartBoxplotItem>) -> Self {
3037 let mut s: Self = Self::default();
3038 s.set_items(items);
3039 s
3040 }
3041}
3042
3043/// Constructors for `EuvChartHeatmapCell` and `EuvChartHeatmapSeries`.
3044impl EuvChartHeatmapCell {
3045 /// Creates a heatmap cell at `(x_index, y_index)` with `value`.
3046 ///
3047 /// # Arguments
3048 ///
3049 /// - `usize` - Column index.
3050 /// - `usize` - Row index.
3051 /// - `f32` - Numeric intensity.
3052 ///
3053 /// # Returns
3054 ///
3055 /// - `Self` - Heatmap cell.
3056 #[must_use]
3057 pub fn new(x_index: usize, y_index: usize, value: f32) -> Self {
3058 Self {
3059 x_index,
3060 y_index,
3061 value,
3062 label: String::new(),
3063 }
3064 }
3065}
3066
3067/// Fluent constructors for `EuvChartHeatmapSeries`.
3068impl EuvChartHeatmapSeries {
3069 /// Creates a Cartesian matrix heatmap series.
3070 ///
3071 /// # Arguments
3072 ///
3073 /// - `Vec<EuvChartHeatmapCell>` - Matrix cells.
3074 ///
3075 /// # Returns
3076 ///
3077 /// - `Self` - Heatmap series.
3078 #[must_use]
3079 pub fn new(cells: Vec<EuvChartHeatmapCell>) -> Self {
3080 let mut s: Self = Self::default();
3081 s.set_cells(cells);
3082 s
3083 }
3084
3085 /// Binds this heatmap to `Calendar` or `Cartesian2d` coordinates.
3086 ///
3087 /// # Arguments
3088 ///
3089 /// - `Self` - Source heatmap series.
3090 /// - `EuvChartCoordinateSystem` - Coordinate system.
3091 ///
3092 /// # Returns
3093 ///
3094 /// - `Self` - Updated heatmap series.
3095 #[must_use]
3096 pub fn coordinate_system(mut self, coord: EuvChartCoordinateSystem) -> Self {
3097 self.set_coordinate_system(coord);
3098 self
3099 }
3100
3101 /// Toggles numeric cell value captions.
3102 ///
3103 /// # Arguments
3104 ///
3105 /// - `Self` - Source heatmap series.
3106 /// - `bool` - Cell label flag.
3107 ///
3108 /// # Returns
3109 ///
3110 /// - `Self` - Updated heatmap series.
3111 #[must_use]
3112 pub fn show_labels(mut self, show: bool) -> Self {
3113 self.set_show_labels(show);
3114 self
3115 }
3116}
3117
3118/// Constructors and recursive aggregation helpers for `EuvChartHierarchyNode`.
3119impl EuvChartHierarchyNode {
3120 /// Creates a leaf hierarchy node with numeric `value`.
3121 ///
3122 /// # Arguments
3123 ///
3124 /// - `S` - Node display label.
3125 /// - `f32` - Positive numeric weight.
3126 ///
3127 /// # Returns
3128 ///
3129 /// - `Self` - Leaf node.
3130 #[must_use]
3131 pub fn leaf<S>(name: S, value: f32) -> Self
3132 where
3133 S: Into<String>,
3134 {
3135 Self {
3136 name: name.into(),
3137 value,
3138 color: None,
3139 children: Vec::new(),
3140 }
3141 }
3142
3143 /// Creates a parent branch hierarchy node wrapping `children`.
3144 ///
3145 /// # Arguments
3146 ///
3147 /// - `S` - Branch display label.
3148 /// - `Vec<Self>` - Nested child nodes.
3149 ///
3150 /// # Returns
3151 ///
3152 /// - `Self` - Branch node whose weight sums its children.
3153 #[must_use]
3154 pub fn branch<S>(name: S, children: Vec<Self>) -> Self
3155 where
3156 S: Into<String>,
3157 {
3158 let total: f32 = children.iter().map(Self::total_value).sum();
3159 Self {
3160 name: name.into(),
3161 value: total,
3162 color: None,
3163 children,
3164 }
3165 }
3166
3167 /// Overrides the node tint color.
3168 ///
3169 /// # Arguments
3170 ///
3171 /// - `Self` - Source hierarchy node.
3172 /// - `Color` - Explicit node color.
3173 ///
3174 /// # Returns
3175 ///
3176 /// - `Self` - Updated hierarchy node.
3177 #[must_use]
3178 pub fn color(mut self, color: Color) -> Self {
3179 self.set_color(Some(color));
3180 self
3181 }
3182
3183 /// Returns the optional explicit color tint.
3184 ///
3185 /// # Arguments
3186 ///
3187 /// - `&Self` - Source hierarchy node.
3188 ///
3189 /// # Returns
3190 ///
3191 /// - `Option<Color>` - Explicit node color.
3192 #[must_use]
3193 pub fn color_opt(&self) -> Option<Color> {
3194 let Self { color, .. } = *self;
3195 color
3196 }
3197
3198 /// Computes total positive weight recursively for treemap and sunburst proportionality.
3199 ///
3200 /// # Arguments
3201 ///
3202 /// - `&Self` - Hierarchy node.
3203 ///
3204 /// # Returns
3205 ///
3206 /// - `f32` - Positive aggregated weight.
3207 #[must_use]
3208 pub fn total_value(&self) -> f32 {
3209 let children: &[Self] = self.get_children().as_slice();
3210 if children.is_empty() {
3211 self.get_value().max(0.0)
3212 } else {
3213 let sum: f32 = children.iter().map(Self::total_value).sum();
3214 sum.max(self.get_value().max(0.0))
3215 }
3216 }
3217
3218 /// Returns the maximum subtree depth (`1` for a leaf).
3219 ///
3220 /// # Arguments
3221 ///
3222 /// - `&Self` - Hierarchy node.
3223 ///
3224 /// # Returns
3225 ///
3226 /// - `usize` - Subtree depth.
3227 #[must_use]
3228 pub fn max_depth(&self) -> usize {
3229 let children: &[Self] = self.get_children().as_slice();
3230 if children.is_empty() {
3231 1
3232 } else {
3233 let deepest: usize = children.iter().map(Self::max_depth).max().unwrap_or(0);
3234 1 + deepest
3235 }
3236 }
3237}
3238
3239/// Constructors for `EuvChartTreemapSeries`, `EuvChartSunburstSeries`, `EuvChartSankeySeries`, `EuvChartFunnelSeries`, `EuvChartGaugeSeries`, `EuvChartGraphSeries`, `EuvChartTreeSeries`, `EuvChartParallelSeries`, `EuvChartLinesSeries`, `EuvChartThemeRiverSeries`, `EuvChartPictorialBarSeries`, `EuvChartCustomSeries`, and `EuvChartGeoMapSeries`.
3240impl EuvChartTreemapSeries {
3241 /// Creates a treemap series from top-level nodes.
3242 ///
3243 /// # Arguments
3244 ///
3245 /// - `Vec<EuvChartHierarchyNode>` - Top-level hierarchy nodes.
3246 ///
3247 /// # Returns
3248 ///
3249 /// - `Self` - Treemap series.
3250 #[must_use]
3251 pub fn new(nodes: Vec<EuvChartHierarchyNode>) -> Self {
3252 let mut s: Self = Self::default();
3253 s.set_nodes(nodes);
3254 s
3255 }
3256}
3257
3258/// Constructors for `EuvChartSunburstSeries`.
3259impl EuvChartSunburstSeries {
3260 /// Creates a sunburst series from top-level nodes.
3261 ///
3262 /// # Arguments
3263 ///
3264 /// - `Vec<EuvChartHierarchyNode>` - Top-level hierarchy nodes.
3265 ///
3266 /// # Returns
3267 ///
3268 /// - `Self` - Sunburst series.
3269 #[must_use]
3270 pub fn new(nodes: Vec<EuvChartHierarchyNode>) -> Self {
3271 let mut s: Self = Self::default();
3272 s.set_nodes(nodes);
3273 s
3274 }
3275}
3276
3277/// Constructors and accessors for `EuvChartSankeyNode` and `EuvChartSankeySeries`.
3278impl EuvChartSankeyNode {
3279 /// Creates a named Sankey node.
3280 ///
3281 /// # Arguments
3282 ///
3283 /// - `S` - Node identifier name.
3284 ///
3285 /// # Returns
3286 ///
3287 /// - `Self` - Sankey node.
3288 #[must_use]
3289 pub fn new<S>(name: S) -> Self
3290 where
3291 S: Into<String>,
3292 {
3293 Self {
3294 name: name.into(),
3295 color: None,
3296 depth: None,
3297 }
3298 }
3299
3300 /// Overrides the node fill color.
3301 ///
3302 /// # Arguments
3303 ///
3304 /// - `Self` - Source node.
3305 /// - `Color` - Fill color.
3306 ///
3307 /// # Returns
3308 ///
3309 /// - `Self` - Updated node.
3310 #[must_use]
3311 pub fn color(mut self, color: Color) -> Self {
3312 self.set_color(Some(color));
3313 self
3314 }
3315
3316 /// Returns the optional explicit node color.
3317 ///
3318 /// # Arguments
3319 ///
3320 /// - `&Self` - Source node.
3321 ///
3322 /// # Returns
3323 ///
3324 /// - `Option<Color>` - Explicit node color.
3325 #[must_use]
3326 pub fn color_opt(&self) -> Option<Color> {
3327 let Self { color, .. } = *self;
3328 color
3329 }
3330
3331 /// Returns the optional explicit column depth.
3332 ///
3333 /// # Arguments
3334 ///
3335 /// - `&Self` - Source node.
3336 ///
3337 /// # Returns
3338 ///
3339 /// - `Option<usize>` - Explicit column depth.
3340 #[must_use]
3341 pub fn depth_opt(&self) -> Option<usize> {
3342 let Self { depth, .. } = *self;
3343 depth
3344 }
3345}
3346
3347/// Constructors for `EuvChartSankeySeries`.
3348impl EuvChartSankeySeries {
3349 /// Creates a Sankey diagram from nodes and weighted links.
3350 ///
3351 /// # Arguments
3352 ///
3353 /// - `Vec<EuvChartSankeyNode>` - Sankey nodes.
3354 /// - `Vec<EuvChartSankeyLink>` - Weighted flow links.
3355 ///
3356 /// # Returns
3357 ///
3358 /// - `Self` - Sankey series.
3359 #[must_use]
3360 pub fn new(nodes: Vec<EuvChartSankeyNode>, links: Vec<EuvChartSankeyLink>) -> Self {
3361 let mut s: Self = Self::default();
3362 s.set_nodes(nodes);
3363 s.set_links(links);
3364 s
3365 }
3366}
3367
3368/// Constructors and accessors for `EuvChartFunnelStage` and `EuvChartFunnelSeries`.
3369impl EuvChartFunnelStage {
3370 /// Creates a conversion funnel stage.
3371 ///
3372 /// # Arguments
3373 ///
3374 /// - `S` - Stage display name.
3375 /// - `f32` - Positive stage weight.
3376 ///
3377 /// # Returns
3378 ///
3379 /// - `Self` - Funnel stage.
3380 #[must_use]
3381 pub fn new<S>(name: S, value: f32) -> Self
3382 where
3383 S: Into<String>,
3384 {
3385 Self {
3386 name: name.into(),
3387 value,
3388 color: None,
3389 }
3390 }
3391
3392 /// Returns the optional explicit stage color.
3393 ///
3394 /// # Arguments
3395 ///
3396 /// - `&Self` - Source stage.
3397 ///
3398 /// # Returns
3399 ///
3400 /// - `Option<Color>` - Explicit stage color.
3401 #[must_use]
3402 pub fn color_opt(&self) -> Option<Color> {
3403 let Self { color, .. } = *self;
3404 color
3405 }
3406}
3407
3408/// Constructors for `EuvChartFunnelSeries`.
3409impl EuvChartFunnelSeries {
3410 /// Creates a funnel series from conversion stages.
3411 ///
3412 /// # Arguments
3413 ///
3414 /// - `Vec<EuvChartFunnelStage>` - Ordered conversion stages.
3415 ///
3416 /// # Returns
3417 ///
3418 /// - `Self` - Funnel series.
3419 #[must_use]
3420 pub fn new(stages: Vec<EuvChartFunnelStage>) -> Self {
3421 let mut s: Self = Self::default();
3422 s.set_stages(stages);
3423 s
3424 }
3425
3426 /// Sets vertical funnel sorting order.
3427 ///
3428 /// # Arguments
3429 ///
3430 /// - `Self` - Source funnel series.
3431 /// - `EuvChartFunnelSort` - Sorting mode.
3432 ///
3433 /// # Returns
3434 ///
3435 /// - `Self` - Updated funnel series.
3436 #[must_use]
3437 pub fn sort(mut self, sort: EuvChartFunnelSort) -> Self {
3438 self.set_sort(sort);
3439 self
3440 }
3441}
3442
3443/// Fluent constructors for `EuvChartGaugeSeries`.
3444impl EuvChartGaugeSeries {
3445 /// Creates a gauge reading `value` over `[min, max]`.
3446 ///
3447 /// # Arguments
3448 ///
3449 /// - `f32` - Active numeric reading.
3450 /// - `f32` - Lower dial bound.
3451 /// - `f32` - Upper dial bound.
3452 ///
3453 /// # Returns
3454 ///
3455 /// - `Self` - Gauge series.
3456 #[must_use]
3457 pub fn new(value: f32, min: f32, max: f32) -> Self {
3458 let mut g: Self = Self::default();
3459 g.set_value(value);
3460 g.set_min(min);
3461 g.set_max(max);
3462 g
3463 }
3464
3465 /// Sets the center unit suffix string.
3466 ///
3467 /// # Arguments
3468 ///
3469 /// - `Self` - Source gauge.
3470 /// - `S` - Unit text.
3471 ///
3472 /// # Returns
3473 ///
3474 /// - `Self` - Updated gauge.
3475 #[must_use]
3476 pub fn unit<S>(mut self, unit: S) -> Self
3477 where
3478 S: Into<String>,
3479 {
3480 self.set_unit(unit.into());
3481 self
3482 }
3483
3484 /// Sets the dial caption title.
3485 ///
3486 /// # Arguments
3487 ///
3488 /// - `Self` - Source gauge.
3489 /// - `S` - Caption text.
3490 ///
3491 /// # Returns
3492 ///
3493 /// - `Self` - Updated gauge.
3494 #[must_use]
3495 pub fn title<S>(mut self, title: S) -> Self
3496 where
3497 S: Into<String>,
3498 {
3499 self.set_title(title.into());
3500 self
3501 }
3502
3503 /// Sets custom arc start and end angles in degrees.
3504 ///
3505 /// # Arguments
3506 ///
3507 /// - `Self` - Source gauge.
3508 /// - `f32` - Start angle in degrees.
3509 /// - `f32` - End angle in degrees.
3510 ///
3511 /// # Returns
3512 ///
3513 /// - `Self` - Updated gauge.
3514 #[must_use]
3515 pub fn angles(mut self, start_deg: f32, end_deg: f32) -> Self {
3516 self.set_start_angle_deg(start_deg);
3517 self.set_end_angle_deg(end_deg);
3518 self
3519 }
3520}
3521
3522/// Constructors and accessors for `EuvChartGraphNode`, `EuvChartGraphEdge`, and `EuvChartGraphSeries`.
3523impl EuvChartGraphNode {
3524 /// Creates a graph vertex with `id`, `name`, radius `size`, and `category`.
3525 ///
3526 /// # Arguments
3527 ///
3528 /// - `I` - Unique node identifier.
3529 /// - `N` - Display caption.
3530 /// - `f32` - Visual radius in logical pixels.
3531 /// - `usize` - Category index.
3532 ///
3533 /// # Returns
3534 ///
3535 /// - `Self` - Graph node.
3536 #[must_use]
3537 pub fn new<I, N>(id: I, name: N, size: f32, category: usize) -> Self
3538 where
3539 I: Into<String>,
3540 N: Into<String>,
3541 {
3542 Self {
3543 id: id.into(),
3544 name: name.into(),
3545 value: size,
3546 size: size.max(4.0),
3547 category,
3548 x: None,
3549 y: None,
3550 color: None,
3551 }
3552 }
3553
3554 /// Returns optional pre-assigned `(x, y)` normalized coordinates.
3555 ///
3556 /// # Arguments
3557 ///
3558 /// - `&Self` - Source graph node.
3559 ///
3560 /// # Returns
3561 ///
3562 /// - `(Option<f32>, Option<f32>)` - Optional preset position.
3563 #[must_use]
3564 pub fn pos_opt(&self) -> (Option<f32>, Option<f32>) {
3565 let Self { x, y, .. } = *self;
3566 (x, y)
3567 }
3568
3569 /// Returns optional explicit vertex color.
3570 ///
3571 /// # Arguments
3572 ///
3573 /// - `&Self` - Source graph node.
3574 ///
3575 /// # Returns
3576 ///
3577 /// - `Option<Color>` - Explicit node color.
3578 #[must_use]
3579 pub fn color_opt(&self) -> Option<Color> {
3580 let Self { color, .. } = *self;
3581 color
3582 }
3583}
3584
3585/// Constructors for `EuvChartGraphEdge`.
3586impl EuvChartGraphEdge {
3587 /// Creates an edge connecting `source` and `target`.
3588 ///
3589 /// # Arguments
3590 ///
3591 /// - `S` - Source node id.
3592 /// - `T` - Target node id.
3593 ///
3594 /// # Returns
3595 ///
3596 /// - `Self` - Graph edge.
3597 #[must_use]
3598 pub fn new<S, T>(source: S, target: T) -> Self
3599 where
3600 S: Into<String>,
3601 T: Into<String>,
3602 {
3603 Self {
3604 source: source.into(),
3605 target: target.into(),
3606 weight: 1.5,
3607 label: String::new(),
3608 curveness: 0.14,
3609 }
3610 }
3611
3612 /// Sets edge curve bow ratio (`0.0` = straight).
3613 ///
3614 /// # Arguments
3615 ///
3616 /// - `Self` - Source edge.
3617 /// - `f32` - Curveness ratio.
3618 ///
3619 /// # Returns
3620 ///
3621 /// - `Self` - Updated edge.
3622 #[must_use]
3623 pub fn curveness(mut self, curveness: f32) -> Self {
3624 self.set_curveness(curveness);
3625 self
3626 }
3627}
3628
3629/// Constructors for `EuvChartGraphSeries`.
3630impl EuvChartGraphSeries {
3631 /// Creates a network graph series from vertices and edges.
3632 ///
3633 /// # Arguments
3634 ///
3635 /// - `Vec<EuvChartGraphNode>` - Vertices.
3636 /// - `Vec<EuvChartGraphEdge>` - Edges.
3637 ///
3638 /// # Returns
3639 ///
3640 /// - `Self` - Graph series.
3641 #[must_use]
3642 pub fn new(nodes: Vec<EuvChartGraphNode>, edges: Vec<EuvChartGraphEdge>) -> Self {
3643 let mut s: Self = Self::default();
3644 s.set_nodes(nodes);
3645 s.set_edges(edges);
3646 s
3647 }
3648
3649 /// Selects the graph layout algorithm (`Force`, `Circular`, or `None`).
3650 ///
3651 /// # Arguments
3652 ///
3653 /// - `Self` - Source graph series.
3654 /// - `EuvChartGraphLayout` - Layout strategy.
3655 ///
3656 /// # Returns
3657 ///
3658 /// - `Self` - Updated graph series.
3659 #[must_use]
3660 pub fn layout(mut self, layout: EuvChartGraphLayout) -> Self {
3661 self.set_layout(layout);
3662 self
3663 }
3664}
3665
3666/// Constructors for `EuvChartTreeSeries`.
3667impl EuvChartTreeSeries {
3668 /// Creates a tree series rooted at `root`.
3669 ///
3670 /// # Arguments
3671 ///
3672 /// - `EuvChartHierarchyNode` - Tree root node.
3673 ///
3674 /// # Returns
3675 ///
3676 /// - `Self` - Tree series.
3677 #[must_use]
3678 pub fn new(root: EuvChartHierarchyNode) -> Self {
3679 let mut s: Self = Self::default();
3680 s.set_root(root);
3681 s
3682 }
3683
3684 /// Selects tree layout geometry (`OrthogonalLeftRight`, `OrthogonalTopBottom`, or `Radial`).
3685 ///
3686 /// # Arguments
3687 ///
3688 /// - `Self` - Source tree series.
3689 /// - `EuvChartTreeLayout` - Tree layout mode.
3690 ///
3691 /// # Returns
3692 ///
3693 /// - `Self` - Updated tree series.
3694 #[must_use]
3695 pub fn layout(mut self, layout: EuvChartTreeLayout) -> Self {
3696 self.set_layout(layout);
3697 self
3698 }
3699}
3700
3701/// Constructors and accessors for `EuvChartParallelAxis`, `EuvChartParallelRow`, and `EuvChartParallelSeries`.
3702impl EuvChartParallelAxis {
3703 /// Creates a numeric parallel dimension axis.
3704 ///
3705 /// # Arguments
3706 ///
3707 /// - `S` - Dimension caption.
3708 ///
3709 /// # Returns
3710 ///
3711 /// - `Self` - Parallel axis.
3712 #[must_use]
3713 pub fn new<S>(name: S) -> Self
3714 where
3715 S: Into<String>,
3716 {
3717 Self {
3718 name: name.into(),
3719 min: None,
3720 max: None,
3721 categories: Vec::new(),
3722 }
3723 }
3724
3725 /// Sets explicit lower and upper numeric bounds for this dimension.
3726 ///
3727 /// # Arguments
3728 ///
3729 /// - `Self` - Source parallel axis.
3730 /// - `f32` - Minimum bound.
3731 /// - `f32` - Maximum bound.
3732 ///
3733 /// # Returns
3734 ///
3735 /// - `Self` - Updated parallel axis.
3736 #[must_use]
3737 pub fn range(mut self, min: f32, max: f32) -> Self {
3738 self.set_min(Some(min));
3739 self.set_max(Some(max));
3740 self
3741 }
3742
3743 /// Returns optional `(min, max)` bounds.
3744 ///
3745 /// # Arguments
3746 ///
3747 /// - `&Self` - Source parallel axis.
3748 ///
3749 /// # Returns
3750 ///
3751 /// - `(Option<f32>, Option<f32>)` - Optional domain bounds.
3752 #[must_use]
3753 pub fn bounds_opt(&self) -> (Option<f32>, Option<f32>) {
3754 let Self { min, max, .. } = *self;
3755 (min, max)
3756 }
3757}
3758
3759/// Constructors and accessors for `EuvChartParallelRow`.
3760impl EuvChartParallelRow {
3761 /// Creates a parallel coordinates observation row.
3762 ///
3763 /// # Arguments
3764 ///
3765 /// - `S` - Observation label.
3766 /// - `Vec<f32>` - Dimension values.
3767 /// - `usize` - Category index.
3768 ///
3769 /// # Returns
3770 ///
3771 /// - `Self` - Parallel row.
3772 #[must_use]
3773 pub fn new<S>(name: S, values: Vec<f32>, category: usize) -> Self
3774 where
3775 S: Into<String>,
3776 {
3777 Self {
3778 name: name.into(),
3779 values,
3780 category,
3781 color: None,
3782 }
3783 }
3784
3785 /// Returns optional explicit stroke color.
3786 ///
3787 /// # Arguments
3788 ///
3789 /// - `&Self` - Source row.
3790 ///
3791 /// # Returns
3792 ///
3793 /// - `Option<Color>` - Explicit stroke color.
3794 #[must_use]
3795 pub fn color_opt(&self) -> Option<Color> {
3796 let Self { color, .. } = *self;
3797 color
3798 }
3799}
3800
3801/// Constructors for `EuvChartParallelSeries`.
3802impl EuvChartParallelSeries {
3803 /// Creates a parallel coordinates series from axes and observation rows.
3804 ///
3805 /// # Arguments
3806 ///
3807 /// - `Vec<EuvChartParallelAxis>` - Dimension axes.
3808 /// - `Vec<EuvChartParallelRow>` - Observation rows.
3809 ///
3810 /// # Returns
3811 ///
3812 /// - `Self` - Parallel series.
3813 #[must_use]
3814 pub fn new(axes: Vec<EuvChartParallelAxis>, rows: Vec<EuvChartParallelRow>) -> Self {
3815 let mut s: Self = Self::default();
3816 s.set_axes(axes);
3817 s.set_rows(rows);
3818 s
3819 }
3820}
3821
3822/// Constructors and accessors for `EuvChartFlowArc` and `EuvChartLinesSeries`.
3823impl EuvChartFlowArc {
3824 /// Creates a directed curved flow arc between `(from_x, from_y)` and `(to_x, to_y)`.
3825 ///
3826 /// # Arguments
3827 ///
3828 /// - `A` - Origin label.
3829 /// - `B` - Destination label.
3830 /// - `(f32, f32)` - Origin `(x, y)` or `(lon, lat)`.
3831 /// - `(f32, f32)` - Destination `(x, y)` or `(lon, lat)`.
3832 /// - `f32` - Flow magnitude value.
3833 ///
3834 /// # Returns
3835 ///
3836 /// - `Self` - Flow arc descriptor.
3837 #[must_use]
3838 pub fn new<A, B>(from_name: A, to_name: B, from: (f32, f32), to: (f32, f32), value: f32) -> Self
3839 where
3840 A: Into<String>,
3841 B: Into<String>,
3842 {
3843 Self {
3844 from_name: from_name.into(),
3845 to_name: to_name.into(),
3846 from_x: from.0,
3847 from_y: from.1,
3848 to_x: to.0,
3849 to_y: to.1,
3850 value,
3851 color: None,
3852 }
3853 }
3854
3855 /// Returns optional explicit arc color.
3856 ///
3857 /// # Arguments
3858 ///
3859 /// - `&Self` - Source flow arc.
3860 ///
3861 /// # Returns
3862 ///
3863 /// - `Option<Color>` - Explicit arc stroke color.
3864 #[must_use]
3865 pub fn color_opt(&self) -> Option<Color> {
3866 let Self { color, .. } = *self;
3867 color
3868 }
3869}
3870
3871/// Constructors for `EuvChartLinesSeries`.
3872impl EuvChartLinesSeries {
3873 /// Creates a curved directional lines series from arcs.
3874 ///
3875 /// # Arguments
3876 ///
3877 /// - `Vec<EuvChartFlowArc>` - Directed arcs.
3878 ///
3879 /// # Returns
3880 ///
3881 /// - `Self` - Lines series.
3882 #[must_use]
3883 pub fn new(arcs: Vec<EuvChartFlowArc>) -> Self {
3884 let mut s: Self = Self::default();
3885 s.set_arcs(arcs);
3886 s
3887 }
3888
3889 /// Binds this lines series to `Cartesian2d` or `Geo` coordinates.
3890 ///
3891 /// # Arguments
3892 ///
3893 /// - `Self` - Source lines series.
3894 /// - `EuvChartCoordinateSystem` - Coordinate system.
3895 ///
3896 /// # Returns
3897 ///
3898 /// - `Self` - Updated lines series.
3899 #[must_use]
3900 pub fn coordinate_system(mut self, coord: EuvChartCoordinateSystem) -> Self {
3901 self.set_coordinate_system(coord);
3902 self
3903 }
3904}
3905
3906/// Constructors for `EuvChartThemeRiverSeries`, `EuvChartPictorialBarSeries`, `EuvChartCustomSeries`, `EuvChartCustomDrawContext`, `EuvChartGeoDatum`, and `EuvChartGeoMapSeries`.
3907impl EuvChartThemeRiverSeries {
3908 /// Creates a ThemeRiver streamgraph from `(time, value, theme)` observations.
3909 ///
3910 /// # Arguments
3911 ///
3912 /// - `Vec<EuvChartThemeRiverPoint>` - Stream observations.
3913 ///
3914 /// # Returns
3915 ///
3916 /// - `Self` - ThemeRiver series.
3917 #[must_use]
3918 pub fn new(points: Vec<EuvChartThemeRiverPoint>) -> Self {
3919 let mut s: Self = Self::default();
3920 s.set_points(points);
3921 s
3922 }
3923}
3924
3925/// Constructors for `EuvChartPictorialBarSeries`.
3926impl EuvChartPictorialBarSeries {
3927 /// Creates a stacked symbol pictorial bar series.
3928 ///
3929 /// # Arguments
3930 ///
3931 /// - `Vec<f32>` - Category values.
3932 /// - `EuvChartSymbol` - Repeated glyph symbol.
3933 ///
3934 /// # Returns
3935 ///
3936 /// - `Self` - Pictorial bar series.
3937 #[must_use]
3938 pub fn new(values: Vec<f32>, symbol: EuvChartSymbol) -> Self {
3939 let mut s: Self = Self::default();
3940 s.set_values(values);
3941 s.set_symbol(symbol);
3942 s
3943 }
3944}
3945
3946/// Accessors for `EuvChartCustomDrawContext`.
3947impl EuvChartCustomDrawContext {
3948 /// Returns the active pointer coordinates when hovering the plot area.
3949 ///
3950 /// # Arguments
3951 ///
3952 /// - `&Self` - Draw context.
3953 ///
3954 /// # Returns
3955 ///
3956 /// - `Option<Point>` - Pointer coordinates.
3957 #[must_use]
3958 pub fn hover_pos_opt(&self) -> Option<Point> {
3959 let Self { hover_pos, .. } = *self;
3960 hover_pos
3961 }
3962}
3963
3964/// Constructors and accessors for `EuvChartCustomSeries`.
3965impl EuvChartCustomSeries {
3966 /// Creates a custom vector painter series.
3967 ///
3968 /// # Arguments
3969 ///
3970 /// - `Vec<f32>` - Numeric reference values used for auto-scaling.
3971 /// - `F` - Custom `DrawCommand` painter closure.
3972 ///
3973 /// # Returns
3974 ///
3975 /// - `Self` - Custom series.
3976 #[must_use]
3977 pub fn new<F>(values: Vec<f32>, painter: F) -> Self
3978 where
3979 F: Fn(Rect, &EuvChartCustomDrawContext, &mut DisplayList) + 'static,
3980 {
3981 let mut s: Self = Self::default();
3982 s.set_values(values);
3983 s.set_painter(Some(Rc::new(painter)));
3984 s
3985 }
3986
3987 /// Returns the optional custom painter handle.
3988 ///
3989 /// # Arguments
3990 ///
3991 /// - `&Self` - Custom series.
3992 ///
3993 /// # Returns
3994 ///
3995 /// - `Option<EuvChartCustomPainter>` - Cloned painter handle.
3996 #[must_use]
3997 pub fn painter_opt(&self) -> Option<EuvChartCustomPainter> {
3998 let Self { painter, .. } = self;
3999 painter.clone()
4000 }
4001}
4002
4003/// Constructors and accessors for `EuvChartGeoDatum` and `EuvChartGeoMapSeries`.
4004impl EuvChartGeoDatum {
4005 /// Creates a region choropleth metric entry.
4006 ///
4007 /// # Arguments
4008 ///
4009 /// - `S` - Region name.
4010 /// - `f32` - Numeric intensity.
4011 ///
4012 /// # Returns
4013 ///
4014 /// - `Self` - Geo datum.
4015 #[must_use]
4016 pub fn new<S>(region_name: S, value: f32) -> Self
4017 where
4018 S: Into<String>,
4019 {
4020 Self {
4021 region_name: region_name.into(),
4022 value,
4023 color: None,
4024 }
4025 }
4026
4027 /// Returns optional explicit region color.
4028 ///
4029 /// # Arguments
4030 ///
4031 /// - `&Self` - Geo datum.
4032 ///
4033 /// # Returns
4034 ///
4035 /// - `Option<Color>` - Explicit fill color.
4036 #[must_use]
4037 pub fn color_opt(&self) -> Option<Color> {
4038 let Self { color, .. } = *self;
4039 color
4040 }
4041}
4042
4043/// Constructors for `EuvChartGeoMapSeries`.
4044impl EuvChartGeoMapSeries {
4045 /// Creates a geographic choropleth map series.
4046 ///
4047 /// # Arguments
4048 ///
4049 /// - `Vec<EuvChartGeoDatum>` - Region metric entries.
4050 ///
4051 /// # Returns
4052 ///
4053 /// - `Self` - GeoMap series.
4054 #[must_use]
4055 pub fn new(data: Vec<EuvChartGeoDatum>) -> Self {
4056 let mut s: Self = Self::default();
4057 s.set_data(data);
4058 s
4059 }
4060}
4061
4062/// Constructors and accessors for `EuvChartSeries`.
4063impl EuvChartSeries {
4064 /// Creates a visible named series wrapping `data`.
4065 ///
4066 /// # Arguments
4067 ///
4068 /// - `S` - Legend and tooltip series name.
4069 /// - `EuvChartSeriesData` - Typed series payload.
4070 ///
4071 /// # Returns
4072 ///
4073 /// - `Self` - Named series entry.
4074 #[must_use]
4075 pub fn new<S>(name: S, data: EuvChartSeriesData) -> Self
4076 where
4077 S: Into<String>,
4078 {
4079 Self {
4080 name: name.into(),
4081 color: None,
4082 visible: true,
4083 data,
4084 }
4085 }
4086
4087 /// Overrides the series color fluently.
4088 ///
4089 /// # Arguments
4090 ///
4091 /// - `Self` - Source series.
4092 /// - `Color` - Explicit tint color.
4093 ///
4094 /// # Returns
4095 ///
4096 /// - `Self` - Updated series.
4097 #[must_use]
4098 pub fn color(mut self, color: Color) -> Self {
4099 self.set_color(Some(color));
4100 self
4101 }
4102
4103 /// Sets initial series visibility.
4104 ///
4105 /// # Arguments
4106 ///
4107 /// - `Self` - Source series.
4108 /// - `bool` - Initial visibility flag.
4109 ///
4110 /// # Returns
4111 ///
4112 /// - `Self` - Updated series.
4113 #[must_use]
4114 pub fn visible(mut self, visible: bool) -> Self {
4115 self.set_visible(visible);
4116 self
4117 }
4118
4119 /// Returns the optional explicit series color.
4120 ///
4121 /// # Arguments
4122 ///
4123 /// - `&Self` - Source series.
4124 ///
4125 /// # Returns
4126 ///
4127 /// - `Option<Color>` - Explicit series color.
4128 #[must_use]
4129 pub fn color_opt(&self) -> Option<Color> {
4130 let Self { color, .. } = *self;
4131 color
4132 }
4133}
4134
4135/// Fluent declarative builders and safe option accessors for `EuvChartOption`.
4136impl EuvChartOption {
4137 /// Creates an empty declarative chart option ready for fluent chaining.
4138 ///
4139 /// # Returns
4140 ///
4141 /// - `Self` - Empty chart option.
4142 #[must_use]
4143 pub fn new() -> Self {
4144 Self::default()
4145 }
4146
4147 /// Sets the chart title block fluently.
4148 ///
4149 /// # Arguments
4150 ///
4151 /// - `Self` - Source chart option.
4152 /// - `EuvChartTitle` - Title configuration.
4153 ///
4154 /// # Returns
4155 ///
4156 /// - `Self` - Updated chart option.
4157 #[must_use]
4158 pub fn title(mut self, title: EuvChartTitle) -> Self {
4159 self.set_title(Some(title));
4160 self
4161 }
4162
4163 /// Sets the interactive legend configuration fluently.
4164 ///
4165 /// # Arguments
4166 ///
4167 /// - `Self` - Source chart option.
4168 /// - `EuvChartLegend` - Legend configuration.
4169 ///
4170 /// # Returns
4171 ///
4172 /// - `Self` - Updated chart option.
4173 #[must_use]
4174 pub fn legend(mut self, legend: EuvChartLegend) -> Self {
4175 self.set_legend(Some(legend));
4176 self
4177 }
4178
4179 /// Appends a Cartesian subplot grid fluently.
4180 ///
4181 /// # Arguments
4182 ///
4183 /// - `Self` - Source chart option.
4184 /// - `EuvChartGrid` - Subplot grid specification.
4185 ///
4186 /// # Returns
4187 ///
4188 /// - `Self` - Updated chart option.
4189 #[must_use]
4190 pub fn add_grid(mut self, grid: EuvChartGrid) -> Self {
4191 self.get_mut_grid().push(grid);
4192 self
4193 }
4194
4195 /// Appends an X axis fluently (supporting dual or multi-axis layouts).
4196 ///
4197 /// # Arguments
4198 ///
4199 /// - `Self` - Source chart option.
4200 /// - `EuvChartAxis` - X axis configuration.
4201 ///
4202 /// # Returns
4203 ///
4204 /// - `Self` - Updated chart option.
4205 #[must_use]
4206 pub fn x_axis(mut self, axis: EuvChartAxis) -> Self {
4207 self.get_mut_x_axes().push(axis);
4208 self
4209 }
4210
4211 /// Appends a Y axis fluently (supporting dual or multi-axis layouts).
4212 ///
4213 /// # Arguments
4214 ///
4215 /// - `Self` - Source chart option.
4216 /// - `EuvChartAxis` - Y axis configuration.
4217 ///
4218 /// # Returns
4219 ///
4220 /// - `Self` - Updated chart option.
4221 #[must_use]
4222 pub fn y_axis(mut self, axis: EuvChartAxis) -> Self {
4223 self.get_mut_y_axes().push(axis);
4224 self
4225 }
4226
4227 /// Sets the polar coordinate system fluently.
4228 ///
4229 /// # Arguments
4230 ///
4231 /// - `Self` - Source chart option.
4232 /// - `EuvChartPolar` - Polar coordinate configuration.
4233 ///
4234 /// # Returns
4235 ///
4236 /// - `Self` - Updated chart option.
4237 #[must_use]
4238 pub fn polar(mut self, polar: EuvChartPolar) -> Self {
4239 self.set_polar(Some(polar));
4240 self
4241 }
4242
4243 /// Sets the radar coordinate system fluently.
4244 ///
4245 /// # Arguments
4246 ///
4247 /// - `Self` - Source chart option.
4248 /// - `EuvChartRadar` - Radar coordinate configuration.
4249 ///
4250 /// # Returns
4251 ///
4252 /// - `Self` - Updated chart option.
4253 #[must_use]
4254 pub fn radar(mut self, radar: EuvChartRadar) -> Self {
4255 self.set_radar(Some(radar));
4256 self
4257 }
4258
4259 /// Sets the single-axis coordinate system fluently.
4260 ///
4261 /// # Arguments
4262 ///
4263 /// - `Self` - Source chart option.
4264 /// - `EuvChartSingleAxis` - Single-axis configuration.
4265 ///
4266 /// # Returns
4267 ///
4268 /// - `Self` - Updated chart option.
4269 #[must_use]
4270 pub fn single_axis(mut self, single_axis: EuvChartSingleAxis) -> Self {
4271 self.set_single_axis(Some(single_axis));
4272 self
4273 }
4274
4275 /// Sets the calendar coordinate system fluently.
4276 ///
4277 /// # Arguments
4278 ///
4279 /// - `Self` - Source chart option.
4280 /// - `EuvChartCalendar` - Calendar configuration.
4281 ///
4282 /// # Returns
4283 ///
4284 /// - `Self` - Updated chart option.
4285 #[must_use]
4286 pub fn calendar(mut self, calendar: EuvChartCalendar) -> Self {
4287 self.set_calendar(Some(calendar));
4288 self
4289 }
4290
4291 /// Sets the geographic coordinate system fluently.
4292 ///
4293 /// # Arguments
4294 ///
4295 /// - `Self` - Source chart option.
4296 /// - `EuvChartGeo` - Geo configuration.
4297 ///
4298 /// # Returns
4299 ///
4300 /// - `Self` - Updated chart option.
4301 #[must_use]
4302 pub fn geo(mut self, geo: EuvChartGeo) -> Self {
4303 self.set_geo(Some(geo));
4304 self
4305 }
4306
4307 /// Sets the interactive hover tooltip configuration fluently.
4308 ///
4309 /// # Arguments
4310 ///
4311 /// - `Self` - Source chart option.
4312 /// - `EuvChartTooltip` - Tooltip configuration.
4313 ///
4314 /// # Returns
4315 ///
4316 /// - `Self` - Updated chart option.
4317 #[must_use]
4318 pub fn tooltip(mut self, tooltip: EuvChartTooltip) -> Self {
4319 self.set_tooltip(Some(tooltip));
4320 self
4321 }
4322
4323 /// Appends a data-zoom controller (`Inside` or `Slider`) fluently.
4324 ///
4325 /// # Arguments
4326 ///
4327 /// - `Self` - Source chart option.
4328 /// - `EuvChartDataZoom` - Data-zoom controller.
4329 ///
4330 /// # Returns
4331 ///
4332 /// - `Self` - Updated chart option.
4333 #[must_use]
4334 pub fn data_zoom(mut self, zoom: EuvChartDataZoom) -> Self {
4335 self.get_mut_data_zoom().push(zoom);
4336 self
4337 }
4338
4339 /// Sets the continuous or piecewise visual-map controller fluently.
4340 ///
4341 /// # Arguments
4342 ///
4343 /// - `Self` - Source chart option.
4344 /// - `EuvChartVisualMap` - Visual-map configuration.
4345 ///
4346 /// # Returns
4347 ///
4348 /// - `Self` - Updated chart option.
4349 #[must_use]
4350 pub fn visual_map(mut self, visual_map: EuvChartVisualMap) -> Self {
4351 self.set_visual_map(Some(visual_map));
4352 self
4353 }
4354
4355 /// Sets the compact icon-only toolbox toolbar fluently.
4356 ///
4357 /// # Arguments
4358 ///
4359 /// - `Self` - Source chart option.
4360 /// - `EuvChartToolbox` - Toolbox configuration.
4361 ///
4362 /// # Returns
4363 ///
4364 /// - `Self` - Updated chart option.
4365 #[must_use]
4366 pub fn toolbox(mut self, toolbox: EuvChartToolbox) -> Self {
4367 self.set_toolbox(Some(toolbox));
4368 self
4369 }
4370
4371 /// Sets a shared tabular dataset fluently.
4372 ///
4373 /// # Arguments
4374 ///
4375 /// - `Self` - Source chart option.
4376 /// - `EuvChartDataset` - Shared dataset.
4377 ///
4378 /// # Returns
4379 ///
4380 /// - `Self` - Updated chart option.
4381 #[must_use]
4382 pub fn dataset(mut self, dataset: EuvChartDataset) -> Self {
4383 self.set_dataset(Some(dataset));
4384 self
4385 }
4386
4387 /// Overrides the categorical color palette fluently.
4388 ///
4389 /// # Arguments
4390 ///
4391 /// - `Self` - Source chart option.
4392 /// - `Vec<Color>` - Custom ordered palette colors.
4393 ///
4394 /// # Returns
4395 ///
4396 /// - `Self` - Updated chart option.
4397 #[must_use]
4398 pub fn color_palette(mut self, colors: Vec<Color>) -> Self {
4399 self.set_color_palette(Some(colors));
4400 self
4401 }
4402
4403 /// Appends a typed series fluently.
4404 ///
4405 /// # Arguments
4406 ///
4407 /// - `Self` - Source chart option.
4408 /// - `EuvChartSeries` - Named series entry.
4409 ///
4410 /// # Returns
4411 ///
4412 /// - `Self` - Updated chart option.
4413 #[must_use]
4414 pub fn add_series(mut self, series: EuvChartSeries) -> Self {
4415 self.get_mut_series().push(series);
4416 self
4417 }
4418
4419 /// Overrides the canvas background color fluently.
4420 ///
4421 /// # Arguments
4422 ///
4423 /// - `Self` - Source chart option.
4424 /// - `Color` - Explicit background color.
4425 ///
4426 /// # Returns
4427 ///
4428 /// - `Self` - Updated chart option.
4429 #[must_use]
4430 pub fn background(mut self, color: Color) -> Self {
4431 self.set_background(Some(color));
4432 self
4433 }
4434
4435 /// Resolves the active categorical color palette for `tokens`.
4436 ///
4437 /// # Arguments
4438 ///
4439 /// - `&Self` - Source chart option.
4440 /// - `ThemeTokens` - Active UI theme tokens.
4441 ///
4442 /// # Returns
4443 ///
4444 /// - `Vec<Color>` - Non-empty high-contrast categorical color palette.
4445 #[must_use]
4446 pub fn resolved_palette(&self, tokens: ThemeTokens) -> Vec<Color> {
4447 let Self { color_palette, .. } = self;
4448 if let Some(custom) = color_palette.as_ref()
4449 && !custom.is_empty()
4450 {
4451 return custom.clone();
4452 }
4453 let hexes: &[u32; 10] = match tokens.get_mode() {
4454 ThemeMode::Light => &ECHART_PALETTE_LIGHT,
4455 ThemeMode::Dark => &ECHART_PALETTE_DARK,
4456 };
4457 let mut out: Vec<Color> = Vec::with_capacity(hexes.len());
4458 for &hex in hexes.iter() {
4459 out.push(Color::hex(hex));
4460 }
4461 out
4462 }
4463
4464 /// Returns the optional chart title reference.
4465 ///
4466 /// # Arguments
4467 ///
4468 /// - `&Self` - Chart option.
4469 ///
4470 /// # Returns
4471 ///
4472 /// - `Option<&EuvChartTitle>` - Title configuration.
4473 #[must_use]
4474 pub fn title_opt(&self) -> Option<&EuvChartTitle> {
4475 let Self { title, .. } = self;
4476 title.as_ref()
4477 }
4478
4479 /// Returns a cloned chart option with its `title` cleared so host header chrome can render the title once without canvas duplication.
4480 ///
4481 /// # Arguments
4482 ///
4483 /// - `&Self` - Source chart option.
4484 ///
4485 /// # Returns
4486 ///
4487 /// - `Self` - Cloned option with `title` set to `None`.
4488 #[must_use]
4489 pub fn without_title(&self) -> Self {
4490 let mut copy: Self = self.clone();
4491 copy.set_title(None);
4492 copy
4493 }
4494
4495 /// Returns the optional legend reference.
4496 ///
4497 /// # Arguments
4498 ///
4499 /// - `&Self` - Chart option.
4500 ///
4501 /// # Returns
4502 ///
4503 /// - `Option<&EuvChartLegend>` - Legend configuration.
4504 #[must_use]
4505 pub fn legend_opt(&self) -> Option<&EuvChartLegend> {
4506 let Self { legend, .. } = self;
4507 legend.as_ref()
4508 }
4509
4510 /// Returns the optional polar coordinate system reference.
4511 ///
4512 /// # Arguments
4513 ///
4514 /// - `&Self` - Chart option.
4515 ///
4516 /// # Returns
4517 ///
4518 /// - `Option<&EuvChartPolar>` - Polar coordinate configuration.
4519 #[must_use]
4520 pub fn polar_opt(&self) -> Option<&EuvChartPolar> {
4521 let Self { polar, .. } = self;
4522 polar.as_ref()
4523 }
4524
4525 /// Returns the optional radar coordinate system reference.
4526 ///
4527 /// # Arguments
4528 ///
4529 /// - `&Self` - Chart option.
4530 ///
4531 /// # Returns
4532 ///
4533 /// - `Option<&EuvChartRadar>` - Radar coordinate configuration.
4534 #[must_use]
4535 pub fn radar_opt(&self) -> Option<&EuvChartRadar> {
4536 let Self { radar, .. } = self;
4537 radar.as_ref()
4538 }
4539
4540 /// Returns the optional single-axis coordinate system reference.
4541 ///
4542 /// # Arguments
4543 ///
4544 /// - `&Self` - Chart option.
4545 ///
4546 /// # Returns
4547 ///
4548 /// - `Option<&EuvChartSingleAxis>` - Single-axis configuration.
4549 #[must_use]
4550 pub fn single_axis_opt(&self) -> Option<&EuvChartSingleAxis> {
4551 let Self { single_axis, .. } = self;
4552 single_axis.as_ref()
4553 }
4554
4555 /// Returns the optional calendar coordinate system reference.
4556 ///
4557 /// # Arguments
4558 ///
4559 /// - `&Self` - Chart option.
4560 ///
4561 /// # Returns
4562 ///
4563 /// - `Option<&EuvChartCalendar>` - Calendar configuration.
4564 #[must_use]
4565 pub fn calendar_opt(&self) -> Option<&EuvChartCalendar> {
4566 let Self { calendar, .. } = self;
4567 calendar.as_ref()
4568 }
4569
4570 /// Returns the optional geographic coordinate system reference.
4571 ///
4572 /// # Arguments
4573 ///
4574 /// - `&Self` - Chart option.
4575 ///
4576 /// # Returns
4577 ///
4578 /// - `Option<&EuvChartGeo>` - Geo coordinate configuration.
4579 #[must_use]
4580 pub fn geo_opt(&self) -> Option<&EuvChartGeo> {
4581 let Self { geo, .. } = self;
4582 geo.as_ref()
4583 }
4584
4585 /// Returns the optional tooltip configuration reference.
4586 ///
4587 /// # Arguments
4588 ///
4589 /// - `&Self` - Chart option.
4590 ///
4591 /// # Returns
4592 ///
4593 /// - `Option<&EuvChartTooltip>` - Tooltip configuration.
4594 #[must_use]
4595 pub fn tooltip_opt(&self) -> Option<&EuvChartTooltip> {
4596 let Self { tooltip, .. } = self;
4597 tooltip.as_ref()
4598 }
4599
4600 /// Returns the optional visual-map configuration reference.
4601 ///
4602 /// # Arguments
4603 ///
4604 /// - `&Self` - Chart option.
4605 ///
4606 /// # Returns
4607 ///
4608 /// - `Option<&EuvChartVisualMap>` - Visual-map configuration.
4609 #[must_use]
4610 pub fn visual_map_opt(&self) -> Option<&EuvChartVisualMap> {
4611 let Self { visual_map, .. } = self;
4612 visual_map.as_ref()
4613 }
4614
4615 /// Returns the optional toolbox configuration reference.
4616 ///
4617 /// # Arguments
4618 ///
4619 /// - `&Self` - Chart option.
4620 ///
4621 /// # Returns
4622 ///
4623 /// - `Option<&EuvChartToolbox>` - Toolbox configuration.
4624 #[must_use]
4625 pub fn toolbox_opt(&self) -> Option<&EuvChartToolbox> {
4626 let Self { toolbox, .. } = self;
4627 toolbox.as_ref()
4628 }
4629
4630 /// Returns the optional shared dataset reference.
4631 ///
4632 /// # Arguments
4633 ///
4634 /// - `&Self` - Chart option.
4635 ///
4636 /// # Returns
4637 ///
4638 /// - `Option<&EuvChartDataset>` - Shared dataset.
4639 #[must_use]
4640 pub fn dataset_opt(&self) -> Option<&EuvChartDataset> {
4641 let Self { dataset, .. } = self;
4642 dataset.as_ref()
4643 }
4644
4645 /// Returns the optional explicit background color.
4646 ///
4647 /// # Arguments
4648 ///
4649 /// - `&Self` - Chart option.
4650 ///
4651 /// # Returns
4652 ///
4653 /// - `Option<Color>` - Explicit background color.
4654 #[must_use]
4655 pub fn background_opt(&self) -> Option<Color> {
4656 let Self { background, .. } = *self;
4657 background
4658 }
4659}