You can find poloto on github and crates.io. Documentation at docs.rs
A simple 2D plotting library that outputs graphs to SVG that can be styled using CSS.
Poloto graphs can be stylized using css either directly in the SVG, or from inside of html with an embedded svg. The latter allows the user to dynamically match the svg to their website's theme. The user can take full advantage of CSS, adding highlight on hover, animation, shadows, strokes, etc. Check out the github examples to see this. The latest graph outputs of the examples can be found in the assets folder.
You can see it in action in this rust book broccoli-book
See also poloto-chrono on github and crates.io. Allows for plotting unix time stamps.
Gaussian Example
use build;
// PIPE me to a file!
Output
Collatz Example
use *;
use build;
// PIPE me to a file!
Output
Custom Ticks Example
use format_move;
use build;
Output
Bar example
Output
Styling example
use *;
use ;
Output
Usecases
Poloto converts each plot into svg elements like circles. Because of this its not really suitable for plots with many many plots. For those you might want to use a library to lets you plot directly to a png/jpg image instead. You can certainly rasterize the generated svg image, but generating and displaying the svg wont be all that efficient if there are a ton of plots.
cloned
vs buffered
plot iterators
poloto runs through plot iterators twice. Once to get the min/max bounds, and a second time to scale all the plots by those min/max bounds. There are two ways to do this. One is to just clone the iterator, and consume both. The second way is to accumulate the items from one iterator into a Vec<>, and then just iterate over that vec. By default, poloto will use a Vec backed buffer. However, you can configure it to clone the iterator instead.
//Uses vec backed buffer
let data=;
plot.line;
//Cloned the iterator
let it=.take.zip;
plot.line;
Using the cloned method has pros and cons. The user has more control and can reduce memory usage. However they might accidentally increase memory usage.
More examples
Here are more examples that are presented in a jupyter notebook using evcxr. https://nbviewer.org/github/tiby312/poloto-project/blob/master/poloto-evcxr/float_int_test.ipynb https://nbviewer.org/github/tiby312/poloto-project/blob/master/poloto-evcxr/test_simple.ipynb
The source of the notebooks can be found here: https://github.com/tiby312/poloto-project/tree/master/poloto-evcxr
Escape protection
If a user tried to inject html through the title/xname/yname/tick format/ or plot names, the html escapes
will get turned into their encoded values. This protection is provided by the tagu
dependency crate.
CSS Usage Example
See the graphs in this report: broccoli_book
CSS classes
poloto[n]fill
- If the n'th plot requires fill. (e.g. linefill or histogram)poloto[n]stroke
- If the n'th plot requires stroke. (e.g. line or scatter)
Can I change the styling of the plots?
Yes! You can harness the power of CSS both in the svg, or outside in html with an embedded svg. Some things you can do:
- Change the color scheme to fit your html theme.
- Highlight one plot, make it dashed, or add hover effect
- Animate things using @keyframes
The Plotter
struct documents which css classes you can modify for the graph as a whole.
Each plot function documents which css classes you can modify to change that specific plot.
Scatter plots are done using SVG paths made up of lines of zero length. This allows you to change the radius of the scatter dots by changing the stroke width.
Formatting Tick Intervals
Poloto will first print intervals in normal decimal at the precision required to capture the differences in the step size between the intervals. If the magnitude of a number is detected to be too big or small, it may switch to scientific notation, still at the required precision. It will only switch if the scientific notation version is actually less characters than the normal decimal format which is not always the case when you consider the precision that might be required to capture the step size.
Even with the above system, there are cases where the numbers all have a really big magnitude, but are all really close together (small step size). In this case, there isn't really a good way to format it. In these cases, poloto will fall back to making the number relative to the first number.
How to render to png?
You can use resvg. Install that, and then run a command similar to:
resvg -w 1200 target/assets/collatz.svg target/assets/collatz.png