SlideShare a Scribd company logo
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 currently Though 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-clicker Esp: https://github.com/gphat/chart-clicker/tree/master/example Github forks (and more) of clicker https://github.com/tomlanyon/chart-clicker Chart::Clicker::Tutorial
Blog: http://www.onemogin.com/blog/category/chartclicker
Chart::Clicker components Clicker Object Handles titles, datasets, data writes, contexts. Series Objects X data (keys), Y data (values), labels Dataset objects Contain 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.

More Related Content

Chart clicker presentation

  • 1. Chart::Clicker A plotting module for Perl
  • 2. As the author says: “Chart::Clicker aims to be a powerful, extensible charting package that creates really pretty output.” Why Chart::Clicker?
  • 3. Chart::Clicker underlying technologies Overall code base: Moose classes.
  • 5. ColorAllocator is developed from Color::Scheme
  • 6. Color objects can use Color::Library named colors.
  • 7. Geometric entities represented as Geometry::Primitive objects.
  • 9. Unavailable in Active Perl currently Though chk out Perl Monks thread on this topic. Tends to be long (30-45 mins to install).
  • 10. Works best if you preinstall the Cairo module. The package libcairo-perl in Ubuntu
  • 11. Issues with Cairo cause install issues with CENTOS.
  • 12. Output PNG, SVG, PDF and Postscript
  • 13. Specify when you create your clicker object.
  • 14. my $cc = Chart::Clicker->new( format => 'pdf', ..
  • 15. When specifying format, can specify size as well.
  • 16. If you expect to post-process the file, then bigger is better.You can shrink the image after the fact.
  • 17. Resources Author's github: http://github.com/gphat/chart-clicker Esp: https://github.com/gphat/chart-clicker/tree/master/example Github forks (and more) of clicker https://github.com/tomlanyon/chart-clicker Chart::Clicker::Tutorial
  • 19. Chart::Clicker components Clicker Object Handles titles, datasets, data writes, contexts. Series Objects X data (keys), Y data (values), labels Dataset objects Contain 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.
  • 20. 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);
  • 21. Axes and Contexts Contexts contain 2 axes, a renderer, and a name. Contexts can/will be assigned to a dataset.
  • 22. Axis objects:Can set tick count, and upper and lower bounds.
  • 23. For some reason, pie charts still require a nonzero axis length.
  • 24. If you mix plot types (lines and points), you'll need more than one context. Turn off the extra axes if necessary.
  • 25. Renderers Plenty of Renderer objects Point, Pie, Bubble, Bar, Area, Line
  • 26. StackedArea, StackedBar, PolarArea, CandleStick, HeatMap, etc. The default renderer is a line. If you don't see one initialized, that's why.
  • 27. my $context = Chart::Clicker::Context->new( name => 'sales' ); $clicker->add_to_contexts($context); $dataset->context('sales'); $clicker->add_to_datasets($dataset);
  • 28. # # 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);
  • 29. 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);
  • 30. Colors and ColorAllocators Chart::Clicker has good default colors
  • 31. 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
  • 32. Default order = 270,90,180,0, 45, 135, 215, 305, etc.
  • 33. 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.
  • 34. Named colors can be accessed through the from_color_library method of the Graphics::Color::RGB object.
  • 35. 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);
  • 36. # # 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 ); }
  • 37. Complementary Tools Configuration Modules – soft code your graphs. Config::Simple, Config::General, etc. PDL and PDL::Stats – curve fitting, numerical methods, statistics.
  • 38. Image::Magick – The Annotate method can be used to label graphs (will have to DIY the Geometry)
  • 39. GIMP/Photoshop – format translation. Tiling multiple images as a PDF. Simple inset graphs.
  • 40. Fedex-Kinkos – next day online color prints
  • 41. Acknowledgements Cory G. Watson, for Graph::Clicker and many of the code examples shown in this slide show.
  • 42. Bruce Gray, who suggested I look at this module.
  • 43. Stephen Cristol, who puts up with my off topic statistics questions.
  • 44. Atlanta Perl Mongers, for giving me the opportunity to present to their membership.