View Source Contex.Gallery.Sample (ContEx v0.5.0)

Renders plots to be used in ExDocs and tests.

The idea is that each graph is displayed along its source code, so it's very easy to spot what is what. To shortern the source code displayed, though, aliases are imported but not shown.

Link to this section Summary

Functions

Encodes a div for our SVG.

Adds a graph to a documentation block.

Returns a timer function.

Will try and evaluate a set of files, by sticking them in order one after the other.

Link to this section Functions

Link to this function

encode_svg(svg, bgcolor)

View Source

Encodes a div for our SVG.

Unfortunately, we need to split it into multiple lines, as ExDoc is veeeeery slow with long text lines.

It also complains of SVG code being improperly formatted, and breaks the page.

So we encode the SVG as one long JS line, and then stick it into the container DIV we just created.

Adds a graph to a documentation block.

Usage:

import Contex.Gallery.Sample, only: [graph: 1]

graph(title: "A stacked sample",
      file: "bar_charts_log_stacked.sample",
      info: "Some Markdown description")

If there are rendering errors, a message is printed on stdout and the full text of the error is shown on the docs. We don't want this to break, as docs are generated at compile time, so if they break, your code does not compile!

Returns a timer function.

By calling it, we get the number of elapsed milliseconds since the function was created.

Link to this function

safely_evaluate_svg(files)

View Source

Will try and evaluate a set of files, by sticking them in order one after the other.

If all goes well, it will return the SVG generated and how long execution took.

If there are any errors, it will return the error, the complete source code that was evaluated (with includes) and how long execution took in ms.