Chart-Dygraphs
view release on metacpan or search on metacpan
"dist_version" => "0.007",
"license" => "perl",
"module_name" => "Chart::Dygraphs",
"recursive_test_files" => 1,
"requires" => {
"Exporter" => 0,
"HTML::Show" => 0,
"JSON" => 0,
"Moose" => 0,
"Params::Validate" => 0,
"Ref::Util" => 0,
"Text::Template" => 0,
"strict" => 0,
"utf8" => 0,
"warnings" => 0
},
"test_requires" => {
"Test::More" => 0,
"Test::Most" => 0
}
);
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: Chart-Dygraphs
requires:
Exporter: '0'
HTML::Show: '0'
JSON: '0'
Moose: '0'
Params::Validate: '0'
Ref::Util: '0'
Text::Template: '0'
strict: '0'
utf8: '0'
warnings: '0'
resources:
bugtracker: https://github.com/pablrod/p5-Chart-Dygraphs/issues
homepage: https://github.com/pablrod/p5-Chart-Dygraphs
repository: https://github.com/pablrod/p5-Chart-Dygraphs.git
version: '0.007'
x_serialization_backend: 'YAML::Tiny version 1.69'
lib/Chart/Dygraphs.pm view on Meta::CPAN
use warnings;
use utf8;
use Exporter 'import';
our @EXPORT_OK = qw(show_plot);
use JSON;
use Params::Validate qw(:all);
use Text::Template;
use HTML::Show;
use Ref::Util;
our $VERSION = '0.007'; # VERSION
# ABSTRACT: Generate html/javascript charts from perl data using javascript library Dygraphs
sub render_full_html {
my %params = validate( @_,
{ data => { type => SCALAR | ARRAYREF | OBJECT },
options => { type => HASHREF, default => { showRangeSelector => 1 } },
render_html_options => { type => HASHREF,
lib/Chart/Dygraphs.pm view on Meta::CPAN
}
}
);
return _render_html_wrap(
_render_cell( _process_data_and_options( @params{qw(data options)} ), $params{'render_html_options'}, '' ) );
}
sub _transform_data {
my $data = shift;
my $string_data = "";
if ( Ref::Util::is_plain_arrayref($data) ) {
$string_data .= "[" . ( join( ',', map { _transform_data($_) } @$data ) ) . "]";
} elsif ( Ref::Util::is_plain_hashref($data) ) {
return "not supported";
} elsif ( Ref::Util::is_blessed_ref($data) && $data->isa('DateTime') ) {
return 'new Date("' . $data . '")';
} else {
return $data;
}
return $string_data;
}
sub _process_data_and_options {
my $data = shift();
my $options = shift();
my $json_formatter = JSON->new->utf8;
local *PDL::TO_JSON = sub { $_[0]->unpdl };
if ( Ref::Util::is_blessed_ref($data) ) {
my $adapter_name = 'Chart::Dygraphs::Adapter::' . ref $data;
eval {
load $adapter_name;
my $adapter = $adapter_name->new( data => $data );
$data = $adapter->series();
};
if ($@) {
warn 'Cannot load adapter: ' . $adapter_name . '. ' . $@;
}
}
( run in 0.263 second using v1.01-cache-2.11-cpan-4d50c553e7e )