use crate::canvas;
use crate::chart::plotchart;
use crate::wish;
#[derive(Clone, Debug, PartialEq)]
pub struct TkTernaryDiagram {
pub id: String,
}
pub fn make_ternary_diagram(
canvas: &canvas::TkCanvas,
fractions: bool,
steps: u64,
) -> TkTernaryDiagram {
let id = wish::next_var();
let msg = format!(
"global {}; set {} [::Plotchart::createTernaryDiagram {} -fractions {} -steps {}]",
id,
id,
&canvas.id,
if fractions { "1" } else { "0" },
steps
);
wish::tell_wish(&msg);
TkTernaryDiagram { id }
}
impl plotchart::TkPlotchart for TkTernaryDiagram {
fn id(&self) -> &str {
&self.id
}
}
impl plotchart::TkChartSeries for TkTernaryDiagram {}
impl TkTernaryDiagram {
pub fn corner_titles(&self, bottom_left: &str, bottom_right: &str, top_centre: &str) {
let msg = format!("global {}; ${} text {{{}}} {{{}}} {{{}}}",
&self.id, &self.id, bottom_left, bottom_right, top_centre);
wish::tell_wish(&msg);
}
pub fn draw_filled_polygon(&self, series: &str, points: &[(f64, f64, f64)]) {
let mut points_str = String::new();
for (x, y, z) in points {
points_str.push_str(&format!("{} {} {} ", x, y, z));
}
let msg = format!("global {}; ${} fill {} {{{}}}",
&self.id, &self.id, series, &points_str);
wish::tell_wish(&msg);
}
pub fn draw_line(&self, series: &str, points: &[(f64, f64, f64)]) {
let mut points_str = String::new();
for (x, y, z) in points {
points_str.push_str(&format!("{} {} {} ", x, y, z));
}
let msg = format!("global {}; ${} line {} {{{}}}",
&self.id, &self.id, series, &points_str);
wish::tell_wish(&msg);
}
pub fn draw_ticklines(&self, colour: &str) {
let msg = format!("global {}; ${} ticklines {}",
&self.id, &self.id, colour);
wish::tell_wish(&msg);
}
pub fn plot(&self, series: &str, (x, y, z): (f64, f64, f64), text: &str,
direction: plotchart::Direction) {
let msg = format!("global {}; ${} plot {} {} {} {} {{{}}} {}",
&self.id, &self.id, series, x, y, z,
text, &direction.to_short_string());
wish::tell_wish(&msg);
}
pub fn series_smooth(&self, series: &str, smooth: bool) {
let msg = format!("global {}; ${} dataconfig {} -smooth {}",
&self.id, &self.id, series,
if smooth { "1" } else { "0" });
wish::tell_wish(&msg);
}
}