#![allow(clippy::needless_return)]
use animate::{CanvasContext, Point};
use dataflow::*;
use std::fmt;
#[macro_use]
extern crate log;
mod basechart;
pub use basechart::*;
mod bar;
pub use bar::*;
mod gauge;
pub use gauge::*;
mod line;
pub use line::*;
mod options;
pub use options::*;
mod pie;
pub use pie::*;
mod radar;
pub use radar::*;
pub mod utils;
pub(crate) const CLOCKWISE: i64 = 1;
pub(crate) const COUNTERCLOCKWISE: i64 = -1;
pub(crate) const HIGHLIGHT_OUTER_RADIUS_FACTOR: f64 = 1.05;
pub const PI: f64 = std::f64::consts::PI;
pub const TAU: f64 = std::f64::consts::TAU;
pub const PI_2: f64 = std::f64::consts::FRAC_PI_2;
pub const DEFAULT_FONT_FAMILY: &str = "monospace";
pub const CHART_PADDING: f64 = 12.0;
pub const LEGEND_MARGIN: f64 = 12.0;
pub const CHART_TITLE_MARGIN: f64 = 12.0;
pub const TITLE_PADDING: f64 = 6.0;
pub const AXIS_LABEL_MARGIN: usize = 12;
pub type LabelFormatter = fn(label: String) -> String;
pub type ValueFormatter = fn(value: f64) -> String;
pub fn default_label_formatter(label: String) -> String {
label
}
pub fn default_value_formatter(value: f64) -> String {
format!("{}", value)
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Visibility {
Hidden,
Hiding,
Showing,
Shown,
}
impl Default for Visibility {
fn default() -> Self {
Visibility::Hidden
}
}
pub struct MouseEvent;
pub trait Entity {
fn free(&mut self);
fn save(&self);
}
pub trait Drawable<C>
where
C: CanvasContext,
{
fn draw(&self, ctx: &C, percent: f64, highlight: bool);
}
#[derive(Default, Debug, Clone)]
pub struct ChartChannel<E>
where
E: Entity,
{
name: String,
fill: Fill,
highlight: Fill,
state: Visibility,
entities: Vec<E>,
}
impl<E> ChartChannel<E>
where
E: Entity,
{
pub fn new(name: &str, fill: Fill, highlight: Fill, entities: Vec<E>) -> Self {
Self {
name: name.into(),
fill,
highlight,
state: Visibility::Shown,
entities,
}
}
pub fn free_entities(&self, start: usize, end: Option<usize>) {
let end = match end {
Some(end) => end,
None => self.entities.len(),
};
let mut start = start;
while start < end {
start += 1;
}
unimplemented!()
}
}
pub trait Chart<C, M, D, E>
where
E: Entity,
C: CanvasContext,
M: fmt::Display,
D: fmt::Display + Copy,
{
fn calculate_drawing_sizes(&self, ctx: &C);
fn update_channel(&self, index: usize);
fn draw_axes_and_grid(&self, ctx: &C);
fn draw_channels(&self, ctx: &C, percent: f64) -> bool;
fn draw_frame(&self, ctx: &C, time: Option<i64>);
fn create_entities(
&self,
channel_index: usize,
start: usize,
end: usize,
color: Fill,
highlight_color: Fill,
) -> Vec<E>;
fn create_entity(
&self,
channel_index: usize,
entity_index: usize,
value: Option<D>,
color: Fill,
highlight_color: Fill,
) -> E;
fn create_channels(&self, start: usize, end: usize);
fn get_tooltip_position(&self, tooltip_width: f64, tooltip_height: f64) -> Point<f64>;
fn set_stream(&mut self, stream: DataStream<M, D>);
fn draw(&self, ctx: &C);
fn resize(&self, w: f64, h: f64);
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}