Clicker 2.0 And You

Today I released version 1.99_01 to the CPAN. Version 2.0 is substantially different — API wise — from 1.x. I’ll cover a few of the ways here.

No More Simple

Firstly, I removed Chart::Clicker::Simple because the core module is more simple than Simple.pm was. Here’s an example of the new API.

use Chart::Clicker;
use Chart::Clicker::Data::Series;
use Chart::Clicker::Data::DataSet;
use Chart::Clicker::Renderer::Point;
 
my $cc = Chart::Clicker->new;
 
my $series = Chart::Clicker::Data::Series->new(
    keys    => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ],
    values  => [ 42, 25, 86, 23, 2, 19, 103, 12, 54, 9 ],
);
 
my $ds = Chart::Clicker::Data::DataSet->new(series => [ $series ]);
$cc->add_to_datasets($ds);
 
$cc->prepare();
$cc->draw();
$cc->write('/Users/gphat/foo.png');

Contexts

Aside from the à la carte creation of charts, the major complication in Clicker’s API has always been the handling of multiple axes. My solution to this has been the introduction of contexts. A context is a domain axis, a range axis and a renderer. By default there is a single context called ‘default’. All datasets added to a chart are associated with the default context unless you specify otherwise, like so:

$dataset->context('sales');

You can create new contexts easily.

my $ctx = Chart::Clicker::Context->new(
	name => 'sales',
	renderer => Chart::Clicker::Renderer::Area->new
);
$clicker->add_to_contexts($ctx);

Each context will be charted on unique axes and with whatever renderer it is set to. The upcoming cookbook will details advanced ways to change this behavior, but the default will over most people’s use cases.

Layout

Clicker previously required you to ‘add’ all the components of the chart manually. No longer! In removing Simple.pm I had Clicker simply add a set of default components. I’ll be working on a Cookbook for various customizations soon.

Under The Hood

The first major contribution to the 2.0 codebase was a patch from Ash Berlin that used Cairo’s clipping to replace the multiple-surface method that I had been using the past.

During YAPC::NA I added PDF and PostScript support and had a discussions with Guillermo and Stevan that pushed me to create a new stack underneath Clicker to facilitate some future features. I detailed these modules in a post on my personal blog.

In addition to the above Clicker is now Moose through-and-through, making extensive use of MooseX::AttributeHelpers.

2.0

I intend to release 2.0 soon, but there are still a few small bugs and missing features I want to complete. I also want to get started on the aforementioned Cookbook so that users can easily find out how to do advanced rendering. Stay tuned!

Leave a Reply