use crate::chart::plotchart;
use crate::canvas;
use crate::wish;
#[derive(Clone, Debug, PartialEq)]
pub struct TkPieChart {
pub id: String,
}
#[derive(Clone, Debug, PartialEq)]
pub struct TkSpiralPieChart {
pub id: String,
}
pub fn make_pie_chart(canvas: &canvas::TkCanvas) -> TkPieChart {
let id = wish::next_var();
let msg = format!("global {}; set {} [::Plotchart::createPiechart {}]",
id, id, &canvas.id);
wish::tell_wish(&msg);
TkPieChart { id }
}
pub fn make_spiral_pie_chart(canvas: &canvas::TkCanvas) -> TkSpiralPieChart {
let id = wish::next_var();
let msg = format!("global {}; set {} [::Plotchart::createSpiralPie {}]",
id, id, &canvas.id);
wish::tell_wish(&msg);
TkSpiralPieChart { id }
}
impl plotchart::TkPlotchart for TkPieChart {
fn id(&self) -> &str {
&self.id
}
}
impl plotchart::TkPlotchart for TkSpiralPieChart {
fn id(&self) -> &str {
&self.id
}
}
pub trait PieChartMethods: plotchart::TkPlotchart {
fn colours(&self, colours: &[&str]) {
let mut colour_str = String::new();
for colour in colours {
colour_str.push_str(&format!("{} ", colour));
}
let msg = format!("global {}; ${} colours {}",
self.id(), self.id(), colour_str);
wish::tell_wish(&msg);
}
fn plot(&self, data: &[(&str, f64)]) {
let mut data_str = String::new();
for (label, angle) in data {
data_str.push_str(&format!("{{{}}} {} ", label, angle));
}
let msg = format!("global {}; ${} plot {{{}}}",
self.id(), self.id(), data_str);
wish::tell_wish(&msg);
}
}
impl PieChartMethods for TkPieChart {}
impl TkPieChart {
pub fn explode(&self, slice_number: u64) {
let msg = format!("global {}; ${} explode {}",
&self.id, &self.id, slice_number);
wish::tell_wish(&msg);
}
}
impl PieChartMethods for TkSpiralPieChart {}