rtimelog 0.51.0

System for tracking time in a text-log-based format.
Documentation
//! Representation of charts for timelog
//!
//! # Description
//!
//! Support for both pie charts (of projects and tasks in a project), and
//! a bar graph of tasks displayed hourly.

pub mod colors;
pub mod day;
pub mod histogram;
pub mod legend;
pub mod pie;
pub mod pie_data;
pub mod tag_percent;

/// The [`ColorIter`] type represents an ordered list of colors to use for
/// building a pie chart.
pub type ColorIter<'a> = colors::ColorIter<'a>;

/// The [`Percent`] type represents a percentage greater than 0.0 up to 100.0
pub type Percent = tag_percent::Percent;

/// The [`TagPercent`] type holds a labeled percent value used in constructing
/// pie charts.
pub type TagPercent = tag_percent::TagPercent;

/// The [`PieData`] type holds the data for a pie chart.
pub type PieData = pie_data::PieData;

/// The [`Legend`] type formats the labels for a legend on the pie chart.
pub type Legend<'a> = legend::Legend<'a>;

/// The [`PieChart`] type holds the configuration data needed to display a
/// pie chart.
pub type PieChart<'a> = pie::PieChart<'a>;

/// The [`Percentages`] type is a vector of [`TagPercent`]s.
pub type Percentages = Vec<TagPercent>;

/// The [`BarGraph`] type holds configuration data needed to display an
/// hourly bar graph of the projects worked.
pub type BarGraph = histogram::BarGraph;

/// The [`DayHours`] type holds project-based task events for building an
/// hourly bar graph of the projects worked.
pub type DayHours = day::DayHours;

pub(crate) mod utils {
    pub(crate) fn format_coord(coord: f32) -> String {
        let s = format!("{coord:.3}");
        s.trim_end_matches('0').trim_end_matches('.').to_string()
    }
}

#[cfg(test)]
mod tests {
    use spectral::prelude::*;

    use super::utils::*;

    #[test]
    fn test_format_coord() {
        assert_that!(format_coord(0.0).as_str()).is_equal_to("0");
        assert_that!(format_coord(1.2345678).as_str()).is_equal_to("1.235");
        assert_that!(format_coord(10.5).as_str()).is_equal_to("10.5");
        assert_that!(format_coord(10.25).as_str()).is_equal_to("10.25");
    }
}