Creating Theme Files

Theme files are specially crafted YAML fils which contain a list of colours and options which Prawn::Graph interprets to draw charts.

The Keynote Theme Explained

name: keynote
title: Keynote Theme
font_color: 'FFFFFF'
background_colour: '000000'
marker_colour: 'FFFFFF'
stroke_grid_markers: 0
colours:
 - '6886B4'
 - 'FDD84E'
 - '72AE6E'
 - 'D1695E'
 - '8A6EAF'
 - 'EFAA43'
 - 'FFFFFF'

The YAML above describes the Keynote theme theme. You’ll notice that I’m using color and colour interchangeably. This is deliberate, either spelling will work.

The name key should be a lowercase + underscores version of the name of the theme. Basically, what you would use for a method definition. This is what will be used to access this theme.

The title key is the name of the theme as it would be displayed in a list of themes; should be as readable as possible.

The font_colour / font_color key is the colour you wish the text to be rendered using. This applies to all text, including titles, axis labels.

The background_colour / background_color key is the colour you wish the background area of the graph to be filled with.

The marker_colour / marker_color key is the colour which will be used to draw the axis of the grid and the grid lines.

The stroke_grid_markers key should be set to 1 or 0, 1 if you want to draw the grid lines on your graph, 0 if you don’t.

The colours / colors key takes an array of HTML-style hexadecimal colours, these colours will be cycled through when drawing bars / lines / pie segments on your graph.

Registering your own theme

If you’ve created your own theme file, you can make it available to Prawn::Graph by calling Prawn::Chart::Themes._register_theme with the path to the YAML file which defines your theme. You can then use it just like any other theme by passing it on the :theme key to your chart’s method.