| 1 | package Chart::GGPlot::Backend::Plotly::Geom::Boxplot; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Chart::GGPlot's Plotly implementation for Geom::Boxplot | ||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Chart::GGPlot::Class qw(:pdl); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '0.002003'; # VERSION | |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 1 | with qw(Chart::GGPlot::Backend::Plotly::Geom); | |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use List::AllUtils qw(max pairmap); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Module::Load; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Chart::GGPlot::Backend::Plotly::Util qw(to_px to_rgb pdl_to_plotly); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Chart::GGPlot::Geom::Boxplot; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Chart::GGPlot::Geom::Point; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | classmethod split_on () { [qw(color fill size)] } | ||||||||||||||||||||||||||||||||
|
Subroutine
split_on: not called CC=3 SCAR=22.6
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | classmethod prepare_data ($data, $prestats_data, @rest) { | ||||||||||||||||||||||||||||||||
|
Subroutine
prepare_data: not called CC=4 SCAR=30.0
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 22 | 0 | my @join_on_columns = qw(PANEL group); | |||||||||||||||||||||||||||||||||
| 23 | 0 | my @prestats_data_columns = map { $prestats_data->at($_) } @join_on_columns; | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 0 | my $prestats_y = $prestats_data->at('y'); | |||||||||||||||||||||||||||||||||
| 26 | 0 | my %prestats_y_grouped; # PANEL;group => $y_data | |||||||||||||||||||||||||||||||||
| 27 | 0 | for my $ridx ( 0 .. $prestats_data->nrow - 1 ) { | |||||||||||||||||||||||||||||||||
| 28 | my @key_values = | ||||||||||||||||||||||||||||||||||
| 29 | 0 | map { $_->at($ridx) } @prestats_data_columns; | |||||||||||||||||||||||||||||||||
| 30 | 0 | my $k = join( $;, @key_values ); | |||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $prestats_y_grouped{$k} //= []; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$prestats_y_grouped{$k} //= []
MC/DC0%0/1
$prestats_y_grouped{$k} //= []
$prestats_y_grouped{$k}
Truth table0%0/2
A
A= $prestats_y_grouped{$k}
| |||||||||||||||||||||||||||||||||||
| 32 | 0 | push @{ $prestats_y_grouped{$k} }, $prestats_y->at($ridx); | |||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | my @data_y = map { | ||||||||||||||||||||||||||||||||||
| 36 | 0 | my $ridx = $_; | |||||||||||||||||||||||||||||||||
| 37 | 0 | my @key_values = map { $data->at($_)->at($ridx) } @join_on_columns; | |||||||||||||||||||||||||||||||||
| 38 | 0 | my $k = join( $;, @key_values ); | |||||||||||||||||||||||||||||||||
| 39 | 0 | pdl( $prestats_y_grouped{$k} ); | |||||||||||||||||||||||||||||||||
| 40 | } ( 0 .. $data->nrow - 1 ); | ||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | 0 | $data->set( 'y', PDL::SV->new( \@data_y ) ); | |||||||||||||||||||||||||||||||||
| 43 | 0 | return $data; | |||||||||||||||||||||||||||||||||
| 44 | 1 | } | |||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | classmethod to_traces ($df, $params, $plot) { | ||||||||||||||||||||||||||||||||
|
Subroutine
to_traces: not called CC=14 SCAR=53.5
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 47 | 0 | load Chart::Plotly::Trace::Box; | |||||||||||||||||||||||||||||||||
| 48 | 0 | load Chart::Plotly::Trace::Box::Line; | |||||||||||||||||||||||||||||||||
| 49 | 0 | load Chart::Plotly::Trace::Box::Marker; | |||||||||||||||||||||||||||||||||
| 50 | 0 | load Chart::Plotly::Trace::Box::Marker::Line; | |||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | 0 | my $geom_point_default_aes = Chart::GGPlot::Geom::Point->default_aes; | |||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | my $marker_opacity = $params->at('outlier_alpha') | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$params->at("outlier_alpha") // $df->at("alpha")->setbadtoval(1)->at(0)
MC/DC0%0/2
$params->at("outlier_alpha") // $df->at("alpha")->setbadtoval(1)->at(0)
$params->at("outlier_alpha")
$df->at("alpha")->setbadtoval(1)->at(0)
Truth table0%0/3
A // B
A= $params->at("outlier_alpha")B= $df->at("alpha")->setbadtoval(1)->at(0)
| |||||||||||||||||||||||||||||||||||
| 54 | // $df->at('alpha')->setbadtoval(1)->at(0); | ||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | # If neither outlier_color or outlier_fill are defined, they use box color. | ||||||||||||||||||||||||||||||||||
| 57 | 0 | my $params_outlier_color = $params->at('outlier_color'); | |||||||||||||||||||||||||||||||||
| 58 | 0 | my $params_outlier_fill = $params->at('outlier_fill'); | |||||||||||||||||||||||||||||||||
| 59 | 0 | my $marker_color; | |||||||||||||||||||||||||||||||||
| 60 | my $marker_fill; | ||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ( !$params_outlier_color and !$params_outlier_fill ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$params_outlier_color or $params_outlier_fill
MC/DC0%0/2
$params_outlier_color or $params_outlier_fill
$params_outlier_color
$params_outlier_fill
Truth table0%0/3
A or B
A= $params_outlier_colorB= $params_outlier_fill
| |||||||||||||||||||||||||||||||||||
| 62 | 0 | $marker_color = $marker_fill = $df->at('color')->at(0); | |||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $marker_color = to_rgb( $marker_color // $params_outlier_color | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
($marker_color // $params_outlier_color) // $df->at("color")->at(0)
$marker_color // $params_outlier_color
MC/DC0%0/3
($marker_color // $params_outlier_color) // $df->at("color")->at(0)
$marker_color
$params_outlier_color
$df->at("color")->at(0)
Truth table0%0/4
A // B // C
A= $marker_colorB= $params_outlier_colorC= $df->at("color")->at(0)
| |||||||||||||||||||||||||||||||||||
| 65 | // $df->at('color')->at(0) ); | ||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $marker_fill = | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
($marker_fill // $params_outlier_fill) // $df->at("color")->at(0)
$marker_fill // $params_outlier_fill
MC/DC0%0/3
($marker_fill // $params_outlier_fill) // $df->at("color")->at(0)
$marker_fill
$params_outlier_fill
$df->at("color")->at(0)
Truth table0%0/4
A // B // C
A= $marker_fillB= $params_outlier_fillC= $df->at("color")->at(0)
| |||||||||||||||||||||||||||||||||||
| 67 | to_rgb( $marker_fill // $params_outlier_fill // $df->at('color')->at(0) ); | ||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 0 | my $marker_size = do { | |||||||||||||||||||||||||||||||||
| 70 | 0 | my $s = $params->at('outlier_size'); | |||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $s ? max( to_px($s), 2 ) : 2; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 72 | }; | ||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $marker_stroke = to_px( $params->at('outlier_stroke') | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$params->at("outlier_stroke") // $geom_point_default_aes->at("stroke")->at(0)
MC/DC0%0/2
$params->at("outlier_stroke") // $geom_point_default_aes->at("stroke")->at(0)
$params->at("outlier_stroke")
$geom_point_default_aes->at("stroke")->at(0)
Truth table0%0/3
A // B
A= $params->at("outlier_stroke")B= $geom_point_default_aes->at("stroke")->at(0)
| |||||||||||||||||||||||||||||||||||
| 74 | // $geom_point_default_aes->at('stroke')->at(0) ); | ||||||||||||||||||||||||||||||||||
| 75 | 0 | my $marker = Chart::Plotly::Trace::Box::Marker->new( | |||||||||||||||||||||||||||||||||
| 76 | opacity => $marker_opacity, | ||||||||||||||||||||||||||||||||||
| 77 | outliercolor => $marker_fill, | ||||||||||||||||||||||||||||||||||
| 78 | color => $marker_fill, | ||||||||||||||||||||||||||||||||||
| 79 | size => $marker_size, | ||||||||||||||||||||||||||||||||||
| 80 | line => Chart::Plotly::Trace::Box::Marker::Line->new( | ||||||||||||||||||||||||||||||||||
| 81 | width => $marker_stroke, | ||||||||||||||||||||||||||||||||||
| 82 | color => $marker_color, | ||||||||||||||||||||||||||||||||||
| 83 | ), | ||||||||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 0 | my $line = Chart::Plotly::Trace::Box::Line->new( | |||||||||||||||||||||||||||||||||
| 87 | color => to_rgb( $df->at('color') )->at(0), | ||||||||||||||||||||||||||||||||||
| 88 | width => max( to_px( $df->at('size')->at(0) ), 2 ), | ||||||||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||||||||
| 90 | 0 | my $fillcolor = to_rgb( $df->at('fill'), $df->at('alpha') )->at(0); | |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 0 | my $data_y = $df->at('y'); | |||||||||||||||||||||||||||||||||
| 93 | 0 | my $y = [ map { $data_y->at($_)->unpdl; } ( 0 .. $data_y->length - 1 ) ]; | |||||||||||||||||||||||||||||||||
| 94 | 0 | my $data_x = $df->at('x'); | |||||||||||||||||||||||||||||||||
| 95 | my $x = | ||||||||||||||||||||||||||||||||||
| 96 | 0 | [ map { ( $data_x->at($_) ) x @{ $y->[$_] } } | |||||||||||||||||||||||||||||||||
| 97 | ( 0 .. $data_x->length - 1 ) ]; | ||||||||||||||||||||||||||||||||||
| 98 | 0 | $y = [ map { @$_ } @$y ]; # flatten y data | |||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||
| 100 | 0 | my $flip = $plot->coordinates->DOES('Chart::GGPlot::Coord::Flip'); | |||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my $trace = Chart::Plotly::Trace::Box->new( | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 102 | x => $x, | ||||||||||||||||||||||||||||||||||
| 103 | y => $y, | ||||||||||||||||||||||||||||||||||
| 104 | type => 'box', | ||||||||||||||||||||||||||||||||||
| 105 | fillcolor => $fillcolor, | ||||||||||||||||||||||||||||||||||
| 106 | marker => $marker, | ||||||||||||||||||||||||||||||||||
| 107 | line => $line, | ||||||||||||||||||||||||||||||||||
| 108 | notched => ( $params->at('notch') ? JSON::true : JSON::false ), | ||||||||||||||||||||||||||||||||||
| 109 | notchwidth => $params->at('notchwidth'), | ||||||||||||||||||||||||||||||||||
| 110 | hoverinfo => ( $flip ? 'x' : 'y' ), | ||||||||||||||||||||||||||||||||||
| 111 | hoveron => $class->hover_on, | ||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||
| 113 | # plotly defaults to 'suspectedoutliers' to show outliers and | ||||||||||||||||||||||||||||||||||
| 114 | # suspected in different styles. | ||||||||||||||||||||||||||||||||||
| 115 | # we use 'outliers' here to align with ggplot2 behavior. | ||||||||||||||||||||||||||||||||||
| 116 | boxpoints => 'outliers', | ||||||||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||||||||
| 118 | 0 | return [ $class->_adjust_trace_for_flip($trace, $plot) ]; | |||||||||||||||||||||||||||||||||
| 119 | 1 | } | |||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||||||||