Skip to content

Commit

Permalink
Wip fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SiegeLord committed Jun 30, 2024
1 parent bcb592a commit 8d4ec77
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 46 deletions.
89 changes: 46 additions & 43 deletions gnuplot/examples/example3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,60 +21,63 @@ fn example(c: Common)
}
}

let mut fg = Figure::new();
//~ let mut fg = Figure::new();

fg.axes3d()
.set_title("Surface fg3.1", &[])
.surface(z1.iter(), w, h, Some((-4.0, -4.0, 4.0, 4.0)), &[])
.set_x_label("X", &[])
.set_y_label("Y", &[])
.set_z_label("Z", &[])
.set_z_range(Fix(-1.0), Fix(1.0))
.set_z_ticks(Some((Fix(1.0), 1)), &[Mirror(false)], &[])
.set_view(45.0, 45.0);
//~ fg.axes3d()
//~ .set_title("Surface fg3.1", &[])
//~ .surface(z1.iter(), w, h, Some((-4.0, -4.0, 4.0, 4.0)), &[])
//~ .set_x_label("X", &[])
//~ .set_y_label("Y", &[])
//~ .set_z_label("Z", &[])
//~ .set_z_range(Fix(-1.0), Fix(1.0))
//~ .set_z_ticks(Some((Fix(1.0), 1)), &[Mirror(false)], &[])
//~ .set_view(45.0, 45.0);

c.show(&mut fg, "example3_1");
//~ c.show(&mut fg, "example3_1");

let mut fg = Figure::new();
//~ let mut fg = Figure::new();

fg.axes3d()
.set_title("Map fg3.2", &[])
.surface(z1.iter(), w, h, None, &[])
.set_x_label("X", &[])
.set_y_label("Y", &[])
.set_view_map();
//~ fg.axes3d()
//~ .set_title("Map fg3.2", &[])
//~ .surface(z1.iter(), w, h, None, &[])
//~ .set_x_label("X", &[])
//~ .set_y_label("Y", &[])
//~ .set_view_map();

c.show(&mut fg, "example3_2");
//~ c.show(&mut fg, "example3_2");

let mut fg = Figure::new();

fg.set_data_directory(Some("C:/temp/gnuplot".into()));

fg.axes3d()
.set_pos_grid(2, 2, 0)
//~ .set_pos_grid(2, 2, 0)
.set_title("Base fg3.3", &[])
.show_contours(true, false, Cubic(10), Fix(""), Auto)
.surface(z1.iter(), w, h, Some((-4.0, -4.0, 4.0, 4.0)), &[])
.set_view(45.0, 45.0);

fg.axes3d()
.set_pos_grid(2, 2, 1)
.set_title("Surface", &[])
.show_contours(false, true, Linear, Fix(""), Auto)
.surface(z1.iter(), w, h, Some((-4.0, -4.0, 4.0, 4.0)), &[])
.set_view(45.0, 45.0);

fg.axes3d()
.set_pos_grid(2, 2, 2)
.set_title("Both + Fix Levels", &[])
.show_contours(true, true, Linear, Fix("%f"), Fix(1))
.show_contours(true, false, Cubic(10), Fix("Abc"), Auto)
.surface(z1.iter(), w, h, Some((-4.0, -4.0, 4.0, 4.0)), &[])
.set_view(45.0, 45.0);

fg.axes3d()
.set_pos_grid(2, 2, 3)
.set_title("Custom Levels", &[])
.show_contours_custom(true, false, Linear, Fix(""), Some(0f32).iter())
.surface(z1.iter(), w, h, Some((-4.0, -4.0, 4.0, 4.0)), &[])
.set_view(45.0, 45.0);
.set_view_map();
//~ .set_view(45.0, 45.0);

//~ fg.axes3d()
//~ .set_pos_grid(2, 2, 1)
//~ .set_title("Surface", &[])
//~ .show_contours(false, true, Linear, Fix(""), Auto)
//~ .surface(z1.iter(), w, h, Some((-4.0, -4.0, 4.0, 4.0)), &[])
//~ .set_view(45.0, 45.0);

//~ fg.axes3d()
//~ .set_pos_grid(2, 2, 2)
//~ .set_title("Both + Fix Levels", &[])
//~ .show_contours(true, true, Linear, Fix("%f"), Fix(1))
//~ .surface(z1.iter(), w, h, Some((-4.0, -4.0, 4.0, 4.0)), &[])
//~ .set_view(45.0, 45.0);

//~ fg.axes3d()
//~ .set_pos_grid(2, 2, 3)
//~ .set_title("Custom Levels", &[])
//~ .show_contours_custom(true, false, Linear, Fix(""), [0.1, 0.2, 0.3, 0.4].iter())
//~ .surface(z1.iter(), w, h, Some((-4.0, -4.0, 4.0, 4.0)), &[])
//~ .set_view(45.0, 45.0);

c.show(&mut fg, "example3_3");
}
Expand Down
20 changes: 18 additions & 2 deletions gnuplot/src/axes3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ impl Axes3D
}
);
writeln!(w);
writeln!(w, "set pm3d border retrace");

match self.contour_label
{
Expand All @@ -443,11 +444,26 @@ impl Axes3D
{
if s.is_empty()
{
writeln!(w, "unset clabel")
if version.major >= 6
{
writeln!(w, "set cntrlabel onecolor")
}
else
{
writeln!(w, "unset clabel")
}
}
else
{
writeln!(w, r#"set clabel "{}""#, s)
println!("{}", version.major);
if version.major >= 6
{
writeln!(w, r#"set cntrlabel "{}""#, s)
}
else
{
writeln!(w, r#"set clabel "{}""#, s)
}
}
}
};
Expand Down
12 changes: 11 additions & 1 deletion gnuplot/src/figure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ impl Figure
{
let output = Command::new("gnuplot").arg("--version").output()?;

if let Ok(version_string) = str::from_utf8(&output.stdout)
for version_string in [str::from_utf8(&output.stdout).ok().map(|s| s.to_string()), from_utf16(&output.stdout)].iter().flatten()
//~ if let Ok(version_string) =
{
let parts: Vec<_> = version_string.split(|c| c == ' ' || c == '.').collect();
if parts.len() > 2 && parts[0] == "gnuplot"
Expand All @@ -409,6 +410,7 @@ impl Figure
(parts[1].parse::<i32>(), parts[2].parse::<i32>())
{
self.version = Some(GnuplotVersion { major, minor });
break;
}
}
}
Expand Down Expand Up @@ -743,6 +745,14 @@ impl Drop for Figure
}
}

fn from_utf16(bytes: &[u8]) -> Option<String>
{
assert!(bytes.len() % 2 == 0);
let size = bytes.len() / 2;
let iter = (0..size).map(|i| u16::from_le_bytes([bytes[2 * i], bytes[2 * i + 1]]));
std::char::decode_utf16(iter).collect::<Result<String, _>>().ok()
}

#[test]
fn flush_test()
{
Expand Down

0 comments on commit 8d4ec77

Please sign in to comment.