From 4032970f730f26f0ecc870e0b8655a55739b3e05 Mon Sep 17 00:00:00 2001 From: Campbell He Date: Fri, 3 Jan 2025 16:52:55 +0800 Subject: [PATCH] feat(example): aloow example run at workspace root --- examples/mpg_line.rs | 15 +- examples/mpg_line.svg | 183 +++++ examples/mpg_line_shape.svg | 1412 ++++++++++++++++++++++++++++++++++ examples/mpg_point.rs | 18 +- examples/mpg_point.svg | 1 - examples/mpg_point_color.svg | 1 - examples/mpg_point_shape.svg | 432 +++++++++++ 7 files changed, 2054 insertions(+), 8 deletions(-) create mode 100644 examples/mpg_line.svg create mode 100644 examples/mpg_line_shape.svg create mode 100644 examples/mpg_point_shape.svg diff --git a/examples/mpg_line.rs b/examples/mpg_line.rs index 910c0c9..27b529b 100644 --- a/examples/mpg_line.rs +++ b/examples/mpg_line.rs @@ -1,15 +1,24 @@ +use std::{env, path::PathBuf}; + use gongbi::{aes, geom_line, plot}; use polars::prelude::*; fn main() -> anyhow::Result<()> { + let examples_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("examples"); + let mpg = examples_dir.join("mpg.csv"); + let mpg = CsvReadOptions::default() .with_has_header(true) - .try_into_reader_with_file_path(Some("examples/mpg.csv".into()))? + .try_into_reader_with_file_path(Some(mpg))? .finish()?; - let plot = plot!(mpg, aes!(hwy)) + geom_line!(aes!(label = "hwy")); + let plot = plot!(mpg.clone(), aes!(hwy)) + geom_line!(aes!(label = "hwy")); + + plot.to_svg(examples_dir.join("mpg_line.svg"), (1024, 768))?; + + let plot = plot!(mpg.clone(), aes!(hwy)) + geom_line!(aes!(shape = 2)); - plot.to_svg("mpg_line.svg", (1024, 768))?; + plot.to_svg(examples_dir.join("mpg_line_shape.svg"), (1024, 768))?; Ok(()) } diff --git a/examples/mpg_line.svg b/examples/mpg_line.svg new file mode 100644 index 0000000..b46d2e7 --- /dev/null +++ b/examples/mpg_line.svg @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +y + + +hwy + + + + + + + + + + + + + + +15.0 + + + +20.0 + + + +25.0 + + + +30.0 + + + +35.0 + + + +40.0 + + + + +0.0 + + + +50.0 + + + +100.0 + + + +150.0 + + + +200.0 + + + + diff --git a/examples/mpg_line_shape.svg b/examples/mpg_line_shape.svg new file mode 100644 index 0000000..11e0f2c --- /dev/null +++ b/examples/mpg_line_shape.svg @@ -0,0 +1,1412 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +y + + +hwy + + + + + + + + + + + + + + +15.0 + + + +20.0 + + + +25.0 + + + +30.0 + + + +35.0 + + + +40.0 + + + + +0.0 + + + +50.0 + + + +100.0 + + + +150.0 + + + +200.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/mpg_point.rs b/examples/mpg_point.rs index c7dea85..a422276 100644 --- a/examples/mpg_point.rs +++ b/examples/mpg_point.rs @@ -1,23 +1,35 @@ +use std::{env, path::PathBuf}; + use gongbi::{aes, geom_point, labs, plot}; use polars::prelude::*; fn main() -> anyhow::Result<()> { + let examples_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("examples"); + let mpg = examples_dir.join("mpg.csv"); + let mpg = CsvReadOptions::default() .with_has_header(true) - .try_into_reader_with_file_path(Some("mpg.csv".into()))? + .try_into_reader_with_file_path(Some(mpg))? .finish()?; let plot = plot!(mpg.clone(), aes!("displ", "hwy")) + geom_point!() + labs!(caption = "Demo of geom_point"); - plot.to_svg("mpg_point.svg", (1024, 768))?; + plot.to_svg(examples_dir.join("mpg_point.svg"), (1024, 768))?; + // plot.to_png(examples_dir.join("mpg_point.png"), (1024, 768))?; let plot = plot!(mpg.clone(), aes!("displ", "hwy", color = "blue")) + geom_point!() + labs!(caption = "Demo of geom_point with color"); - plot.to_svg("mpg_point_color.svg", (1024, 768))?; + plot.to_svg(examples_dir.join("mpg_point_color.svg"), (1024, 768))?; + + let plot = plot!(mpg.clone(), aes!("displ", "hwy")) + + geom_point!(aes!(shape = 0)) + + labs!(caption = "Demo of geom_point with shape"); + + plot.to_svg(examples_dir.join("mpg_point_shape.svg"), (1024, 768))?; Ok(()) } diff --git a/examples/mpg_point.svg b/examples/mpg_point.svg index 9b174d0..fc6ffcb 100644 --- a/examples/mpg_point.svg +++ b/examples/mpg_point.svg @@ -429,5 +429,4 @@ displ - diff --git a/examples/mpg_point_color.svg b/examples/mpg_point_color.svg index 364b5e6..1098e74 100644 --- a/examples/mpg_point_color.svg +++ b/examples/mpg_point_color.svg @@ -429,5 +429,4 @@ displ - diff --git a/examples/mpg_point_shape.svg b/examples/mpg_point_shape.svg new file mode 100644 index 0000000..02ed397 --- /dev/null +++ b/examples/mpg_point_shape.svg @@ -0,0 +1,432 @@ + + + +Demo of geom_point with shape + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +hwy + + +displ + + + + + + + + + + + + + + + +15.0 + + + +20.0 + + + +25.0 + + + +30.0 + + + +35.0 + + + +40.0 + + + + +2.0 + + + +3.0 + + + +4.0 + + + +5.0 + + + +6.0 + + + +7.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +