| 1 | package Chart::Plotly::Trace::Indicator::Delta; | ||
| 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 | use Chart::Plotly::Trace::Indicator::Delta::Decreasing; | ||
| 10 | use Chart::Plotly::Trace::Indicator::Delta::Font; | ||
| 11 | use Chart::Plotly::Trace::Indicator::Delta::Increasing; | ||
| 12 | |||
| 13 | our $VERSION = '0.042'; # VERSION | ||
| 14 | |||
| 15 | # ABSTRACT: This attribute is one of the possible options for the trace indicator. | ||
| 16 | |||
| 17 | sub TO_JSON { | ||
| 18 | my $self = shift; | ||
| 19 | my $extra_args = $self->extra_args // {}; | ||
| 20 | my $meta = $self->meta; | ||
| 21 | my %hash = %$self; | ||
| 22 | for my $name ( sort keys %hash ) { | ||
| 23 | my $attr = $meta->get_attribute($name); | ||
| 24 | if ( defined $attr ) { | ||
| 25 | my $value = $hash{$name}; | ||
| 26 | my $type = $attr->type_constraint; | ||
| 27 | if ( $type && $type->equals('Bool') ) { | ||
| 28 | $hash{$name} = $value ? \1 : \0; | ||
| 29 | } | ||
| 30 | } | ||
| 31 | } | ||
| 32 | %hash = ( %hash, %$extra_args ); | ||
| 33 | delete $hash{'extra_args'}; | ||
| 34 | if ( $self->can('type') && ( !defined $hash{'type'} ) ) { | ||
| 35 | $hash{type} = $self->type(); | ||
| 36 | } | ||
| 37 | return \%hash; | ||
| 38 | } | ||
| 39 | |||
| 40 | has decreasing => ( is => "rw", | ||
| 41 | isa => "Maybe[HashRef]|Chart::Plotly::Trace::Indicator::Delta::Decreasing", ); | ||
| 42 | |||
| 43 | has font => ( is => "rw", | ||
| 44 | isa => "Maybe[HashRef]|Chart::Plotly::Trace::Indicator::Delta::Font", ); | ||
| 45 | |||
| 46 | has increasing => ( is => "rw", | ||
| 47 | isa => "Maybe[HashRef]|Chart::Plotly::Trace::Indicator::Delta::Increasing", ); | ||
| 48 | |||
| 49 | has position => ( is => "rw", | ||
| 50 | isa => enum( [ "top", "bottom", "left", "right" ] ), | ||
| 51 | documentation => "Sets the position of delta with respect to the number.", | ||
| 52 | ); | ||
| 53 | |||
| 54 | has prefix => ( is => "rw", | ||
| 55 | isa => "Str", | ||
| 56 | documentation => "Sets a prefix appearing before the delta.", | ||
| 57 | ); | ||
| 58 | |||
| 59 | has reference => ( | ||
| 60 | is => "rw", | ||
| 61 | isa => "Num", | ||
| 62 | documentation => "Sets the reference value to compute the delta. By default, it is set to the current value.", | ||
| 63 | ); | ||
| 64 | |||
| 65 | has relative => ( is => "rw", | ||
| 66 | isa => "Bool", | ||
| 67 | documentation => "Show relative change", | ||
| 68 | ); | ||
| 69 | |||
| 70 | has suffix => ( is => "rw", | ||
| 71 | isa => "Str", | ||
| 72 | documentation => "Sets a suffix appearing next to the delta.", | ||
| 73 | ); | ||
| 74 | |||
| 75 | has valueformat => ( | ||
| 76 | is => "rw", | ||
| 77 | isa => "Str", | ||
| 78 | documentation => | ||
| 79 | "Sets the value formatting rule using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format.", | ||
| 80 | ); | ||
| 81 | |||
| 82 | __PACKAGE__->meta->make_immutable(); | ||
| 83 | 1; | ||
| 84 | |||
| 85 | __END__ |