use super::*;
impl Default for EuvChartLegend {
fn default() -> Self {
Self {
show: true,
position: EuvChartPosition::Top,
items: Vec::new(),
}
}
}
impl Default for EuvChartGrid {
fn default() -> Self {
Self {
left: ECHART_GRID_DEFAULT_LEFT,
right: ECHART_GRID_DEFAULT_RIGHT,
top: ECHART_GRID_DEFAULT_TOP,
bottom: ECHART_GRID_DEFAULT_BOTTOM,
contain_label: true,
show_border: false,
}
}
}
impl Default for EuvChartAxis {
fn default() -> Self {
Self {
axis_type: EuvChartAxisType::Value,
name: String::new(),
unit_suffix: String::new(),
categories: Vec::new(),
grid_index: 0,
min: None,
max: None,
inverse: false,
split_number: ECHART_DEFAULT_SPLIT_NUMBER,
show_axis_line: true,
show_axis_tick: true,
show_axis_label: true,
show_split_line: true,
show_split_area: false,
position: None,
}
}
}
impl Default for EuvChartPolar {
fn default() -> Self {
Self {
angle_axis: EuvChartAxis::category(Vec::new()),
radius_axis: EuvChartAxis::value(),
radius_ratio: 0.72,
center_x_ratio: 0.5,
center_y_ratio: 0.5,
}
}
}
impl Default for EuvChartRadar {
fn default() -> Self {
Self {
indicators: Vec::new(),
shape: EuvChartRadarShape::Polygon,
split_number: 4,
radius_ratio: 0.72,
}
}
}
impl Default for EuvChartSingleAxis {
fn default() -> Self {
Self {
axis: EuvChartAxis::category(Vec::new()),
center_y_ratio: 0.54,
}
}
}
impl Default for EuvChartCalendar {
fn default() -> Self {
Self {
year: 2026,
weeks: ECHART_CALENDAR_DEFAULT_WEEKS,
month_labels: Vec::new(),
cell_gap: 3.0,
orient: EuvChartOrient::Horizontal,
}
}
}
impl Default for EuvChartGeo {
fn default() -> Self {
Self {
preset: EuvChartGeoMapPreset::World,
regions: Vec::new(),
show_labels: true,
roam: false,
}
}
}
impl Default for EuvChartTooltip {
fn default() -> Self {
Self {
show: true,
trigger: EuvChartTooltipTrigger::Axis,
axis_pointer: EuvChartAxisPointerType::Line,
}
}
}
impl Default for EuvChartDataZoom {
fn default() -> Self {
Self {
kind: EuvChartDataZoomKind::Slider,
start_pct: 0.0,
end_pct: 100.0,
min_span_pct: ECHART_ZOOM_DEFAULT_MIN_SPAN,
show_preview: true,
}
}
}
impl Default for EuvChartVisualMap {
fn default() -> Self {
Self {
show: true,
kind: EuvChartVisualMapKind::Continuous,
min: 0.0,
max: 100.0,
in_range_colors: Vec::new(),
pieces: Vec::new(),
orient: EuvChartOrient::Horizontal,
position: EuvChartPosition::Bottom,
}
}
}
impl Default for EuvChartToolbox {
fn default() -> Self {
Self {
show: true,
restore: true,
magic_type: true,
data_view: true,
fullscreen: true,
}
}
}
impl Default for EuvChartLineSeries {
fn default() -> Self {
Self {
values: Vec::new(),
xy_points: Vec::new(),
smooth: false,
step: EuvChartStepMode::None,
area_opacity: 0.0,
area_gradient: true,
stack: None,
dashed: false,
line_width: 2.2,
symbol: EuvChartSymbol::Circle,
symbol_size: 3.5,
connect_nulls: false,
show_labels: false,
coordinate_system: EuvChartCoordinateSystem::Cartesian2d,
x_axis_index: 0,
y_axis_index: 0,
annotations: EuvChartAnnotations::default(),
encode: None,
}
}
}
impl Default for EuvChartBarSeries {
fn default() -> Self {
Self {
values: Vec::new(),
stack: None,
bar_radius: 4.0,
bar_width_ratio: 0.62,
show_background: false,
show_labels: false,
coordinate_system: EuvChartCoordinateSystem::Cartesian2d,
x_axis_index: 0,
y_axis_index: 0,
annotations: EuvChartAnnotations::default(),
encode: None,
}
}
}
impl Default for EuvChartPieSeries {
fn default() -> Self {
Self {
slices: Vec::new(),
inner_radius_ratio: 0.0,
outer_radius_ratio: ECHART_PIE_DEFAULT_OUTER_RATIO,
rose_type: EuvChartRoseType::None,
pad_angle_deg: 1.5,
start_angle_deg: ECHART_PIE_DEFAULT_START_ANGLE,
show_labels: true,
show_leader_lines: true,
selected_offset: ECHART_PIE_DEFAULT_POPOUT,
center_x_ratio: 0.5,
center_y_ratio: 0.52,
}
}
}
impl Default for EuvChartScatterSeries {
fn default() -> Self {
Self {
points: Vec::new(),
symbol: EuvChartSymbol::Circle,
default_size: 6.0,
ripple_rings: 3,
ripple_scale: 2.6,
show_labels: false,
coordinate_system: EuvChartCoordinateSystem::Cartesian2d,
x_axis_index: 0,
y_axis_index: 0,
annotations: EuvChartAnnotations::default(),
encode: None,
}
}
}
impl Default for EuvChartRadarSeries {
fn default() -> Self {
Self {
items: Vec::new(),
area_opacity: 0.24,
line_width: 2.0,
show_vertices: true,
}
}
}
impl Default for EuvChartCandlestickSeries {
fn default() -> Self {
Self {
candles: Vec::new(),
bull_color: None,
bear_color: None,
x_axis_index: 0,
y_axis_index: 0,
annotations: EuvChartAnnotations::default(),
}
}
}
impl Default for EuvChartBoxplotSeries {
fn default() -> Self {
Self {
items: Vec::new(),
x_axis_index: 0,
y_axis_index: 0,
annotations: EuvChartAnnotations::default(),
}
}
}
impl Default for EuvChartHeatmapSeries {
fn default() -> Self {
Self {
cells: Vec::new(),
show_labels: true,
cell_gap: 2.0,
coordinate_system: EuvChartCoordinateSystem::Cartesian2d,
x_axis_index: 0,
y_axis_index: 0,
}
}
}
impl Default for EuvChartTreemapSeries {
fn default() -> Self {
Self {
nodes: Vec::new(),
show_headers: true,
cell_gap: 3.0,
corner_radius: 4.0,
}
}
}
impl Default for EuvChartSunburstSeries {
fn default() -> Self {
Self {
nodes: Vec::new(),
inner_radius_ratio: 0.16,
outer_radius_ratio: 0.84,
pad_angle_deg: 1.0,
show_labels: true,
}
}
}
impl Default for EuvChartSankeySeries {
fn default() -> Self {
Self {
nodes: Vec::new(),
links: Vec::new(),
node_width: 14.0,
node_gap: 10.0,
ribbon_opacity: 0.36,
}
}
}
impl Default for EuvChartFunnelSeries {
fn default() -> Self {
Self {
stages: Vec::new(),
sort: EuvChartFunnelSort::Descending,
gap: 3.0,
show_labels: true,
show_percent: true,
}
}
}
impl Default for EuvChartGaugeSeries {
fn default() -> Self {
Self {
value: 0.0,
min: 0.0,
max: 100.0,
unit: String::new(),
title: String::new(),
start_angle_deg: ECHART_GAUGE_DEFAULT_START_ANGLE,
end_angle_deg: ECHART_GAUGE_DEFAULT_END_ANGLE,
split_number: 5,
show_progress: true,
show_pointer: true,
segments: vec![
EuvChartGaugeSegment::new(0.35, Color::hex(ECHART_GAUGE_LOW_HEX)),
EuvChartGaugeSegment::new(0.75, Color::hex(ECHART_GAUGE_MID_HEX)),
EuvChartGaugeSegment::new(1.0, Color::hex(ECHART_GAUGE_HIGH_HEX)),
],
}
}
}
impl Default for EuvChartGraphSeries {
fn default() -> Self {
Self {
nodes: Vec::new(),
edges: Vec::new(),
categories: Vec::new(),
layout: EuvChartGraphLayout::Force,
directed: true,
show_labels: true,
iterations: ECHART_GRAPH_DEFAULT_ITERS,
}
}
}
impl Default for EuvChartTreeSeries {
fn default() -> Self {
Self {
root: EuvChartHierarchyNode::leaf(String::new(), 1.0),
layout: EuvChartTreeLayout::OrthogonalLeftRight,
symbol_size: 5.5,
show_labels: true,
}
}
}
impl Default for EuvChartParallelSeries {
fn default() -> Self {
Self {
axes: Vec::new(),
rows: Vec::new(),
line_width: 1.8,
line_opacity: 0.72,
}
}
}
impl Default for EuvChartLinesSeries {
fn default() -> Self {
Self {
arcs: Vec::new(),
curveness: 0.22,
line_width: 2.0,
show_arrows: true,
coordinate_system: EuvChartCoordinateSystem::Cartesian2d,
x_axis_index: 0,
y_axis_index: 0,
}
}
}
impl Default for EuvChartThemeRiverSeries {
fn default() -> Self {
Self {
points: Vec::new(),
show_labels: true,
smooth: true,
}
}
}
impl Default for EuvChartPictorialBarSeries {
fn default() -> Self {
Self {
values: Vec::new(),
symbol: EuvChartSymbol::RoundRect,
symbol_repeat: true,
symbol_size: 10.0,
x_axis_index: 0,
y_axis_index: 0,
}
}
}
impl Default for EuvChartCustomSeries {
fn default() -> Self {
Self {
values: Vec::new(),
painter: None,
x_axis_index: 0,
y_axis_index: 0,
}
}
}
impl Default for EuvChartGeoMapSeries {
fn default() -> Self {
Self {
data: Vec::new(),
show_labels: true,
border_width: 1.0,
}
}
}
impl EuvChartTitle {
#[must_use]
pub fn new<S>(text: S) -> Self
where
S: Into<String>,
{
Self {
text: text.into(),
subtext: String::new(),
align: EuvChartAlign::Left,
}
}
#[must_use]
pub fn subtext<S>(mut self, subtext: S) -> Self
where
S: Into<String>,
{
self.set_subtext(subtext.into());
self
}
#[must_use]
pub fn align(mut self, align: EuvChartAlign) -> Self {
self.set_align(align);
self
}
}
impl EuvChartLegend {
#[must_use]
pub fn at(position: EuvChartPosition) -> Self {
let mut legend: Self = Self::default();
legend.set_position(position);
legend
}
#[must_use]
pub fn show(mut self, show: bool) -> Self {
self.set_show(show);
self
}
#[must_use]
pub fn items(mut self, items: Vec<String>) -> Self {
self.set_items(items);
self
}
}
impl EuvChartGrid {
#[must_use]
pub fn margins(left: f32, right: f32, top: f32, bottom: f32) -> Self {
Self {
left,
right,
top,
bottom,
contain_label: true,
show_border: false,
}
}
#[must_use]
pub fn contain_label(mut self, contain_label: bool) -> Self {
self.set_contain_label(contain_label);
self
}
#[must_use]
pub fn show_border(mut self, show_border: bool) -> Self {
self.set_show_border(show_border);
self
}
}
impl EuvChartAxis {
#[must_use]
pub fn category(categories: Vec<String>) -> Self {
let mut axis: Self = Self::default();
axis.set_axis_type(EuvChartAxisType::Category);
axis.set_categories(categories);
axis.set_show_split_line(false);
axis
}
#[must_use]
pub fn value() -> Self {
Self::default()
}
#[must_use]
pub fn time() -> Self {
let mut axis: Self = Self::default();
axis.set_axis_type(EuvChartAxisType::Time);
axis
}
#[must_use]
pub fn log() -> Self {
let mut axis: Self = Self::default();
axis.set_axis_type(EuvChartAxisType::Log);
axis
}
#[must_use]
pub fn name<S>(mut self, name: S) -> Self
where
S: Into<String>,
{
self.set_name(name.into());
self
}
#[must_use]
pub fn unit_suffix<S>(mut self, suffix: S) -> Self
where
S: Into<String>,
{
self.set_unit_suffix(suffix.into());
self
}
#[must_use]
pub fn min(mut self, min: f32) -> Self {
self.set_min(Some(min));
self
}
#[must_use]
pub fn max(mut self, max: f32) -> Self {
self.set_max(Some(max));
self
}
#[must_use]
pub fn inverse(mut self, inverse: bool) -> Self {
self.set_inverse(inverse);
self
}
#[must_use]
pub fn split_number(mut self, count: usize) -> Self {
self.set_split_number(count.max(1));
self
}
#[must_use]
pub fn show_split_line(mut self, show: bool) -> Self {
self.set_show_split_line(show);
self
}
#[must_use]
pub fn show_split_area(mut self, show: bool) -> Self {
self.set_show_split_area(show);
self
}
#[must_use]
pub fn grid_index(mut self, idx: usize) -> Self {
self.set_grid_index(idx);
self
}
#[must_use]
pub fn position(mut self, pos: EuvChartPosition) -> Self {
self.set_position(Some(pos));
self
}
#[must_use]
pub fn min_opt(&self) -> Option<f32> {
let Self { min, .. } = *self;
min
}
#[must_use]
pub fn max_opt(&self) -> Option<f32> {
let Self { max, .. } = *self;
max
}
#[must_use]
pub fn position_opt(&self) -> Option<EuvChartPosition> {
let Self { position, .. } = *self;
position
}
}
impl EuvChartPolar {
#[must_use]
pub fn new(angle_axis: EuvChartAxis, radius_axis: EuvChartAxis) -> Self {
Self {
angle_axis,
radius_axis,
radius_ratio: 0.72,
center_x_ratio: 0.5,
center_y_ratio: 0.52,
}
}
}
impl EuvChartRadar {
#[must_use]
pub fn new(indicators: Vec<EuvChartRadarIndicator>) -> Self {
let mut radar: Self = Self::default();
radar.set_indicators(indicators);
radar
}
#[must_use]
pub fn shape(mut self, shape: EuvChartRadarShape) -> Self {
self.set_shape(shape);
self
}
#[must_use]
pub fn split_number(mut self, split_number: usize) -> Self {
self.set_split_number(split_number.max(1));
self
}
}
impl EuvChartSingleAxis {
#[must_use]
pub fn new(axis: EuvChartAxis) -> Self {
Self {
axis,
center_y_ratio: 0.54,
}
}
}
impl EuvChartCalendar {
#[must_use]
pub fn new(year: u32, weeks: usize) -> Self {
let mut cal: Self = Self::default();
cal.set_year(year);
cal.set_weeks(weeks.max(1));
cal
}
#[must_use]
pub fn month_labels(mut self, labels: Vec<String>) -> Self {
self.set_month_labels(labels);
self
}
}
impl EuvChartGeoRegion {
#[must_use]
pub fn new<S, C>(name: S, code: C, polygons: Vec<Vec<(f32, f32)>>) -> Self
where
S: Into<String>,
C: Into<String>,
{
Self {
name: name.into(),
code: code.into(),
polygons,
label_center: None,
}
}
#[must_use]
pub fn label_center(mut self, center: (f32, f32)) -> Self {
self.set_label_center(Some(center));
self
}
#[must_use]
pub fn label_center_opt(&self) -> Option<(f32, f32)> {
let Self { label_center, .. } = *self;
label_center
}
}
impl EuvChartGeo {
#[must_use]
pub fn world() -> Self {
Self::default()
}
#[must_use]
pub fn custom(regions: Vec<EuvChartGeoRegion>) -> Self {
Self {
preset: EuvChartGeoMapPreset::Custom,
regions,
show_labels: true,
roam: false,
}
}
#[must_use]
pub fn show_labels(mut self, show: bool) -> Self {
self.set_show_labels(show);
self
}
}
impl EuvChartTooltip {
#[must_use]
pub fn new(trigger: EuvChartTooltipTrigger, axis_pointer: EuvChartAxisPointerType) -> Self {
Self {
show: trigger != EuvChartTooltipTrigger::None,
trigger,
axis_pointer,
}
}
#[must_use]
pub fn item() -> Self {
Self::new(EuvChartTooltipTrigger::Item, EuvChartAxisPointerType::None)
}
#[must_use]
pub fn axis(pointer: EuvChartAxisPointerType) -> Self {
Self::new(EuvChartTooltipTrigger::Axis, pointer)
}
}
impl EuvChartDataZoom {
#[must_use]
pub fn inside() -> Self {
let mut dz: Self = Self::default();
dz.set_kind(EuvChartDataZoomKind::Inside);
dz
}
#[must_use]
pub fn slider() -> Self {
Self::default()
}
#[must_use]
pub fn range(mut self, start_pct: f32, end_pct: f32) -> Self {
let lo: f32 = start_pct.clamp(0.0, 99.0);
let hi: f32 = end_pct.clamp(lo + 1.0, 100.0);
self.set_start_pct(lo);
self.set_end_pct(hi);
self
}
}
impl EuvChartVisualPiece {
#[must_use]
pub fn new<S>(min: Option<f32>, max: Option<f32>, label: S, color: Color) -> Self
where
S: Into<String>,
{
Self {
min,
max,
label: label.into(),
color,
}
}
#[must_use]
pub fn min_opt(&self) -> Option<f32> {
let Self { min, .. } = *self;
min
}
#[must_use]
pub fn max_opt(&self) -> Option<f32> {
let Self { max, .. } = *self;
max
}
}
impl EuvChartVisualMap {
#[must_use]
pub fn continuous(min: f32, max: f32) -> Self {
let mut vm: Self = Self::default();
vm.set_kind(EuvChartVisualMapKind::Continuous);
vm.set_min(min);
vm.set_max(max);
vm
}
#[must_use]
pub fn piecewise(pieces: Vec<EuvChartVisualPiece>) -> Self {
let mut vm: Self = Self::default();
vm.set_kind(EuvChartVisualMapKind::Piecewise);
vm.set_pieces(pieces);
vm
}
#[must_use]
pub fn colors(mut self, colors: Vec<Color>) -> Self {
self.set_in_range_colors(colors);
self
}
#[must_use]
pub fn position(mut self, position: EuvChartPosition) -> Self {
self.set_position(position);
self
}
}
impl EuvChartToolbox {
#[must_use]
pub fn full() -> Self {
Self::default()
}
#[must_use]
pub fn magic_type(mut self, enabled: bool) -> Self {
self.set_magic_type(enabled);
self
}
#[must_use]
pub fn data_view(mut self, enabled: bool) -> Self {
self.set_data_view(enabled);
self
}
#[must_use]
pub fn fullscreen(mut self, enabled: bool) -> Self {
self.set_fullscreen(enabled);
self
}
}
impl EuvChartDataset {
#[must_use]
pub fn new(dimensions: Vec<String>, rows: Vec<Vec<EuvChartCell>>) -> Self {
Self { dimensions, rows }
}
#[must_use]
pub fn column_index(&self, dim: &str) -> Option<usize> {
if let Some(pos) = self
.get_dimensions()
.iter()
.position(|d: &String| d.as_str() == dim)
{
return Some(pos);
}
dim.parse::<usize>().ok()
}
}
impl EuvChartEncode {
#[must_use]
pub fn x<S>(mut self, dim: S) -> Self
where
S: Into<String>,
{
self.set_x(Some(dim.into()));
self
}
#[must_use]
pub fn y<S>(mut self, dim: S) -> Self
where
S: Into<String>,
{
self.set_y(Some(dim.into()));
self
}
#[must_use]
pub fn value<S>(mut self, dim: S) -> Self
where
S: Into<String>,
{
self.set_value(Some(dim.into()));
self
}
#[must_use]
pub fn size<S>(mut self, dim: S) -> Self
where
S: Into<String>,
{
self.set_size(Some(dim.into()));
self
}
#[must_use]
pub fn item_name<S>(mut self, dim: S) -> Self
where
S: Into<String>,
{
self.set_item_name(Some(dim.into()));
self
}
#[must_use]
pub fn x_opt(&self) -> Option<&str> {
let Self { x, .. } = self;
x.as_deref()
}
#[must_use]
pub fn y_opt(&self) -> Option<&str> {
let Self { y, .. } = self;
y.as_deref()
}
#[must_use]
pub fn value_opt(&self) -> Option<&str> {
let Self { value, .. } = self;
value.as_deref()
}
#[must_use]
pub fn size_opt(&self) -> Option<&str> {
let Self { size, .. } = self;
size.as_deref()
}
#[must_use]
pub fn item_name_opt(&self) -> Option<&str> {
let Self { item_name, .. } = self;
item_name.as_deref()
}
}
impl EuvChartMarkPoint {
#[must_use]
pub fn new<S>(kind: EuvChartMarkPointKind, name: S) -> Self
where
S: Into<String>,
{
Self {
kind,
name: name.into(),
color: None,
}
}
#[must_use]
pub fn color(mut self, color: Color) -> Self {
self.set_color(Some(color));
self
}
#[must_use]
pub fn color_opt(&self) -> Option<Color> {
let Self { color, .. } = *self;
color
}
}
impl EuvChartMarkLine {
#[must_use]
pub fn new<S>(kind: EuvChartMarkLineKind, name: S) -> Self
where
S: Into<String>,
{
Self {
kind,
name: name.into(),
color: None,
dashed: true,
}
}
#[must_use]
pub fn color(mut self, color: Color) -> Self {
self.set_color(Some(color));
self
}
#[must_use]
pub fn color_opt(&self) -> Option<Color> {
let Self { color, .. } = *self;
color
}
}
impl EuvChartMarkArea {
#[must_use]
pub fn x_range<S>(start_x: f32, end_x: f32, name: S) -> Self
where
S: Into<String>,
{
Self {
start_x: Some(start_x),
end_x: Some(end_x),
start_y: None,
end_y: None,
name: name.into(),
color: None,
}
}
#[must_use]
pub fn y_range<S>(start_y: f32, end_y: f32, name: S) -> Self
where
S: Into<String>,
{
Self {
start_x: None,
end_x: None,
start_y: Some(start_y),
end_y: Some(end_y),
name: name.into(),
color: None,
}
}
#[must_use]
pub fn color(mut self, color: Color) -> Self {
self.set_color(Some(color));
self
}
#[must_use]
pub fn bounds_opt(&self) -> (Option<f32>, Option<f32>, Option<f32>, Option<f32>) {
let Self {
start_x,
end_x,
start_y,
end_y,
..
} = *self;
(start_x, end_x, start_y, end_y)
}
#[must_use]
pub fn color_opt(&self) -> Option<Color> {
let Self { color, .. } = *self;
color
}
}
impl EuvChartLineSeries {
#[must_use]
pub fn from_values(values: Vec<f32>) -> Self {
let mut s: Self = Self::default();
let mapped: Vec<Option<f32>> = values.into_iter().map(Some).collect();
s.set_values(mapped);
s
}
#[must_use]
pub fn from_nullable(values: Vec<Option<f32>>) -> Self {
let mut s: Self = Self::default();
s.set_values(values);
s
}
#[must_use]
pub fn from_xy(points: Vec<(f32, f32)>) -> Self {
let mut s: Self = Self::default();
s.set_xy_points(points);
s
}
#[must_use]
pub fn smooth(mut self, smooth: bool) -> Self {
self.set_smooth(smooth);
self
}
#[must_use]
pub fn step(mut self, step: EuvChartStepMode) -> Self {
self.set_step(step);
self
}
#[must_use]
pub fn area(mut self, opacity: f32) -> Self {
self.set_area_opacity(opacity.clamp(0.0, 1.0));
self
}
#[must_use]
pub fn stack<S>(mut self, stack: S) -> Self
where
S: Into<String>,
{
self.set_stack(Some(stack.into()));
self
}
#[must_use]
pub fn dashed(mut self, dashed: bool) -> Self {
self.set_dashed(dashed);
self
}
#[must_use]
pub fn symbol(mut self, symbol: EuvChartSymbol, size: f32) -> Self {
self.set_symbol(symbol);
self.set_symbol_size(size);
self
}
#[must_use]
pub fn connect_nulls(mut self, connect: bool) -> Self {
self.set_connect_nulls(connect);
self
}
#[must_use]
pub fn axes(mut self, x_axis_index: usize, y_axis_index: usize) -> Self {
self.set_x_axis_index(x_axis_index);
self.set_y_axis_index(y_axis_index);
self
}
#[must_use]
pub fn coordinate_system(mut self, coord: EuvChartCoordinateSystem) -> Self {
self.set_coordinate_system(coord);
self
}
#[must_use]
pub fn mark_point(mut self, mark: EuvChartMarkPoint) -> Self {
self.get_mut_annotations().get_mut_mark_points().push(mark);
self
}
#[must_use]
pub fn mark_line(mut self, mark: EuvChartMarkLine) -> Self {
self.get_mut_annotations().get_mut_mark_lines().push(mark);
self
}
#[must_use]
pub fn mark_area(mut self, mark: EuvChartMarkArea) -> Self {
self.get_mut_annotations().get_mut_mark_areas().push(mark);
self
}
#[must_use]
pub fn encode(mut self, encode: EuvChartEncode) -> Self {
self.set_encode(Some(encode));
self
}
#[must_use]
pub fn stack_opt(&self) -> Option<&str> {
let Self { stack, .. } = self;
stack.as_deref()
}
#[must_use]
pub fn encode_opt(&self) -> Option<&EuvChartEncode> {
let Self { encode, .. } = self;
encode.as_ref()
}
}
impl EuvChartBarSeries {
#[must_use]
pub fn from_values(values: Vec<f32>) -> Self {
let mut s: Self = Self::default();
let mapped: Vec<Option<f32>> = values.into_iter().map(Some).collect();
s.set_values(mapped);
s
}
#[must_use]
pub fn stack<S>(mut self, stack: S) -> Self
where
S: Into<String>,
{
self.set_stack(Some(stack.into()));
self
}
#[must_use]
pub fn bar_radius(mut self, radius: f32) -> Self {
self.set_bar_radius(radius.max(0.0));
self
}
#[must_use]
pub fn show_background(mut self, show: bool) -> Self {
self.set_show_background(show);
self
}
#[must_use]
pub fn show_labels(mut self, show: bool) -> Self {
self.set_show_labels(show);
self
}
#[must_use]
pub fn coordinate_system(mut self, coord: EuvChartCoordinateSystem) -> Self {
self.set_coordinate_system(coord);
self
}
#[must_use]
pub fn axes(mut self, x_axis_index: usize, y_axis_index: usize) -> Self {
self.set_x_axis_index(x_axis_index);
self.set_y_axis_index(y_axis_index);
self
}
#[must_use]
pub fn mark_line(mut self, mark: EuvChartMarkLine) -> Self {
self.get_mut_annotations().get_mut_mark_lines().push(mark);
self
}
#[must_use]
pub fn encode(mut self, encode: EuvChartEncode) -> Self {
self.set_encode(Some(encode));
self
}
#[must_use]
pub fn stack_opt(&self) -> Option<&str> {
let Self { stack, .. } = self;
stack.as_deref()
}
#[must_use]
pub fn encode_opt(&self) -> Option<&EuvChartEncode> {
let Self { encode, .. } = self;
encode.as_ref()
}
}
impl EuvChartPieSlice {
#[must_use]
pub fn new<S>(name: S, value: f32) -> Self
where
S: Into<String>,
{
Self {
name: name.into(),
value,
color: None,
selected: false,
}
}
#[must_use]
pub fn color(mut self, color: Color) -> Self {
self.set_color(Some(color));
self
}
#[must_use]
pub fn selected(mut self, selected: bool) -> Self {
self.set_selected(selected);
self
}
#[must_use]
pub fn color_opt(&self) -> Option<Color> {
let Self { color, .. } = *self;
color
}
}
impl EuvChartPieSeries {
#[must_use]
pub fn new(slices: Vec<EuvChartPieSlice>) -> Self {
let mut s: Self = Self::default();
s.set_slices(slices);
s
}
#[must_use]
pub fn donut(mut self, inner_ratio: f32) -> Self {
self.set_inner_radius_ratio(inner_ratio.clamp(0.0, 0.85));
self
}
#[must_use]
pub fn rose(mut self, rose_type: EuvChartRoseType) -> Self {
self.set_rose_type(rose_type);
self
}
#[must_use]
pub fn pad_angle(mut self, deg: f32) -> Self {
self.set_pad_angle_deg(deg.clamp(0.0, 15.0));
self
}
}
impl EuvChartScatterPoint {
#[must_use]
pub fn new(x: f32, y: f32) -> Self {
Self {
x,
y,
size: 0.0,
value: None,
label: String::new(),
}
}
#[must_use]
pub fn size(mut self, size: f32) -> Self {
self.set_size(size);
self
}
#[must_use]
pub fn value(mut self, value: f32) -> Self {
self.set_value(Some(value));
self
}
#[must_use]
pub fn label<S>(mut self, label: S) -> Self
where
S: Into<String>,
{
self.set_label(label.into());
self
}
#[must_use]
pub fn value_opt(&self) -> Option<f32> {
let Self { value, .. } = *self;
value
}
}
impl EuvChartScatterSeries {
#[must_use]
pub fn new(points: Vec<EuvChartScatterPoint>) -> Self {
let mut s: Self = Self::default();
s.set_points(points);
s
}
#[must_use]
pub fn symbol(mut self, symbol: EuvChartSymbol, size: f32) -> Self {
self.set_symbol(symbol);
self.set_default_size(size.max(1.0));
self
}
#[must_use]
pub fn coordinate_system(mut self, coord: EuvChartCoordinateSystem) -> Self {
self.set_coordinate_system(coord);
self
}
#[must_use]
pub fn show_labels(mut self, show: bool) -> Self {
self.set_show_labels(show);
self
}
#[must_use]
pub fn encode(mut self, encode: EuvChartEncode) -> Self {
self.set_encode(Some(encode));
self
}
#[must_use]
pub fn encode_opt(&self) -> Option<&EuvChartEncode> {
let Self { encode, .. } = self;
encode.as_ref()
}
}
impl EuvChartRadarItem {
#[must_use]
pub fn new<S>(name: S, values: Vec<f32>) -> Self
where
S: Into<String>,
{
Self {
name: name.into(),
values,
color: None,
}
}
#[must_use]
pub fn color(mut self, color: Color) -> Self {
self.set_color(Some(color));
self
}
#[must_use]
pub fn color_opt(&self) -> Option<Color> {
let Self { color, .. } = *self;
color
}
}
impl EuvChartRadarSeries {
#[must_use]
pub fn new(items: Vec<EuvChartRadarItem>) -> Self {
let mut s: Self = Self::default();
s.set_items(items);
s
}
}
impl EuvChartCandlestickSeries {
#[must_use]
pub fn new(candles: Vec<EuvChartOhlcPoint>) -> Self {
let mut s: Self = Self::default();
s.set_candles(candles);
s
}
#[must_use]
pub fn colors(mut self, bull: Color, bear: Color) -> Self {
self.set_bull_color(Some(bull));
self.set_bear_color(Some(bear));
self
}
#[must_use]
pub fn resolved_bull_color(&self) -> Color {
let Self { bull_color, .. } = *self;
bull_color.unwrap_or_else(|| Color::hex(ECHART_CANDLE_BULL_HEX))
}
#[must_use]
pub fn resolved_bear_color(&self) -> Color {
let Self { bear_color, .. } = *self;
bear_color.unwrap_or_else(|| Color::hex(ECHART_CANDLE_BEAR_HEX))
}
}
impl EuvChartBoxplotItem {
#[must_use]
pub fn new(min: f32, q1: f32, median: f32, q3: f32, max: f32) -> Self {
Self {
min,
q1,
median,
q3,
max,
outliers: Vec::new(),
}
}
#[must_use]
pub fn outliers(mut self, outliers: Vec<f32>) -> Self {
self.set_outliers(outliers);
self
}
}
impl EuvChartBoxplotSeries {
#[must_use]
pub fn new(items: Vec<EuvChartBoxplotItem>) -> Self {
let mut s: Self = Self::default();
s.set_items(items);
s
}
}
impl EuvChartHeatmapCell {
#[must_use]
pub fn new(x_index: usize, y_index: usize, value: f32) -> Self {
Self {
x_index,
y_index,
value,
label: String::new(),
}
}
}
impl EuvChartHeatmapSeries {
#[must_use]
pub fn new(cells: Vec<EuvChartHeatmapCell>) -> Self {
let mut s: Self = Self::default();
s.set_cells(cells);
s
}
#[must_use]
pub fn coordinate_system(mut self, coord: EuvChartCoordinateSystem) -> Self {
self.set_coordinate_system(coord);
self
}
#[must_use]
pub fn show_labels(mut self, show: bool) -> Self {
self.set_show_labels(show);
self
}
}
impl EuvChartHierarchyNode {
#[must_use]
pub fn leaf<S>(name: S, value: f32) -> Self
where
S: Into<String>,
{
Self {
name: name.into(),
value,
color: None,
children: Vec::new(),
}
}
#[must_use]
pub fn branch<S>(name: S, children: Vec<Self>) -> Self
where
S: Into<String>,
{
let total: f32 = children.iter().map(Self::total_value).sum();
Self {
name: name.into(),
value: total,
color: None,
children,
}
}
#[must_use]
pub fn color(mut self, color: Color) -> Self {
self.set_color(Some(color));
self
}
#[must_use]
pub fn color_opt(&self) -> Option<Color> {
let Self { color, .. } = *self;
color
}
#[must_use]
pub fn total_value(&self) -> f32 {
let children: &[Self] = self.get_children().as_slice();
if children.is_empty() {
self.get_value().max(0.0)
} else {
let sum: f32 = children.iter().map(Self::total_value).sum();
sum.max(self.get_value().max(0.0))
}
}
#[must_use]
pub fn max_depth(&self) -> usize {
let children: &[Self] = self.get_children().as_slice();
if children.is_empty() {
1
} else {
let deepest: usize = children.iter().map(Self::max_depth).max().unwrap_or(0);
1 + deepest
}
}
}
impl EuvChartTreemapSeries {
#[must_use]
pub fn new(nodes: Vec<EuvChartHierarchyNode>) -> Self {
let mut s: Self = Self::default();
s.set_nodes(nodes);
s
}
}
impl EuvChartSunburstSeries {
#[must_use]
pub fn new(nodes: Vec<EuvChartHierarchyNode>) -> Self {
let mut s: Self = Self::default();
s.set_nodes(nodes);
s
}
}
impl EuvChartSankeyNode {
#[must_use]
pub fn new<S>(name: S) -> Self
where
S: Into<String>,
{
Self {
name: name.into(),
color: None,
depth: None,
}
}
#[must_use]
pub fn color(mut self, color: Color) -> Self {
self.set_color(Some(color));
self
}
#[must_use]
pub fn color_opt(&self) -> Option<Color> {
let Self { color, .. } = *self;
color
}
#[must_use]
pub fn depth_opt(&self) -> Option<usize> {
let Self { depth, .. } = *self;
depth
}
}
impl EuvChartSankeySeries {
#[must_use]
pub fn new(nodes: Vec<EuvChartSankeyNode>, links: Vec<EuvChartSankeyLink>) -> Self {
let mut s: Self = Self::default();
s.set_nodes(nodes);
s.set_links(links);
s
}
}
impl EuvChartFunnelStage {
#[must_use]
pub fn new<S>(name: S, value: f32) -> Self
where
S: Into<String>,
{
Self {
name: name.into(),
value,
color: None,
}
}
#[must_use]
pub fn color_opt(&self) -> Option<Color> {
let Self { color, .. } = *self;
color
}
}
impl EuvChartFunnelSeries {
#[must_use]
pub fn new(stages: Vec<EuvChartFunnelStage>) -> Self {
let mut s: Self = Self::default();
s.set_stages(stages);
s
}
#[must_use]
pub fn sort(mut self, sort: EuvChartFunnelSort) -> Self {
self.set_sort(sort);
self
}
}
impl EuvChartGaugeSeries {
#[must_use]
pub fn new(value: f32, min: f32, max: f32) -> Self {
let mut g: Self = Self::default();
g.set_value(value);
g.set_min(min);
g.set_max(max);
g
}
#[must_use]
pub fn unit<S>(mut self, unit: S) -> Self
where
S: Into<String>,
{
self.set_unit(unit.into());
self
}
#[must_use]
pub fn title<S>(mut self, title: S) -> Self
where
S: Into<String>,
{
self.set_title(title.into());
self
}
#[must_use]
pub fn angles(mut self, start_deg: f32, end_deg: f32) -> Self {
self.set_start_angle_deg(start_deg);
self.set_end_angle_deg(end_deg);
self
}
}
impl EuvChartGraphNode {
#[must_use]
pub fn new<I, N>(id: I, name: N, size: f32, category: usize) -> Self
where
I: Into<String>,
N: Into<String>,
{
Self {
id: id.into(),
name: name.into(),
value: size,
size: size.max(4.0),
category,
x: None,
y: None,
color: None,
}
}
#[must_use]
pub fn pos_opt(&self) -> (Option<f32>, Option<f32>) {
let Self { x, y, .. } = *self;
(x, y)
}
#[must_use]
pub fn color_opt(&self) -> Option<Color> {
let Self { color, .. } = *self;
color
}
}
impl EuvChartGraphEdge {
#[must_use]
pub fn new<S, T>(source: S, target: T) -> Self
where
S: Into<String>,
T: Into<String>,
{
Self {
source: source.into(),
target: target.into(),
weight: 1.5,
label: String::new(),
curveness: 0.14,
}
}
#[must_use]
pub fn curveness(mut self, curveness: f32) -> Self {
self.set_curveness(curveness);
self
}
}
impl EuvChartGraphSeries {
#[must_use]
pub fn new(nodes: Vec<EuvChartGraphNode>, edges: Vec<EuvChartGraphEdge>) -> Self {
let mut s: Self = Self::default();
s.set_nodes(nodes);
s.set_edges(edges);
s
}
#[must_use]
pub fn layout(mut self, layout: EuvChartGraphLayout) -> Self {
self.set_layout(layout);
self
}
}
impl EuvChartTreeSeries {
#[must_use]
pub fn new(root: EuvChartHierarchyNode) -> Self {
let mut s: Self = Self::default();
s.set_root(root);
s
}
#[must_use]
pub fn layout(mut self, layout: EuvChartTreeLayout) -> Self {
self.set_layout(layout);
self
}
}
impl EuvChartParallelAxis {
#[must_use]
pub fn new<S>(name: S) -> Self
where
S: Into<String>,
{
Self {
name: name.into(),
min: None,
max: None,
categories: Vec::new(),
}
}
#[must_use]
pub fn range(mut self, min: f32, max: f32) -> Self {
self.set_min(Some(min));
self.set_max(Some(max));
self
}
#[must_use]
pub fn bounds_opt(&self) -> (Option<f32>, Option<f32>) {
let Self { min, max, .. } = *self;
(min, max)
}
}
impl EuvChartParallelRow {
#[must_use]
pub fn new<S>(name: S, values: Vec<f32>, category: usize) -> Self
where
S: Into<String>,
{
Self {
name: name.into(),
values,
category,
color: None,
}
}
#[must_use]
pub fn color_opt(&self) -> Option<Color> {
let Self { color, .. } = *self;
color
}
}
impl EuvChartParallelSeries {
#[must_use]
pub fn new(axes: Vec<EuvChartParallelAxis>, rows: Vec<EuvChartParallelRow>) -> Self {
let mut s: Self = Self::default();
s.set_axes(axes);
s.set_rows(rows);
s
}
}
impl EuvChartFlowArc {
#[must_use]
pub fn new<A, B>(from_name: A, to_name: B, from: (f32, f32), to: (f32, f32), value: f32) -> Self
where
A: Into<String>,
B: Into<String>,
{
Self {
from_name: from_name.into(),
to_name: to_name.into(),
from_x: from.0,
from_y: from.1,
to_x: to.0,
to_y: to.1,
value,
color: None,
}
}
#[must_use]
pub fn color_opt(&self) -> Option<Color> {
let Self { color, .. } = *self;
color
}
}
impl EuvChartLinesSeries {
#[must_use]
pub fn new(arcs: Vec<EuvChartFlowArc>) -> Self {
let mut s: Self = Self::default();
s.set_arcs(arcs);
s
}
#[must_use]
pub fn coordinate_system(mut self, coord: EuvChartCoordinateSystem) -> Self {
self.set_coordinate_system(coord);
self
}
}
impl EuvChartThemeRiverSeries {
#[must_use]
pub fn new(points: Vec<EuvChartThemeRiverPoint>) -> Self {
let mut s: Self = Self::default();
s.set_points(points);
s
}
}
impl EuvChartPictorialBarSeries {
#[must_use]
pub fn new(values: Vec<f32>, symbol: EuvChartSymbol) -> Self {
let mut s: Self = Self::default();
s.set_values(values);
s.set_symbol(symbol);
s
}
}
impl EuvChartCustomDrawContext {
#[must_use]
pub fn hover_pos_opt(&self) -> Option<Point> {
let Self { hover_pos, .. } = *self;
hover_pos
}
}
impl EuvChartCustomSeries {
#[must_use]
pub fn new<F>(values: Vec<f32>, painter: F) -> Self
where
F: Fn(Rect, &EuvChartCustomDrawContext, &mut DisplayList) + 'static,
{
let mut s: Self = Self::default();
s.set_values(values);
s.set_painter(Some(Rc::new(painter)));
s
}
#[must_use]
pub fn painter_opt(&self) -> Option<EuvChartCustomPainter> {
let Self { painter, .. } = self;
painter.clone()
}
}
impl EuvChartGeoDatum {
#[must_use]
pub fn new<S>(region_name: S, value: f32) -> Self
where
S: Into<String>,
{
Self {
region_name: region_name.into(),
value,
color: None,
}
}
#[must_use]
pub fn color_opt(&self) -> Option<Color> {
let Self { color, .. } = *self;
color
}
}
impl EuvChartGeoMapSeries {
#[must_use]
pub fn new(data: Vec<EuvChartGeoDatum>) -> Self {
let mut s: Self = Self::default();
s.set_data(data);
s
}
}
impl EuvChartSeries {
#[must_use]
pub fn new<S>(name: S, data: EuvChartSeriesData) -> Self
where
S: Into<String>,
{
Self {
name: name.into(),
color: None,
visible: true,
data,
}
}
#[must_use]
pub fn color(mut self, color: Color) -> Self {
self.set_color(Some(color));
self
}
#[must_use]
pub fn visible(mut self, visible: bool) -> Self {
self.set_visible(visible);
self
}
#[must_use]
pub fn color_opt(&self) -> Option<Color> {
let Self { color, .. } = *self;
color
}
}
impl EuvChartOption {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn title(mut self, title: EuvChartTitle) -> Self {
self.set_title(Some(title));
self
}
#[must_use]
pub fn legend(mut self, legend: EuvChartLegend) -> Self {
self.set_legend(Some(legend));
self
}
#[must_use]
pub fn add_grid(mut self, grid: EuvChartGrid) -> Self {
self.get_mut_grid().push(grid);
self
}
#[must_use]
pub fn x_axis(mut self, axis: EuvChartAxis) -> Self {
self.get_mut_x_axes().push(axis);
self
}
#[must_use]
pub fn y_axis(mut self, axis: EuvChartAxis) -> Self {
self.get_mut_y_axes().push(axis);
self
}
#[must_use]
pub fn polar(mut self, polar: EuvChartPolar) -> Self {
self.set_polar(Some(polar));
self
}
#[must_use]
pub fn radar(mut self, radar: EuvChartRadar) -> Self {
self.set_radar(Some(radar));
self
}
#[must_use]
pub fn single_axis(mut self, single_axis: EuvChartSingleAxis) -> Self {
self.set_single_axis(Some(single_axis));
self
}
#[must_use]
pub fn calendar(mut self, calendar: EuvChartCalendar) -> Self {
self.set_calendar(Some(calendar));
self
}
#[must_use]
pub fn geo(mut self, geo: EuvChartGeo) -> Self {
self.set_geo(Some(geo));
self
}
#[must_use]
pub fn tooltip(mut self, tooltip: EuvChartTooltip) -> Self {
self.set_tooltip(Some(tooltip));
self
}
#[must_use]
pub fn data_zoom(mut self, zoom: EuvChartDataZoom) -> Self {
self.get_mut_data_zoom().push(zoom);
self
}
#[must_use]
pub fn visual_map(mut self, visual_map: EuvChartVisualMap) -> Self {
self.set_visual_map(Some(visual_map));
self
}
#[must_use]
pub fn toolbox(mut self, toolbox: EuvChartToolbox) -> Self {
self.set_toolbox(Some(toolbox));
self
}
#[must_use]
pub fn dataset(mut self, dataset: EuvChartDataset) -> Self {
self.set_dataset(Some(dataset));
self
}
#[must_use]
pub fn color_palette(mut self, colors: Vec<Color>) -> Self {
self.set_color_palette(Some(colors));
self
}
#[must_use]
pub fn add_series(mut self, series: EuvChartSeries) -> Self {
self.get_mut_series().push(series);
self
}
#[must_use]
pub fn background(mut self, color: Color) -> Self {
self.set_background(Some(color));
self
}
#[must_use]
pub fn resolved_palette(&self, tokens: ThemeTokens) -> Vec<Color> {
let Self { color_palette, .. } = self;
if let Some(custom) = color_palette.as_ref()
&& !custom.is_empty()
{
return custom.clone();
}
let hexes: &[u32; 10] = match tokens.get_mode() {
ThemeMode::Light => &ECHART_PALETTE_LIGHT,
ThemeMode::Dark => &ECHART_PALETTE_DARK,
};
let mut out: Vec<Color> = Vec::with_capacity(hexes.len());
for &hex in hexes.iter() {
out.push(Color::hex(hex));
}
out
}
#[must_use]
pub fn title_opt(&self) -> Option<&EuvChartTitle> {
let Self { title, .. } = self;
title.as_ref()
}
#[must_use]
pub fn without_title(&self) -> Self {
let mut copy: Self = self.clone();
copy.set_title(None);
copy
}
#[must_use]
pub fn legend_opt(&self) -> Option<&EuvChartLegend> {
let Self { legend, .. } = self;
legend.as_ref()
}
#[must_use]
pub fn polar_opt(&self) -> Option<&EuvChartPolar> {
let Self { polar, .. } = self;
polar.as_ref()
}
#[must_use]
pub fn radar_opt(&self) -> Option<&EuvChartRadar> {
let Self { radar, .. } = self;
radar.as_ref()
}
#[must_use]
pub fn single_axis_opt(&self) -> Option<&EuvChartSingleAxis> {
let Self { single_axis, .. } = self;
single_axis.as_ref()
}
#[must_use]
pub fn calendar_opt(&self) -> Option<&EuvChartCalendar> {
let Self { calendar, .. } = self;
calendar.as_ref()
}
#[must_use]
pub fn geo_opt(&self) -> Option<&EuvChartGeo> {
let Self { geo, .. } = self;
geo.as_ref()
}
#[must_use]
pub fn tooltip_opt(&self) -> Option<&EuvChartTooltip> {
let Self { tooltip, .. } = self;
tooltip.as_ref()
}
#[must_use]
pub fn visual_map_opt(&self) -> Option<&EuvChartVisualMap> {
let Self { visual_map, .. } = self;
visual_map.as_ref()
}
#[must_use]
pub fn toolbox_opt(&self) -> Option<&EuvChartToolbox> {
let Self { toolbox, .. } = self;
toolbox.as_ref()
}
#[must_use]
pub fn dataset_opt(&self) -> Option<&EuvChartDataset> {
let Self { dataset, .. } = self;
dataset.as_ref()
}
#[must_use]
pub fn background_opt(&self) -> Option<Color> {
let Self { background, .. } = *self;
background
}
}