use crate::canvas;
use crate::chart::plotchart;
use crate::scrollbar;
use crate::wish;
#[derive(Clone, Debug, PartialEq)]
pub struct TkTimeChart {
pub id: String,
}
#[derive(Clone, Debug, PartialEq)]
pub struct TkTimeChartDefinition {
canvas_id: String,
time_begin: String,
time_end: String,
num_items: Option<u64>,
bar_height: Option<u64>,
ylabel_width: Option<u64>
}
impl TkTimeChartDefinition {
pub fn bar_height(&mut self, value: u64) -> &mut Self {
self.bar_height = Some(value);
self
}
pub fn num_items(&mut self, value: u64) -> &mut Self {
self.num_items = Some(value);
self
}
pub fn ylabel_width(&mut self, value: u64) -> &mut Self {
self.ylabel_width = Some(value);
self
}
pub fn plot(&self) -> TkTimeChart {
let id = wish::next_var();
let mut msg = format!(
"global {}; set {} [::Plotchart::createTimechart {} {{{}}} {{{}}} ",
id, id, &self.canvas_id, &self.time_begin, &self.time_end);
if let Some(value) = &self.num_items {
msg.push_str(&format!("{} ", value));
}
if let Some(value) = &self.bar_height {
msg.push_str(&format!("-barheight {} ", value));
}
if let Some(value) = &self.ylabel_width {
msg.push_str(&format!("-ylabelwidth {} ", value));
}
msg.push_str("]");
wish::tell_wish(&msg);
TkTimeChart { id }
}
}
pub fn make_time_chart(
canvas: &canvas::TkCanvas,
time_begin: &str,
time_end: &str,
) -> TkTimeChartDefinition {
TkTimeChartDefinition {
canvas_id: String::from(&canvas.id),
time_begin: String::from(time_begin),
time_end: String::from(time_end),
num_items: None,
bar_height: None,
ylabel_width: None
}
}
impl plotchart::TkPlotchart for TkTimeChart {
fn id(&self) -> &str {
&self.id
}
}
impl TkTimeChart {
pub fn add_milestone(&self, time_point: &str, colour: &str) {
let msg = format!("global {}; ${} addmilestone {{{}}} {}",
&self.id, &self.id, time_point, colour);
wish::tell_wish(&msg);
}
pub fn add_period(&self, (time_begin, time_end): (&str, &str), colour: &str) {
let msg = format!("global {}; ${} addperiod {{{}}} {{{}}} {}",
&self.id, &self.id, time_begin, time_end, colour);
wish::tell_wish(&msg);
}
pub fn draw_line(&self, text: &str, time_point: &str, colour: &str) {
let msg = format!("global {}; ${} vertline {{{}}} {{{}}} {}",
&self.id, &self.id, text, time_point, colour);
wish::tell_wish(&msg);
}
pub fn milestone(&self, text: &str, time_point: &str, colour: &str) {
let msg = format!("global {}; ${} milestone {{{}}} {{{}}} {}",
&self.id, &self.id, text, time_point, colour);
wish::tell_wish(&msg);
}
pub fn period(&self, text: &str, (time_begin, time_end): (&str, &str), colour: &str) {
let msg = format!("global {}; ${} period {{{}}} {{{}}} {{{}}} {}",
&self.id, &self.id, text, time_begin, time_end, colour);
wish::tell_wish(&msg);
}
pub fn scrollbar_horizontal(&self, scroll_bar: &scrollbar::TkScrollbar) {
let msg = format!("global {}; ${} hscroll {}",
&self.id, &self.id, &scroll_bar.id);
wish::tell_wish(&msg);
}
pub fn scrollbar_vertical(&self, scroll_bar: &scrollbar::TkScrollbar) {
let msg = format!("global {}; ${} vscroll {}",
&self.id, &self.id, &scroll_bar.id);
wish::tell_wish(&msg);
}
}