Chart clicker presentation

download Chart clicker presentation

If you can't read please download the document

Transcript of Chart clicker presentation

Chart::Clicker

A plotting module for Perl

As the author says:

Chart::Clicker aims to be a powerful, extensible charting package that creates really pretty output.

Why Chart::Clicker?

Chart::Clicker underlying technologies

Overall code base: Moose classes.

Renderers are written in Cairo.

ColorAllocator is developed from Color::Scheme

Color objects can use Color::Library named colors.

Geometric entities represented as Geometry::Primitive objects.

Installation

Via CPAN

Unavailable in Active Perl currentlyThough chk out Perl Monks thread on this topic.

Tends to be long (30-45 mins to install).

Works best if you preinstall the Cairo module.The package libcairo-perl in Ubuntu

Issues with Cairo cause install issues with CENTOS.

Output

PNG, SVG, PDF and Postscript

Specify when you create your clicker object.

my $cc = Chart::Clicker->new( format => 'pdf', ..

When specifying format, can specify size as well.

If you expect to post-process the file, then bigger is better.You can shrink the image after the fact.

Resources

Author's github: http://github.com/gphat/chart-clickerEsp: https://github.com/gphat/chart-clicker/tree/master/example

Github forks (and more) of clickerhttps://github.com/tomlanyon/chart-clicker

Chart::Clicker::Tutorial

Blog: http://www.onemogin.com/blog/category/chartclicker

Chart::Clicker components

Clicker ObjectHandles titles, datasets, data writes, contexts.

Series ObjectsX data (keys), Y data (values), labels

Dataset objectsContain 1 or more series objects, and will be assigned a context.

DON'T AVOID using Series and Datasets.Otherwise you'll be stuck with trivial graphs.

my $cc = Chart::Clicker->new( format =>'png', height => 480, width => 640 );my $series1 = Chart::Clicker::Data::Series->new( keys => \@x_data,, values => \@y_data,);$series1->name('First Line');## lots more series#my $ds = Chart::Clicker::Data::DataSet->new( series => [ $series1, $series2, $series3, $series4, $series5, $series6, $series7, $series8 ] );$cc->add_to_datasets($ds);

Axes and Contexts

Contexts contain 2 axes, a renderer, and a name. Contexts can/will be assigned to a dataset.

Axis objects:Can set tick count, and upper and lower bounds.

For some reason, pie charts still require a nonzero axis length.

If you mix plot types (lines and points), you'll need more than one context.Turn off the extra axes if necessary.

Renderers

Plenty of Renderer objectsPoint, Pie, Bubble, Bar, Area, Line

StackedArea, StackedBar, PolarArea, CandleStick, HeatMap, etc.

The default renderer is a line. If you don't see one initialized, that's why.

my $context = Chart::Clicker::Context->new( name => 'sales' ); $clicker->add_to_contexts($context); $dataset->context('sales'); $clicker->add_to_datasets($dataset);

## Creating a context and then setting up Axis values.
# %cfg values are assigned via a Config::Simple object.#my $defctx = $cc->get_context('default');$defctx->domain_axis->label($cfg{"default.X_Axis"});$defctx->domain_axis->range( Chart::Clicker::Data::Range->new( lower => $cfg{"default.X_Lower"}, upper => $cfg{"default.X_Upper"} ) );$defctx->domain_axis->ticks( $cfg{"default.X_Ticks"});$defctx->range_axis->label($cfg{"default.Y_Axis"});$defctx->range_axis->range( Chart::Clicker::Data::Range->new( lower => $cfg{"default.Y_Lower"}, upper => $cfg{"default.Y_Upper"} ) );$defctx->range_axis->ticks($cfg{"default.Y_Ticks"});$defctx->renderer(Chart::Clicker::Renderer::Point->new);

Contexts: sharing axes

Contexts can share axes. The Chart::Clicker::Context perldocs shows this method:

$context_a->share_axes_with($context_b);

Also possible is

$self->range_axis($other_context->range_axis); $self->domain_axis($other_context->domain_axis);

Colors and ColorAllocators

Chart::Clicker has good default colors

That said, Chart::Clicker::Drawing::ColorAllocator exists.The Allocator is designed to choose color values equally spaced on the color chart.

Colors can specified with rgb floating point values and an alpha value (floating) (object), or by a number between 0 and 359.Red = 0, Green = 180, Yellow = 90, Blue = 270

Default order = 270,90,180,0, 45, 135, 215, 305, etc.

More color notes

By creating color objects and then using the method add_to_colors with your ColorAllocator, then those colors will be stacked in order of the series collected in your dataset.

Named colors can be accessed through the from_color_library method of the Graphics::Color::RGB object.

my $ca = Chart::Clicker::Drawing::ColorAllocator->new; # this hash is simply here to make things readable and cleaner, you can always call G::C::R inline my $red = Graphics::Color::RGB->new({ red => .75, green => 0, blue => 0, alpha => .8 }); my $green = Graphics::Color::RGB->new({ red => 0,green => .75, blue=> 0, alpha=> .8 }); my $blue = Graphics::Color::RGB->new({ red => 0, green => 0, blue => .75, alpha => .8 }),

my $chart = Chart::Clicker->new;

# Create an empty dataset that we can add to my $dataset = Chart::Clicker::Data::DataSet->new;

$dataset->add_to_series(Chart::Clicker::Data::Series->new( keys => [ 1,2,3,4,5 ], values => [ 52,74,52,82,14 ] )); # add a color - note that the order of colors and the order of the # series must match, the first series will use the first color and so on # see contexts and axes for alternate ways of doing this $ca->add_to_colors($blue);

## if $colorlist non-empty, it contains Color::Library# colors.#if ( scalar @{$colorlist} > 0 ) { my $rgb = new Graphics::Color::RGB; my $colors; for (@{$colorlist}) { push @{$colors}, $rgb->from_color_library( $_ ); } my $ca = Chart::Clicker::Drawing::ColorAllocator->new( { colors => $colors }); $cc->color_allocator( $ca );}

Complementary Tools

Configuration Modules soft code your graphs.Config::Simple, Config::General, etc.

PDL and PDL::Stats curve fitting, numerical methods, statistics.

Image::Magick The Annotate method can be used to label graphs (will have to DIY the Geometry)

GIMP/Photoshop format translation. Tiling multiple images as a PDF. Simple inset graphs.

Fedex-Kinkos next day online color prints

Acknowledgements

Cory G. Watson, for Graph::Clicker and many of the code examples shown in this slide show.

Bruce Gray, who suggested I look at this module.

Stephen Cristol, who puts up with my off topic statistics questions.

Atlanta Perl Mongers, for giving me the opportunity to present to their membership.