| 1 | package Chart::GGPlot::Backend::Plotly::Geom::Smooth; | ||
| 2 | |||
| 3 | # ABSTRACT: Chart::GGPlot's Plotly implementation for Geom::Smooth | ||
| 4 | |||
| 5 | use Chart::GGPlot::Class qw(:pdl); | ||
| 6 | |||
| 7 | our $VERSION = '0.002003'; # VERSION | ||
| 8 | |||
| 9 | extends qw(Chart::GGPlot::Backend::Plotly::Geom::Line); | ||
| 10 | |||
| 11 | use Module::Load; | ||
| 12 | |||
| 13 | use Chart::GGPlot::Backend::Plotly::Util qw( | ||
| 14 | to_rgb group_to_NA pdl_to_plotly | ||
| 15 | ); | ||
| 16 | use Chart::GGPlot::Backend::Plotly::Geom::Polygon; | ||
| 17 | use Chart::GGPlot::Backend::Plotly::Util qw(ribbon); | ||
| 18 | use Chart::GGPlot::Util qw(BAD); | ||
| 19 | |||
| 20 | around to_traces( $orig, $class : $df, $params, $plot ) { | ||
| 21 | return [] if $df->nrow == 0; | ||
| 22 | |||
| 23 | my $path = $df->copy; | ||
| 24 | $path->set('alpha', pdl(1)); # alpha for the path is always 1 | ||
| 25 | my $traces_fitted = $class->$orig( $path, $params, $plot ); | ||
| 26 | unless ( $df->exists('ymin') and $df->exists('ymax') ) { | ||
| 27 | return [@$traces_fitted]; | ||
| 28 | } | ||
| 29 | |||
| 30 | my $ribbon = ribbon($df); | ||
| 31 | $ribbon->set( 'color', BAD() ); | ||
| 32 | my $traces_confintv = | ||
| 33 | Chart::GGPlot::Backend::Plotly::Geom::Polygon->to_traces( $ribbon, | ||
| 34 | $params, $plot ); | ||
| 35 | for my $trace (@$traces_confintv) { | ||
| 36 | $trace->{hoverinfo} = 'x+y'; | ||
| 37 | } | ||
| 38 | |||
| 39 | return [ @$traces_confintv, @$traces_fitted ]; | ||
| 40 | } | ||
| 41 | |||
| 42 | __PACKAGE__->meta->make_immutable; | ||
| 43 | |||
| 44 | 1; | ||
| 45 | |||
| 46 | __END__ |