| 1 | package Chart::Plotly::Trace::Treemap::Tiling; | ||
| 2 | use Moose; | ||
| 3 | use MooseX::ExtraArgs; | ||
| 4 | use Moose::Util::TypeConstraints qw(enum union); | ||
| 5 | if ( !defined Moose::Util::TypeConstraints::find_type_constraint('PDL') ) { | ||
| 6 | Moose::Util::TypeConstraints::type('PDL'); | ||
| 7 | } | ||
| 8 | |||
| 9 | our $VERSION = '0.042'; # VERSION | ||
| 10 | |||
| 11 | # ABSTRACT: This attribute is one of the possible options for the trace treemap. | ||
| 12 | |||
| 13 | sub TO_JSON { | ||
| 14 | my $self = shift; | ||
| 15 | my $extra_args = $self->extra_args // {}; | ||
| 16 | my $meta = $self->meta; | ||
| 17 | my %hash = %$self; | ||
| 18 | for my $name ( sort keys %hash ) { | ||
| 19 | my $attr = $meta->get_attribute($name); | ||
| 20 | if ( defined $attr ) { | ||
| 21 | my $value = $hash{$name}; | ||
| 22 | my $type = $attr->type_constraint; | ||
| 23 | if ( $type && $type->equals('Bool') ) { | ||
| 24 | $hash{$name} = $value ? \1 : \0; | ||
| 25 | } | ||
| 26 | } | ||
| 27 | } | ||
| 28 | %hash = ( %hash, %$extra_args ); | ||
| 29 | delete $hash{'extra_args'}; | ||
| 30 | if ( $self->can('type') && ( !defined $hash{'type'} ) ) { | ||
| 31 | $hash{type} = $self->type(); | ||
| 32 | } | ||
| 33 | return \%hash; | ||
| 34 | } | ||
| 35 | |||
| 36 | has flip => ( is => "rw", | ||
| 37 | isa => "Str", | ||
| 38 | documentation => "Determines if the positions obtained from solver are flipped on each axis.", | ||
| 39 | ); | ||
| 40 | |||
| 41 | has packing => ( | ||
| 42 | is => "rw", | ||
| 43 | isa => enum( [ "squarify", "binary", "dice", "slice", "slice-dice", "dice-slice" ] ), | ||
| 44 | documentation => | ||
| 45 | "Determines d3 treemap solver. For more info please refer to https://github.com/d3/d3-hierarchy#treemap-tiling", | ||
| 46 | ); | ||
| 47 | |||
| 48 | has pad => ( is => "rw", | ||
| 49 | isa => "Num", | ||
| 50 | documentation => "Sets the inner padding (in px).", | ||
| 51 | ); | ||
| 52 | |||
| 53 | has squarifyratio => ( | ||
| 54 | is => "rw", | ||
| 55 | isa => "Num", | ||
| 56 | documentation => | ||
| 57 | "When using *squarify* `packing` algorithm, according to https://github.com/d3/d3-hierarchy/blob/v3.1.1/README.md#squarify_ratio this option specifies the desired aspect ratio of the generated rectangles. The ratio must be specified as a number greater than or equal to one. Note that the orientation of the generated rectangles (tall or wide) is not implied by the ratio; for example, a ratio of two will attempt to produce a mixture of rectangles whose width:height ratio is either 2:1 or 1:2. When using *squarify*, unlike d3 which uses the Golden Ratio i.e. 1.618034, Plotly applies 1 to increase squares in treemap layouts.", | ||
| 58 | ); | ||
| 59 | |||
| 60 | __PACKAGE__->meta->make_immutable(); | ||
| 61 | 1; | ||
| 62 | |||
| 63 | __END__ |