Home

Awesome

CHARTER

A simple markdown DSL and C Library to generate svg and pgfplot (LaTeX) plot from a minimal syntax.

Example

Few examples are available in the gallery page of the wiki.

Simple syntax example:

title: reconstruction error vs compression
x-axis:
	label: compression
	mode: log
y-axis:
	label: mse
plot:
	x: 1 10    100
	y: 0 0.01  0.05
	label: f_avg
 	marker: s
 	ls: --

Resutls in:

result

Note: as the image is an svg the rendering of it is browser dependent.

DSL Syntax

syntaxdescription
plotcreate a new line plot
scattercreate a new scatter plot
barcreate a new bar plot
x-axisparameters for the x axis
y-axisparameters for the y axis
labellabel for axis or plot
xx values of a plot
yy values of a plot
colorcolour of a plot
line-width or lwplot line width
line-style or lsplot line style ('--' or 'dashed', '-' or 'normal', ':' or dotted, '/' or 'none')
bar-width or bwbar plot width
line-colorbar plot line color
markermarker style of a plot ('o', 'x', '+', 's', ' ')
rangemin and max value for an axis
modeaxis mode ('linear' or 'log')
titleplot title
widthplot width
heightplot height
csv://file_path#tagload a csv and use column tag as values
range: min max nsteplinear range to use as values
logrange: min max nsteplog range to use as values
math: f(x)math expression based on x to use as y value

commas and spaces are valid separator for arrays and the sytax in general. For the definitions spaces, tabs and : are equivalents. So x: 1 2 3 is equal to x 1,2,3.

Use as a library

if you want to include charter as a library here a simple example

#include "charter/parser.h"
#include "charter/renderer.h"

\***
 * YOUR CODE
 ***\
 chart * parsed = parse_chart(string_to_parse);
 /* chart is the structure you can also create it programmatically in your code
    and render it to svg using chart_to_svg */
 char * svg = chart_to_svg(parsed);
 chart_free(parsed);
\***\

Use as SVG generator

The build process generate as well an executable: charter. It is capable of generate an svg plot from a charter dsl file:

charter your_dsl_file > output.svg

Build and install

Use meson and ninja:

mkdir build
cd build
meson ..
ninja 
sudo ninja install

Future improvements

In the next future I will improve the svg quality, the memory performance, and the look and feel of the output plus the following features:

Marker integration

At the moment charter is integrated in Marker!

marker and charter

Credits