summaryrefslogtreecommitdiffstats
path: root/vendor/plotters/examples
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/plotters/examples
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/plotters/examples')
-rw-r--r--vendor/plotters/examples/3d-plot2.rs4
-rw-r--r--vendor/plotters/examples/colormaps.rs69
-rw-r--r--vendor/plotters/examples/mandelbrot.rs2
3 files changed, 71 insertions, 4 deletions
diff --git a/vendor/plotters/examples/3d-plot2.rs b/vendor/plotters/examples/3d-plot2.rs
index 0b5ca2131..b7138f2c5 100644
--- a/vendor/plotters/examples/3d-plot2.rs
+++ b/vendor/plotters/examples/3d-plot2.rs
@@ -36,9 +36,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
(-15..=15).map(|x| x as f64 / 5.0),
pdf,
)
- .style_func(&|&v| {
- (&HSLColor(240.0 / 360.0 - 240.0 / 360.0 * v / 5.0, 1.0, 0.7)).into()
- }),
+ .style_func(&|&v| (VulcanoHSL::get_color(v / 5.0)).into()),
)?;
root.present()?;
diff --git a/vendor/plotters/examples/colormaps.rs b/vendor/plotters/examples/colormaps.rs
new file mode 100644
index 000000000..4c8cc4d44
--- /dev/null
+++ b/vendor/plotters/examples/colormaps.rs
@@ -0,0 +1,69 @@
+use plotters::prelude::*;
+
+const OUT_FILE_NAME: &'static str = "plotters-doc-data/colormaps.png";
+
+fn main() -> Result<(), Box<dyn std::error::Error>> {
+ let colormaps_rgb: [(Box<dyn ColorMap<RGBColor>>, &str); 4] = [
+ (Box::new(ViridisRGB {}), "Viridis"),
+ (Box::new(BlackWhite {}), "BlackWhite"),
+ (Box::new(Bone {}), "Bone"),
+ (Box::new(Copper {}), "Copper"),
+ ];
+
+ let colormaps_hsl: [(Box<dyn ColorMap<HSLColor>>, &str); 2] = [
+ (Box::new(MandelbrotHSL {}), "MandelbrotHSL"),
+ (Box::new(VulcanoHSL {}), "VulcanoHSL"),
+ ];
+
+ let size_x: i32 = 800;
+ let n_colormaps = colormaps_rgb.len() + colormaps_hsl.len();
+ let size_y = 200 + n_colormaps as u32 * 100;
+ let root = BitMapBackend::new(OUT_FILE_NAME, (size_x as u32, size_y)).into_drawing_area();
+
+ root.fill(&WHITE)?;
+
+ let mut chart = ChartBuilder::on(&root)
+ .caption("Demonstration of predefined colormaps", ("sans-serif", 20))
+ .build_cartesian_2d(
+ -150.0..size_x as f32 + 50.0,
+ 0.0..3.0 * (n_colormaps as f32),
+ )?;
+
+ use plotters::style::text_anchor::*;
+ let centered = Pos::new(HPos::Center, VPos::Center);
+ let label_style = TextStyle::from(("monospace", 14.0).into_font()).pos(centered);
+
+ let mut colormap_counter = 0;
+ macro_rules! plot_colormaps(
+ ($colormap:expr) => {
+ for (colormap, colormap_name) in $colormap.iter() {
+ chart.draw_series(
+ (0..size_x as i32).map(|x| {
+ Rectangle::new([
+ (x as f32, 3.0*(n_colormaps - 1 - colormap_counter) as f32 + 0.5),
+ (x as f32+1.0, 3.0*(n_colormaps - 1 - colormap_counter) as f32 + 2.5)
+ ],
+ colormap.get_color_normalized(x as f32, 0.0, size_x as f32).filled())
+ })
+ )?;
+ chart.draw_series(
+ [Text::new(colormap_name.to_owned(), (-75.0, 3.0*(n_colormaps-1-colormap_counter) as f32 + 1.5), &label_style)]
+ )?;
+ colormap_counter+=1;
+ }
+ }
+ );
+
+ plot_colormaps!(colormaps_rgb);
+ plot_colormaps!(colormaps_hsl);
+
+ // To avoid the IO failure being ignored silently, we manually call the present function
+ root.present().expect("Unable to write result to file, please make sure 'plotters-doc-data' dir exists under current dir");
+ println!("Result has been saved to {}", OUT_FILE_NAME);
+
+ Ok(())
+}
+#[test]
+fn entry_point() {
+ main().unwrap()
+}
diff --git a/vendor/plotters/examples/mandelbrot.rs b/vendor/plotters/examples/mandelbrot.rs
index 413c319c6..b0d5799b2 100644
--- a/vendor/plotters/examples/mandelbrot.rs
+++ b/vendor/plotters/examples/mandelbrot.rs
@@ -28,7 +28,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
for (x, y, c) in mandelbrot_set(xr, yr, (pw as usize, ph as usize), 100) {
if c != 100 {
- plotting_area.draw_pixel((x, y), &HSLColor(c as f64 / 100.0, 1.0, 0.5))?;
+ plotting_area.draw_pixel((x, y), &MandelbrotHSL::get_color(c as f64 / 100.0))?;
} else {
plotting_area.draw_pixel((x, y), &BLACK)?;
}