Skip to content

Commit

Permalink
added or switch to font_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaOber committed Nov 2, 2024
1 parent 5fdfa2e commit 44448ad
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 27 deletions.
13 changes: 7 additions & 6 deletions charming/src/component/radar_coordinate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde::Serialize;
use crate::{
datatype::CompositeValue,
element::{
font_settings::{FontFamily, FontStyle, FontWeight},
AxisLabel, AxisLine, AxisTick, Color, Formatter, Padding, Shape, SplitArea, SplitLine,
},
};
Expand All @@ -23,13 +24,13 @@ pub struct RadarAxisName {
color: Option<Color>,

#[serde(skip_serializing_if = "Option::is_none")]
font_style: Option<String>,
font_style: Option<FontStyle>,

#[serde(skip_serializing_if = "Option::is_none")]
font_weight: Option<String>,
font_weight: Option<FontWeight>,

#[serde(skip_serializing_if = "Option::is_none")]
font_family: Option<String>,
font_family: Option<FontFamily>,

#[serde(skip_serializing_if = "Option::is_none")]
font_size: Option<f64>,
Expand Down Expand Up @@ -161,17 +162,17 @@ impl RadarAxisName {
self
}

pub fn font_style<S: Into<String>>(mut self, font_style: S) -> Self {
pub fn font_style<F: Into<FontStyle>>(mut self, font_style: F) -> Self {
self.font_style = Some(font_style.into());
self
}

pub fn font_weight<S: Into<String>>(mut self, font_weight: S) -> Self {
pub fn font_weight<F: Into<FontWeight>>(mut self, font_weight: F) -> Self {
self.font_weight = Some(font_weight.into());
self
}

pub fn font_family<S: Into<String>>(mut self, font_family: S) -> Self {
pub fn font_family<F: Into<FontFamily>>(mut self, font_family: F) -> Self {
self.font_family = Some(font_family.into());
self
}
Expand Down
33 changes: 32 additions & 1 deletion charming/src/element/axis_label.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use serde::Serialize;

use super::{color::Color, Formatter};
use super::{
color::Color,
font_settings::{FontFamily, FontStyle, FontWeight},
Formatter,
};

#[derive(Serialize, Debug, PartialEq, PartialOrd, Clone)]
#[serde(rename_all = "camelCase")]
Expand All @@ -11,6 +15,15 @@ pub struct AxisLabel {
#[serde(skip_serializing_if = "Option::is_none")]
distance: Option<f64>,

#[serde(skip_serializing_if = "Option::is_none")]
font_style: Option<FontStyle>,

#[serde(skip_serializing_if = "Option::is_none")]
font_weight: Option<FontWeight>,

#[serde(skip_serializing_if = "Option::is_none")]
font_family: Option<FontFamily>,

#[serde(skip_serializing_if = "Option::is_none")]
font_size: Option<f64>,

Expand Down Expand Up @@ -38,6 +51,9 @@ impl AxisLabel {
Self {
show: None,
distance: None,
font_style: None,
font_weight: None,
font_family: None,
font_size: None,
color: None,
formatter: None,
Expand All @@ -56,6 +72,21 @@ impl AxisLabel {
self
}

pub fn font_style<F: Into<FontStyle>>(mut self, font_style: F) -> Self {
self.font_style = Some(font_style.into());
self
}

pub fn font_weight<F: Into<FontWeight>>(mut self, font_weight: F) -> Self {
self.font_weight = Some(font_weight.into());
self
}

pub fn font_family<F: Into<FontFamily>>(mut self, font_family: F) -> Self {
self.font_family = Some(font_family.into());
self
}

pub fn font_size<F: Into<f64>>(mut self, font_size: F) -> Self {
self.font_size = Some(font_size.into());
self
Expand Down
37 changes: 30 additions & 7 deletions charming/src/element/label.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use serde::Serialize;

use super::{color::Color, line_style::LineStyle, Formatter};
use super::{
color::Color,
font_settings::{FontFamily, FontStyle, FontWeight},
line_style::LineStyle,
Formatter,
};

#[derive(Serialize, Debug, PartialEq, PartialOrd, Clone)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -65,10 +70,16 @@ pub struct Label {
color: Option<Color>,

#[serde(skip_serializing_if = "Option::is_none")]
font_size: Option<f64>,
font_style: Option<FontStyle>,

#[serde(skip_serializing_if = "Option::is_none")]
font_weight: Option<FontWeight>,

#[serde(skip_serializing_if = "Option::is_none")]
font_weight: Option<String>,
font_family: Option<FontFamily>,

#[serde(skip_serializing_if = "Option::is_none")]
font_size: Option<f64>,

#[serde(skip_serializing_if = "Option::is_none")]
padding: Option<(f64, f64, f64, f64)>,
Expand Down Expand Up @@ -117,8 +128,10 @@ impl Label {
offset: None,
formatter: None,
color: None,
font_size: None,
font_style: None,
font_weight: None,
font_family: None,
font_size: None,
padding: None,
align: None,
vertical_align: None,
Expand Down Expand Up @@ -167,16 +180,26 @@ impl Label {
self
}

pub fn font_size<F: Into<f64>>(mut self, font_size: F) -> Self {
self.font_size = Some(font_size.into());
pub fn font_style<F: Into<FontStyle>>(mut self, font_style: F) -> Self {
self.font_style = Some(font_style.into());
self
}

pub fn font_weight<S: Into<String>>(mut self, font_weight: S) -> Self {
pub fn font_weight<F: Into<FontWeight>>(mut self, font_weight: F) -> Self {
self.font_weight = Some(font_weight.into());
self
}

pub fn font_family<F: Into<FontFamily>>(mut self, font_family: F) -> Self {
self.font_family = Some(font_family.into());
self
}

pub fn font_size<F: Into<f64>>(mut self, font_size: F) -> Self {
self.font_size = Some(font_size.into());
self
}

pub fn padding<F: Into<f64>>(mut self, padding: (F, F, F, F)) -> Self {
self.padding = Some((
padding.0.into(),
Expand Down
1 change: 1 addition & 0 deletions charming/src/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod coordinate_tooltip;
pub mod cursor;
pub mod dimension_encode;
pub mod emphasis;
pub mod font_settings;
pub mod formatter;
pub mod icon;
pub mod item_style;
Expand Down
17 changes: 10 additions & 7 deletions charming/src/element/text_style.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use serde::Serialize;

use super::color::Color;
use super::{
color::Color,
font_settings::{FontFamily, FontStyle, FontWeight},
};

#[derive(Serialize, Debug, PartialEq, PartialOrd, Clone)]
#[serde(rename_all = "camelCase")]
Expand All @@ -9,13 +12,13 @@ pub struct TextStyle {
color: Option<Color>,

#[serde(skip_serializing_if = "Option::is_none")]
font_style: Option<String>,
font_style: Option<FontStyle>,

#[serde(skip_serializing_if = "Option::is_none")]
font_weight: Option<String>,
font_weight: Option<FontWeight>,

#[serde(skip_serializing_if = "Option::is_none")]
font_family: Option<String>,
font_family: Option<FontFamily>,

#[serde(skip_serializing_if = "Option::is_none")]
font_size: Option<f64>,
Expand Down Expand Up @@ -55,17 +58,17 @@ impl TextStyle {
self
}

pub fn font_style<S: Into<String>>(mut self, font_style: S) -> Self {
pub fn font_style<F: Into<FontStyle>>(mut self, font_style: F) -> Self {
self.font_style = Some(font_style.into());
self
}

pub fn font_weight<S: Into<String>>(mut self, font_weight: S) -> Self {
pub fn font_weight<F: Into<FontWeight>>(mut self, font_weight: F) -> Self {
self.font_weight = Some(font_weight.into());
self
}

pub fn font_family<S: Into<String>>(mut self, font_family: S) -> Self {
pub fn font_family<F: Into<FontFamily>>(mut self, font_family: F) -> Self {
self.font_family = Some(font_family.into());
self
}
Expand Down
13 changes: 7 additions & 6 deletions charming/src/series/gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde::Serialize;
use crate::{
datatype::{DataFrame, DataPoint},
element::{
font_settings::{FontFamily, FontStyle, FontWeight},
Anchor, AxisLabel, AxisLine, AxisTick, Color, ColorBy, Formatter, ItemStyle, Pointer,
SplitLine, Tooltip,
},
Expand All @@ -18,13 +19,13 @@ pub struct GaugeDetail {
color: Option<Color>,

#[serde(skip_serializing_if = "Option::is_none")]
font_style: Option<String>,
font_style: Option<FontStyle>,

#[serde(skip_serializing_if = "Option::is_none")]
font_weight: Option<String>,
font_weight: Option<FontWeight>,

#[serde(skip_serializing_if = "Option::is_none")]
font_family: Option<String>,
font_family: Option<FontFamily>,

#[serde(skip_serializing_if = "Option::is_none")]
font_size: Option<f64>,
Expand Down Expand Up @@ -70,17 +71,17 @@ impl GaugeDetail {
self
}

pub fn font_style<S: Into<String>>(mut self, font_style: S) -> Self {
pub fn font_style<F: Into<FontStyle>>(mut self, font_style: F) -> Self {
self.font_style = Some(font_style.into());
self
}

pub fn font_weight<S: Into<String>>(mut self, font_weight: S) -> Self {
pub fn font_weight<F: Into<FontWeight>>(mut self, font_weight: F) -> Self {
self.font_weight = Some(font_weight.into());
self
}

pub fn font_family<S: Into<String>>(mut self, font_family: S) -> Self {
pub fn font_family<F: Into<FontFamily>>(mut self, font_family: F) -> Self {
self.font_family = Some(font_family.into());
self
}
Expand Down
1 change: 1 addition & 0 deletions charming/src/series/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ pub struct GraphNodeLabel {
#[serde(skip_serializing_if = "Option::is_none")]
color: Option<String>,

//TODO: I think this should be f64, would be a breaking change
#[serde(skip_serializing_if = "Option::is_none")]
font_size: Option<u64>,
}
Expand Down

0 comments on commit 44448ad

Please sign in to comment.