use crate::enums::chart::XlDataLabelPosition;
use crate::text::font::Font;
use crate::text::TextFrame;
#[derive(Debug, Clone)]
#[allow(clippy::struct_excessive_bools)]
pub struct DataLabels {
show_value: bool,
show_category_name: bool,
show_series_name: bool,
show_percent: bool,
show_legend_key: bool,
show_bubble_size: bool,
show_leader_lines: bool,
number_format: Option<String>,
number_format_is_linked: bool,
position: Option<XlDataLabelPosition>,
font: Option<Font>,
}
impl DataLabels {
#[must_use]
pub const fn new() -> Self {
Self {
show_value: false,
show_category_name: false,
show_series_name: false,
show_percent: false,
show_legend_key: false,
show_bubble_size: false,
show_leader_lines: false,
number_format: None,
number_format_is_linked: true,
position: None,
font: None,
}
}
#[must_use]
pub const fn show_value(&self) -> bool {
self.show_value
}
pub fn set_show_value(&mut self, value: bool) {
self.show_value = value;
}
#[must_use]
pub const fn show_category_name(&self) -> bool {
self.show_category_name
}
pub fn set_show_category_name(&mut self, value: bool) {
self.show_category_name = value;
}
#[must_use]
pub const fn show_series_name(&self) -> bool {
self.show_series_name
}
pub fn set_show_series_name(&mut self, value: bool) {
self.show_series_name = value;
}
#[must_use]
pub const fn show_percent(&self) -> bool {
self.show_percent
}
pub fn set_show_percent(&mut self, value: bool) {
self.show_percent = value;
}
#[must_use]
pub const fn show_legend_key(&self) -> bool {
self.show_legend_key
}
pub fn set_show_legend_key(&mut self, value: bool) {
self.show_legend_key = value;
}
#[must_use]
pub const fn show_bubble_size(&self) -> bool {
self.show_bubble_size
}
pub fn set_show_bubble_size(&mut self, value: bool) {
self.show_bubble_size = value;
}
#[must_use]
pub const fn show_leader_lines(&self) -> bool {
self.show_leader_lines
}
pub fn set_show_leader_lines(&mut self, value: bool) {
self.show_leader_lines = value;
}
#[must_use]
pub fn number_format(&self) -> Option<&str> {
self.number_format.as_deref()
}
pub fn set_number_format(&mut self, format: Option<&str>) {
self.number_format = format.map(ToString::to_string);
}
#[must_use]
pub const fn number_format_is_linked(&self) -> bool {
self.number_format_is_linked
}
pub fn set_number_format_is_linked(&mut self, value: bool) {
self.number_format_is_linked = value;
}
#[must_use]
pub const fn position(&self) -> Option<XlDataLabelPosition> {
self.position
}
pub fn set_position(&mut self, position: Option<XlDataLabelPosition>) {
self.position = position;
}
#[must_use]
pub const fn font(&self) -> Option<&Font> {
self.font.as_ref()
}
pub fn font_mut(&mut self) -> &mut Font {
self.font.get_or_insert_with(Font::new)
}
pub fn set_font(&mut self, font: Font) {
self.font = Some(font);
}
}
impl Default for DataLabels {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct DataLabel {
show_value: Option<bool>,
show_category_name: Option<bool>,
show_series_name: Option<bool>,
number_format: Option<String>,
position: Option<XlDataLabelPosition>,
font: Option<Font>,
text_frame: Option<TextFrame>,
has_text_frame: bool,
}
impl DataLabel {
#[must_use]
pub const fn new() -> Self {
Self {
show_value: None,
show_category_name: None,
show_series_name: None,
number_format: None,
position: None,
font: None,
text_frame: None,
has_text_frame: false,
}
}
#[must_use]
pub const fn show_value(&self) -> Option<bool> {
self.show_value
}
pub fn set_show_value(&mut self, value: Option<bool>) {
self.show_value = value;
}
#[must_use]
pub const fn show_category_name(&self) -> Option<bool> {
self.show_category_name
}
pub fn set_show_category_name(&mut self, value: Option<bool>) {
self.show_category_name = value;
}
#[must_use]
pub const fn show_series_name(&self) -> Option<bool> {
self.show_series_name
}
pub fn set_show_series_name(&mut self, value: Option<bool>) {
self.show_series_name = value;
}
#[must_use]
pub fn number_format(&self) -> Option<&str> {
self.number_format.as_deref()
}
pub fn set_number_format(&mut self, format: Option<&str>) {
self.number_format = format.map(ToString::to_string);
}
#[must_use]
pub const fn position(&self) -> Option<XlDataLabelPosition> {
self.position
}
pub fn set_position(&mut self, position: Option<XlDataLabelPosition>) {
self.position = position;
}
#[must_use]
pub const fn font(&self) -> Option<&Font> {
self.font.as_ref()
}
pub fn font_mut(&mut self) -> &mut Font {
self.font.get_or_insert_with(Font::new)
}
pub fn set_font(&mut self, font: Font) {
self.font = Some(font);
}
#[must_use]
pub const fn has_text_frame(&self) -> bool {
self.has_text_frame
}
#[must_use]
pub const fn text_frame(&self) -> Option<&TextFrame> {
self.text_frame.as_ref()
}
pub fn text_frame_mut(&mut self) -> &mut TextFrame {
self.has_text_frame = true;
self.text_frame.get_or_insert_with(TextFrame::new)
}
pub fn set_text_frame(&mut self, tf: TextFrame) {
self.has_text_frame = true;
self.text_frame = Some(tf);
}
}
impl Default for DataLabel {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
#[path = "datalabel_tests.rs"]
mod tests;