Created
October 25, 2012 03:49
-
-
Save alecchen/3950324 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
package Geometry::Primitive::Triangle; | |
use Moose; | |
use Geometry::Primitive::Point; | |
extends 'Geometry::Primitive::Polygon'; | |
has 'origin' => ( | |
is => 'rw', | |
isa => 'Geometry::Primitive::Point', | |
coerce => 1, | |
); | |
has 'width' => ( | |
is => 'rw', | |
isa => 'Num', | |
required => 1 | |
); | |
override 'point_count' => sub { | |
my $self = shift; | |
my @points; | |
my ($x, $y, $width) = ($self->origin->x, $self->origin->y, $self->width); | |
push @points, [$x - $width/2, $y + (sqrt(3)/6*$width)]; | |
push @points, [$x + $width/2, $y + (sqrt(3)/6*$width)]; | |
push @points, [$x, $y - (sqrt(3)/3*$width)]; | |
map { $self->add_point(Geometry::Primitive::Point->new(x => $_->[0], y => $_->[1])) } @points; | |
return scalar @points; | |
}; | |
package main; | |
use Modern::Perl; | |
use Smart::Comments; | |
use Chart::Clicker; | |
use Chart::Clicker::Data::Series; | |
use Chart::Clicker::Data::DataSet; | |
use Chart::Clicker::Drawing::ColorAllocator; | |
use Chart::Clicker::Renderer::Point; | |
use Readonly; | |
Readonly my $BLUE => Graphics::Color::RGB->new(red => 0, green => 0, blue => 0.75, alpha => 1); | |
Readonly my $RED => Graphics::Color::RGB->new(red => 0.75, green => 0, blue => 0, alpha => 0.8); | |
Readonly my $GREY => Graphics::Color::RGB->new(red => 0.9, green => 0.9, blue => 0.9, alpha => 1); | |
Readonly my $SHAPE_BRUSH => Graphics::Primitive::Brush->new(width => 2, color => $BLUE); | |
my $chart = Chart::Clicker->new; | |
my $ca = Chart::Clicker::Drawing::ColorAllocator->new; | |
my $context = $chart->get_context('default'); | |
my $mark_context = Chart::Clicker::Context->new(name => 'mark'); | |
$mark_context->share_axes_with($context); | |
my $series = Chart::Clicker::Data::Series->new( | |
keys => [ 1,2,3,4,5 ], | |
values => [ 52,74,52,82,14 ], | |
); | |
my $dataset = Chart::Clicker::Data::DataSet->new(series => [$series]); | |
my $mark_dataset = Chart::Clicker::Data::DataSet->new(series => [$series]); | |
$mark_dataset->context('mark'); | |
$chart->add_to_contexts($mark_context); | |
$mark_context->renderer(Chart::Clicker::Renderer::Point->new); | |
$mark_context->renderer->shape(Geometry::Primitive::Triangle->new({width => 15})); | |
$mark_context->renderer->shape_brush($SHAPE_BRUSH); | |
my $x_axis = $context->domain_axis; | |
my $y_axis = $context->range_axis; | |
$x_axis->fudge_amount(0.1); | |
$y_axis->fudge_amount(0.1); | |
$chart->add_to_datasets($dataset); | |
$chart->add_to_datasets($mark_dataset); | |
$ca->add_to_colors($BLUE); | |
$ca->add_to_colors($GREY); | |
$chart->color_allocator($ca); | |
$chart->write_output('chart.png'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment