Skip to content

Commit

Permalink
feat(example): aloow example run at workspace root
Browse files Browse the repository at this point in the history
  • Loading branch information
duskmoon314 committed Jan 3, 2025
1 parent 8e5eda3 commit 4032970
Show file tree
Hide file tree
Showing 7 changed files with 2,054 additions and 8 deletions.
15 changes: 12 additions & 3 deletions examples/mpg_line.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
183 changes: 183 additions & 0 deletions examples/mpg_line.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4032970

Please sign in to comment.