| 1 | package Chart::Plotly::Trace::Sankey; | ||
| 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::Sankey::Domain; | ||
| 10 | use Chart::Plotly::Trace::Sankey::Hoverlabel; | ||
| 11 | use Chart::Plotly::Trace::Sankey::Legendgrouptitle; | ||
| 12 | use Chart::Plotly::Trace::Sankey::Link; | ||
| 13 | use Chart::Plotly::Trace::Sankey::Node; | ||
| 14 | use Chart::Plotly::Trace::Sankey::Stream; | ||
| 15 | use Chart::Plotly::Trace::Sankey::Textfont; | ||
| 16 | |||
| 17 | our $VERSION = '0.042'; # VERSION | ||
| 18 | |||
| 19 | # ABSTRACT: Sankey plots for network flow data analysis. The nodes are specified in `nodes` and the links between sources and targets in `links`. The colors are set in `nodes[i].color` and `links[i].color`, otherwise defaults are used. | ||
| 20 | |||
| 21 | sub TO_JSON { | ||
| 22 | my $self = shift; | ||
| 23 | my $extra_args = $self->extra_args // {}; | ||
| 24 | my $meta = $self->meta; | ||
| 25 | my %hash = %$self; | ||
| 26 | for my $name ( sort keys %hash ) { | ||
| 27 | my $attr = $meta->get_attribute($name); | ||
| 28 | if ( defined $attr ) { | ||
| 29 | my $value = $hash{$name}; | ||
| 30 | my $type = $attr->type_constraint; | ||
| 31 | if ( $type && $type->equals('Bool') ) { | ||
| 32 | $hash{$name} = $value ? \1 : \0; | ||
| 33 | } | ||
| 34 | } | ||
| 35 | } | ||
| 36 | my $plotly_meta = delete $hash{'pmeta'}; | ||
| 37 | if ( defined $plotly_meta ) { | ||
| 38 | $hash{'meta'} = $plotly_meta; | ||
| 39 | } | ||
| 40 | %hash = ( %hash, %$extra_args ); | ||
| 41 | delete $hash{'extra_args'}; | ||
| 42 | if ( $self->can('type') && ( !defined $hash{'type'} ) ) { | ||
| 43 | $hash{type} = $self->type(); | ||
| 44 | } | ||
| 45 | return \%hash; | ||
| 46 | } | ||
| 47 | |||
| 48 | sub type { | ||
| 49 | my @components = split( /::/, __PACKAGE__ ); | ||
| 50 | return lc( $components[-1] ); | ||
| 51 | } | ||
| 52 | |||
| 53 | has arrangement => ( | ||
| 54 | is => "rw", | ||
| 55 | isa => enum( [ "snap", "perpendicular", "freeform", "fixed" ] ), | ||
| 56 | documentation => | ||
| 57 | "If value is `snap` (the default), the node arrangement is assisted by automatic snapping of elements to preserve space between nodes specified via `nodepad`. If value is `perpendicular`, the nodes can only move along a line perpendicular to the flow. If value is `freeform`, the nodes can freely move on the plane. If value is `fixed`, the nodes are stationary.", | ||
| 58 | ); | ||
| 59 | |||
| 60 | has customdata => ( | ||
| 61 | is => "rw", | ||
| 62 | isa => "ArrayRef|PDL", | ||
| 63 | documentation => | ||
| 64 | "Assigns extra data each datum. This may be useful when listening to hover, click and selection events. Note that, *scatter* traces also appends customdata items in the markers DOM elements", | ||
| 65 | ); | ||
| 66 | |||
| 67 | has customdatasrc => ( is => "rw", | ||
| 68 | isa => "Str", | ||
| 69 | documentation => "Sets the source reference on Chart Studio Cloud for `customdata`.", | ||
| 70 | ); | ||
| 71 | |||
| 72 | has domain => ( is => "rw", | ||
| 73 | isa => "Maybe[HashRef]|Chart::Plotly::Trace::Sankey::Domain", ); | ||
| 74 | |||
| 75 | has hoverinfo => ( | ||
| 76 | is => "rw", | ||
| 77 | isa => "Str", | ||
| 78 | documentation => | ||
| 79 | "Determines which trace information appear on hover. If `none` or `skip` are set, no information is displayed upon hovering. But, if `none` is set, click and hover events are still fired. Note that this attribute is superseded by `node.hoverinfo` and `node.hoverinfo` for nodes and links respectively.", | ||
| 80 | ); | ||
| 81 | |||
| 82 | has hoverlabel => ( is => "rw", | ||
| 83 | isa => "Maybe[HashRef]|Chart::Plotly::Trace::Sankey::Hoverlabel", ); | ||
| 84 | |||
| 85 | has ids => ( | ||
| 86 | is => "rw", | ||
| 87 | isa => "ArrayRef|PDL", | ||
| 88 | documentation => | ||
| 89 | "Assigns id labels to each datum. These ids for object constancy of data points during animation. Should be an array of strings, not numbers or any other type.", | ||
| 90 | ); | ||
| 91 | |||
| 92 | has idssrc => ( is => "rw", | ||
| 93 | isa => "Str", | ||
| 94 | documentation => "Sets the source reference on Chart Studio Cloud for `ids`.", | ||
| 95 | ); | ||
| 96 | |||
| 97 | has legendgrouptitle => ( is => "rw", | ||
| 98 | isa => "Maybe[HashRef]|Chart::Plotly::Trace::Sankey::Legendgrouptitle", ); | ||
| 99 | |||
| 100 | has legendrank => ( | ||
| 101 | is => "rw", | ||
| 102 | isa => "Num", | ||
| 103 | documentation => | ||
| 104 | "Sets the legend rank for this trace. Items and groups with smaller ranks are presented on top/left side while with `*reversed* `legend.traceorder` they are on bottom/right side. The default legendrank is 1000, so that you can use ranks less than 1000 to place certain items before all unranked items, and ranks greater than 1000 to go after all unranked items.", | ||
| 105 | ); | ||
| 106 | |||
| 107 | has link => ( is => "rw", | ||
| 108 | isa => "Maybe[HashRef]|Chart::Plotly::Trace::Sankey::Link", ); | ||
| 109 | |||
| 110 | has pmeta => ( | ||
| 111 | is => "rw", | ||
| 112 | isa => "Any|ArrayRef[Any]", | ||
| 113 | documentation => | ||
| 114 | "Assigns extra meta information associated with this trace that can be used in various text attributes. Attributes such as trace `name`, graph, axis and colorbar `title.text`, annotation `text` `rangeselector`, `updatemenues` and `sliders` `label` text all support `meta`. To access the trace `meta` values in an attribute in the same trace, simply use `%{meta[i]}` where `i` is the index or key of the `meta` item in question. To access trace `meta` in layout attributes, use `%{data[n[.meta[i]}` where `i` is the index or key of the `meta` and `n` is the trace index.", | ||
| 115 | ); | ||
| 116 | |||
| 117 | has metasrc => ( is => "rw", | ||
| 118 | isa => "Str", | ||
| 119 | documentation => "Sets the source reference on Chart Studio Cloud for `meta`.", | ||
| 120 | ); | ||
| 121 | |||
| 122 | has name => ( is => "rw", | ||
| 123 | isa => "Str", | ||
| 124 | documentation => "Sets the trace name. The trace name appear as the legend item and on hover.", | ||
| 125 | ); | ||
| 126 | |||
| 127 | has node => ( is => "rw", | ||
| 128 | isa => "Maybe[HashRef]|Chart::Plotly::Trace::Sankey::Node", ); | ||
| 129 | |||
| 130 | has orientation => ( is => "rw", | ||
| 131 | isa => enum( [ "v", "h" ] ), | ||
| 132 | documentation => "Sets the orientation of the Sankey diagram.", | ||
| 133 | ); | ||
| 134 | |||
| 135 | has selectedpoints => ( | ||
| 136 | is => "rw", | ||
| 137 | isa => "Any", | ||
| 138 | documentation => | ||
| 139 | "Array containing integer indices of selected points. Has an effect only for traces that support selections. Note that an empty array means an empty selection where the `unselected` are turned on for all points, whereas, any other non-array values means no selection all where the `selected` and `unselected` styles have no effect.", | ||
| 140 | ); | ||
| 141 | |||
| 142 | has stream => ( is => "rw", | ||
| 143 | isa => "Maybe[HashRef]|Chart::Plotly::Trace::Sankey::Stream", ); | ||
| 144 | |||
| 145 | has textfont => ( is => "rw", | ||
| 146 | isa => "Maybe[HashRef]|Chart::Plotly::Trace::Sankey::Textfont", ); | ||
| 147 | |||
| 148 | has uid => ( | ||
| 149 | is => "rw", | ||
| 150 | isa => "Str", | ||
| 151 | documentation => | ||
| 152 | "Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.", | ||
| 153 | ); | ||
| 154 | |||
| 155 | has uirevision => ( | ||
| 156 | is => "rw", | ||
| 157 | isa => "Any", | ||
| 158 | documentation => | ||
| 159 | "Controls persistence of some user-driven changes to the trace: `constraintrange` in `parcoords` traces, as well as some `editable: true` modifications such as `name` and `colorbar.title`. Defaults to `layout.uirevision`. Note that other user-driven trace attribute changes are controlled by `layout` attributes: `trace.visible` is controlled by `layout.legend.uirevision`, `selectedpoints` is controlled by `layout.selectionrevision`, and `colorbar.(x|y)` (accessible with `config: {editable: true}`) is controlled by `layout.editrevision`. Trace changes are tracked by `uid`, which only falls back on trace index if no `uid` is provided. So if your app can add/remove traces before the end of the `data` array, such that the same trace has a different index, you can still preserve user-driven changes if you give each trace a `uid` that stays with it as it moves.", | ||
| 160 | ); | ||
| 161 | |||
| 162 | has valueformat => ( | ||
| 163 | is => "rw", | ||
| 164 | isa => "Str", | ||
| 165 | documentation => | ||
| 166 | "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.", | ||
| 167 | ); | ||
| 168 | |||
| 169 | has valuesuffix => ( | ||
| 170 | is => "rw", | ||
| 171 | isa => "Str", | ||
| 172 | documentation => | ||
| 173 | "Adds a unit to follow the value in the hover tooltip. Add a space if a separation is necessary from the value.", | ||
| 174 | ); | ||
| 175 | |||
| 176 | has visible => ( | ||
| 177 | is => "rw", | ||
| 178 | documentation => | ||
| 179 | "Determines whether or not this trace is visible. If *legendonly*, the trace is not drawn, but can appear as a legend item (provided that the legend itself is visible).", | ||
| 180 | ); | ||
| 181 | |||
| 182 | __PACKAGE__->meta->make_immutable(); | ||
| 183 | 1; | ||
| 184 | |||
| 185 | __END__ |