aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 686d2b329b82b1be6fc79fb73348da59768659cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# wmap-renderer

A rust renderer for `wmap` formatted wardley maps parsed with [`wmap-parser`][wmap-parser-rust].

## Features

- Can render to PNG or SVG.
- Rendering logic attempts to replicate [map][map]'s output.

## Installation

Add it to your project with cargo add

```bash
cargo add wmap-renderer
```

## Usage

```rust
use wmap_renderer::{render_to_png, render_to_svg, Configuration, StageType};

let map_source = r#"
Computer (90, 20)
Silicon Ore (80, 90)
Computer -> Silicon Ore
"#;

let map = wmap_parser::parse(map_source);
let config = Configuration::default();

// Render to PNG
let png_data = render_to_png(&map, StageType::Activities, &config)?;
std::fs::write("map.png", png_data)?;

// Render to SVG
let svg_data = render_to_svg(&map, StageType::Activities, &config)?;
std::fs::write("map.svg", svg_data)?;
```

## Configuration

The renderer lets you configure sizes, colors, and font.

```rust
let mut config = Configuration::default();
config.theme.colors.vertex = "#FF0000".to_string();
config.theme.sizes.vertex_size = 30.0;
config.options.show_background = false;
```

## Development

### Running Examples

```bash
make examples
```

### Running Tests

```bash
make test
```

## Performance

The drawing is not optimized for live-editing. It's relatively quick to
generate a single image. On an M1 Pro mac, our xample map renders in about ~2ms,
while a larger map with slightly under 2000 entities does so in ~140ms.

Turning off smart labels doesn't have a big effect on medium to small maps,
but in our large map test it renders in ~97ms instead.

You can run the benchmarks by using:

```bash
make benchmark
```