diff options
| author | Ruben Beltran del Rio <jj@r.bdr.sh> | 2025-12-16 10:40:44 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <jj@r.bdr.sh> | 2025-12-16 10:55:34 +0100 |
| commit | f08648e4b5a9f7855a2ed9068a386e2f3c596322 (patch) | |
| tree | 1f1567ea609a1f74aaeab3cbbfdb249c5c47d723 /examples/generate_map.rs | |
Initial implementation
Diffstat (limited to 'examples/generate_map.rs')
| -rw-r--r-- | examples/generate_map.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/generate_map.rs b/examples/generate_map.rs new file mode 100644 index 0000000..8b9cf80 --- /dev/null +++ b/examples/generate_map.rs @@ -0,0 +1,38 @@ +use std::fs; +use wmap_renderer::{render_to_png, render_to_svg, Configuration, StageType}; + +fn main() -> Result<(), Box<dyn std::error::Error>> { + // Read the example.wmap file + let map_source = fs::read_to_string("examples/example.wmap")?; + let map = wmap_parser::parse(&map_source); + let config = Configuration::default(); + + // Generate PNG with smart positioning + println!("Generating PNG with smart positioning..."); + let png_data = render_to_png(&map, StageType::Activities, &config)?; + fs::write("example.png", png_data)?; + println!("Generated example.png"); + + // Generate SVG with smart positioning + println!("Generating SVG with smart positioning..."); + let svg_data = render_to_svg(&map, StageType::Activities, &config)?; + fs::write("example.svg", svg_data)?; + println!("Generated example.svg"); + + // Generate with different stage type + println!("Generating with publication types stage type..."); + let png_publication_types = render_to_png(&map, StageType::PublicationTypes, &config)?; + fs::write("example_publication_types.png", png_publication_types)?; + println!("Generated example_publication_types.png"); + + // Generate without smart positioning (simple right-side positioning) + println!("Generating without smart positioning..."); + let mut config_no_smart = Configuration::default(); + config_no_smart.options.smart_label_positioning = false; + let png_no_smart = render_to_png(&map, StageType::Activities, &config_no_smart)?; + fs::write("example_no_smart_positioning.png", png_no_smart)?; + println!("Generated example_no_smart_positioning.png"); + + println!("\nAll examples generated successfully!"); + Ok(()) +} |