README.md
1# CHARTER
2A simple markdown **DSL** and **C Library** to generate *svg* and *pgfplot* (*LaTeX*) plot from a minimal syntax.
3
4
5
6## Example
7
8Few examples are available in the [gallery](https://github.com/Mandarancio/charter/wiki/Gallery) page of the wiki.
9
10Simple syntax example:
11
12```
13title: reconstruction error vs compression
14x-axis:
15 label: compression
16 mode: log
17y-axis:
18 label: mse
19plot:
20 x: 1 10 100
21 y: 0 0.01 0.05
22 label: f_avg
23 marker: s
24 ls: --
25```
26
27Resutls in:
28
29![result](test/test.svg)
30
31**Note:** as the image is an svg the rendering of it is browser dependent.
32
33## DSL Syntax
34
35| syntax | description |
36| :----- | :------ |
37|```plot```| create a new line plot|
38|```scatter```| create a new scatter plot|
39|```scatter```| create a new bar plot |
40|```x-axis```| parameters for the x axis |
41|```y-axis```| parameters for the y axis |
42|```label``` | label for axis or plot |
43|```x```| x values of a plot |
44|```y```| y values of a plot |
45|```color```| colour of a plot |
46|```line-width``` or ```lw```| plot line width |
47|```line-style``` or ```ls```| plot line style ('--' or 'dashed', '-' or 'normal', ':' or dotted, '/' or 'none')|
48|```bar-width``` or ```bw``` | bar plot width|
49|```line-color```| bar plot line color |
50|```marker```| marker style of a plot ('o', 'x', '+', 's', ' ')|
51|```range```| min and max value for an axis |
52|```mode``` | axis mode ('linear' or 'log') |
53|```title```| plot title |
54|```width```| plot width |
55|```height```| plot height |
56|```csv://file_path#tag```| load a csv and use column ```tag``` as values |
57|```range: min max nstep```| linear range to use as values |
58|```logrange: min max nstep```| log range to use as values |
59|```math: f(x)```| math expression based on x to use as y value |
60
61**commas** and **spaces** are valid separator for arrays and the sytax in general.
62For the definitions **spaces**, **tabs** and **:** are equivalents. So ```x: 1 2 3``` is equal to ```x 1,2,3```.
63
64## Use as a library
65if you want to include charter as a library here a simple example
66
67```c
68#include "charter/parser.h"
69#include "charter/renderer.h"
70
71\***
72 * YOUR CODE
73 ***\
74 chart * parsed = parse_chart(string_to_parse);
75 /* chart is the structure you can also create it programmatically in your code
76 and render it to svg using chart_to_svg */
77 char * svg = chart_to_svg(parsed);
78 chart_free(parsed);
79\***\
80```
81
82## Use as SVG generator
83
84The build process generate as well an executable: ```charter```. It is capable of generate an svg plot from a charter dsl file:
85
86```
87charter your_dsl_file > output.svg
88```
89
90## Build and install
91
92Use ```meson``` and ```ninja```:
93
94```bash
95mkdir build
96cd build
97meson ..
98ninja
99sudo ninja install
100```
101## Future improvements
102
103In the next future I will improve the svg quality, the memory performance, and the look and feel of the output plus the following features:
104
105 - more options on grid
106 - more styling options
107 - better typesettings
108
109## Marker integration
110At the moment _charter_ is integrated in [Marker](https://github.com/fabiocolacio/Marker/)!
111
112![marker and charter](marker_charter_support.png)
113
114## Credits
115
116 - [csv_parser](https://github.com/JamesRamm/csv_parserhttps://github.com/JamesRamm/csv_parser)
117 - [tinyexpr](https://github.com/codeplea/tinyexpr)
118