@@ -270,6 +270,21 @@ =head3 Options
270270
271271If multiple box plots are defined, this should only be a single value.
272272
273+ =item whisker_cap
274+
275+ Value of 0 (default) or 1. If 1, his will add a short line perpendicular to the whiskers
276+ on the boxplot with relative size C<cap_width >
277+
278+ =item cap_width
279+
280+ The width of the cap as a fraction of the box height (if C<< orientation => 'vertical' >>)
281+ or box width (if C<< orientation => 'horizontal' >>). Default value is 0.2.
282+
283+ =item outlier_mark
284+
285+ The shape of the mark to use for outliers. Default is 'plus'. See L<Options for add_dataset|plots.pl/DATASET OPTIONS>
286+ for other mark options.
287+
273288=back
274289
275290As with other methods in the macro, other options can be passed along to C<add_rectangle >
@@ -411,7 +426,10 @@ sub add_boxplot {
411426 my ($self , $data , %opts ) = @_ ;
412427
413428 my %options = (
414- orientation => ' horizontal' ,
429+ orientation => ' horizontal' ,
430+ whisker_cap => 0,
431+ cap_width => 0.2,
432+ outlier_mark => ' plus' ,
415433 %opts
416434 );
417435
@@ -463,12 +481,10 @@ sub _add_boxplot {
463481 $count {$_ }++ for (' min' , ' q1' , ' median' , ' q3' , ' max' );
464482 $count {$_ }-- for (keys %$data );
465483 for (keys %count ) {
466- # warn "$_: $count{$_}";
467484 Value::Error(" The parameter $_ is missing from the boxplot attributes." ) if $count {$_ } > 0;
468485 }
469486 $params = $data ;
470487 }
471- # warn "$_: $options{$_}" for (keys %options);s
472488
473489 # if fill_color is passed as an option, set the 'fill' to 'self'.
474490 $options {fill } = ' self' if $options {fill_color };
@@ -484,9 +500,17 @@ sub _add_boxplot {
484500 $self -> add_dataset([ $params -> {median }, $box_center - 0.5 * $box_width ],
485501 [ $params -> {median }, $box_center + 0.5 * $box_width ], %options );
486502
503+ # add whisker caps
504+ if ($options {whisker_cap }) {
505+ $self -> add_dataset([ $params -> {max }, $box_center - 0.5 * $options {cap_width } * $box_width ],
506+ [ $params -> {max }, $box_center + 0.5 * $options {cap_width } * $box_width ], %options );
507+ $self -> add_dataset([ $params -> {min }, $box_center - 0.5 * $options {cap_width } * $box_width ],
508+ [ $params -> {min }, $box_center + 0.5 * $options {cap_width } * $box_width ], %options );
509+ }
510+
487511 if ($params -> {outliers }) {
488512 my @points = map { [ $_ , $box_center ] } @{ $params -> {outliers } };
489- $self -> add_dataset(@points , linestyle => ' none' , marks => ' plus ' , marksize => 3);
513+ $self -> add_dataset(@points , linestyle => ' none' , marks => $options { outlier_mark } , marksize => 3);
490514 }
491515 } elsif ($orientation eq ' vertical' ) {
492516
@@ -499,6 +523,19 @@ sub _add_boxplot {
499523 $self -> add_dataset([ $box_center , $params -> {q3 } ], [ $box_center , $params -> {max }, ], %options );
500524 $self -> add_dataset([ $box_center - 0.5 * $box_width , $params -> {median } ],
501525 [ $box_center + 0.5 * $box_width , $params -> {median } ], %options );
526+
527+ if ($params -> {outliers }) {
528+ my @points = map { [ $box_center , $_ ] } @{ $params -> {outliers } };
529+ $self -> add_dataset(@points , linestyle => ' none' , marks => $options {outlier_mark }, marksize => 3);
530+ }
531+
532+ # add whisker caps
533+ if ($options {whisker_cap }) {
534+ $self -> add_dataset([ $box_center - 0.5 * $options {cap_width } * $box_width , $params -> {max } ],
535+ [ $box_center + 0.5 * $options {cap_width } * $box_width , $params -> {max }, ], %options );
536+ $self -> add_dataset([ $box_center - 0.5 * $options {cap_width } * $box_width , $params -> {min } ],
537+ [ $box_center + 0.5 * $options {cap_width } * $box_width , $params -> {min } ], %options );
538+ }
502539 }
503540}
504541
0 commit comments