| 1 | package Wight::Chart::Google; | ||
| 2 | |||
| 3 | #ABSTRACT: Save google charts to images using phantomjs | ||
| 4 | |||
| 5 | our $VERSION = '0.003'; # VERSION | ||
| 6 | |||
| 7 | 2 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 2 | ▶ | use JSON::XS; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 2 | ▶ | use Encode; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | extends 'Wight::Chart'; | ||
| 11 | 0 | ▶ | sub src_html { 'google.html' } |
|
Subroutine
src_html: not called CC=1 SCAR=6.9
| |||
| 12 | |||
| 13 | #TODO: import roles for each type for more options | ||
| 14 | my $types = { | ||
| 15 | line => "LineChart", | ||
| 16 | area => "AreaChart", | ||
| 17 | bar => "BarChart", | ||
| 18 | pie => "PieChart", | ||
| 19 | spark => 'ImageSparkLine', | ||
| 20 | }; | ||
| 21 | |||
| 22 | has 'type' => ( is => 'rw', required => 1, isa => sub { $types->{$_[0]} } ); | ||
| 23 | has 'border' => ( is => 'rw', default => 100 ); | ||
| 24 | |||
| 25 | 0 | ▶ | sub render { |
|
Subroutine
render: not called CC=1 SCAR=6.9
| |||
| 26 | 0 | my ($self) = @_; | |
| 27 | 0 | my $w = $self->wight; | |
| 28 | my $options = { | ||
| 29 | chartArea => { | ||
| 30 | width => $self->width - $self->border, | ||
| 31 | height => $self->height - $self->border, | ||
| 32 | }, | ||
| 33 | 0 | %{$self->options} | |
| 34 | }; | ||
| 35 | |||
| 36 | my $args = decode_utf8(encode_json({ | ||
| 37 | options => $options, | ||
| 38 | 0 | type => $types->{$self->type}, | |
| 39 | rows => $self->rows, | ||
| 40 | columns => $self->columns, | ||
| 41 | })); | ||
| 42 | #warn $args; | ||
| 43 | 0 | $w->evaluate("drawChart($args)"); | |
| 44 | 0 | $w->render($self->output); | |
| 45 | } | ||
| 46 | |||
| 47 | |||
| 48 | 1; | ||
| 49 | |||
| 50 | __END__ | ||