use std::{fmt::Debug, iter};
use crate::common::*;
use gnuplot::*;
mod common;
fn color_name<T: Debug>(color: &PlotOption<T>) -> String
{
match color
{
Color(color_type) => format!("{:?}", color_type),
_ => panic!(),
}
}
fn example(c: Common)
{
let x = 0..5;
let colors = [
Color("black".into()), Color(ColorType::RGBString("black")), Color("red".into()), Color(RGBString("#ff0000")), Color(RGBString("#ffff0000")), Color("#ff8888".into()), Color("#77ff0000".into()), Color(ColorType::RGBString("#ffff0000")), Color((128, 0, 255).into()), Color(RGBInteger(128, 0, 255)), Color((0.5, 0.0, 1.0).try_into().unwrap()), Color((64, 128, 0, 255).into()), Color(ARGBInteger(64, 128, 0, 255)), Color((0.25, 0.5, 0.0, 1.0).try_into().unwrap()), ];
let mut fg = Figure::new();
let ax = fg.axes2d();
ax.set_title(
"Demo of RGBString in various forms\nSee code comments for how to construct the colors",
&[],
)
.set_x_range(Fix(-9.0), Auto)
.set_legend(Graph(0.5), Graph(0.9), &[], &[Font("", 12.0)]);
let n_colors = colors.len();
for (i, color) in colors.into_iter().enumerate()
{
ax.box_xy_error_delta(
x.clone(),
iter::repeat((n_colors - 1) - i),
iter::repeat(0.4),
iter::repeat(0.2),
&[
Caption(&color_name(&color)),
LineWidth(1.0),
BorderColor("black".into()),
color,
],
);
}
ax.lines(
[0, 0],
[0, n_colors - 1],
&[
LineWidth(7.0),
Color(Black),
Caption(&color_name::<String>(&Color(Black))),
],
);
ax.lines(
[4, 4],
[0, n_colors - 1],
&[
LineWidth(7.0),
Color(Background),
Caption(&color_name::<String>(&Color(Background))),
],
);
ax.set_x_label(
"Labels can be colored using TextColor",
&[TextColor((128, 0, 255).into())],
);
c.show(&mut fg, "rgb_color");
let mut fg = Figure::new();
let ax = fg.axes2d();
let max_cb = 10.0;
ax.set_cb_range(Fix(0.0), Fix(max_cb));
for color_value in (0..=10).into_iter().step_by(2)
{
let color_float = color_value as f64;
let frac_color = Color(PaletteFracColor(color_float / max_cb));
let cb_range_color = Color(PaletteCBColor(color_float));
ax.box_xy_error_delta(
[color_value],
[0],
[0.4],
[0.4],
&[
Caption(&color_name(&frac_color)),
LineWidth(1.0),
BorderColor("black".into()),
frac_color,
],
)
.box_xy_error_delta(
[color_value],
[1],
[0.4],
[0.4],
&[
Caption(&color_name(&cb_range_color)),
LineWidth(1.0),
BorderColor("black".into()),
cb_range_color,
],
);
}
ax.set_x_range(Fix(-10.0), Fix(11.0))
.set_y_range(Fix(-0.5), Fix(1.5))
.set_legend(Graph(0.45), Graph(0.9), &[], &[Font("", 12.0)]);
c.show(&mut fg, "palette_colors");
}
fn main()
{
Common::new().map(|c| example(c));
}