| 1 | package CXC::Gnuplot::V1::AxisTics; | ||
| 2 | |||
| 3 | 1 | ▶ | use v5.38; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use experimental 'builtin', 'declared_refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Object::Pad 0.821; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 6 | |||
| 7 | our $VERSION = 'v0.29.3'; | ||
| 8 | |||
| 9 | class CXC::Gnuplot::V1::AxisTics : isa(CXC::Gnuplot::V1::Base) | ||
| 10 | does( CXC::Gnuplot::V1::Role::Clone ); | ||
| 11 | |||
| 12 | use builtin 'is_bool', 'true', 'false'; | ||
| 13 | |||
| 14 | no namespace::clean; | ||
| 15 | |||
| 16 | use Ref::Util 'is_plain_hashref', 'is_plain_arrayref', 'is_ref'; | ||
| 17 | use List::Util 'none'; | ||
| 18 | |||
| 19 | use namespace::clean; | ||
| 20 | |||
| 21 | use CXC::Gnuplot::V1::Types -lexical, qw( | ||
| 22 | Enum | ||
| 23 | is_Num | ||
| 24 | is_NonEmptyStr | ||
| 25 | PerlBoolFalse | ||
| 26 | TicList | ||
| 27 | TicSeries | ||
| 28 | CoordOffset3D | ||
| 29 | ); | ||
| 30 | use CXC::Gnuplot::V1::Util -lexical, 'maybe_quote', 'pvalidate', 'to_hash_r', 'render_opts'; | ||
| 31 | use CXC::Gnuplot::V1::AxisFormat; | ||
| 32 | |||
| 33 | |||
| 34 | my sub croak { | ||
| 35 | require Carp; | ||
| 36 | goto \&Carp::croak; | ||
| 37 | } | ||
| 38 | |||
| 39 | #<<< no tidy | ||
| 40 | field $where :param :reader = undef; # {axis | border} | ||
| 41 | field $mirror :param :reader = undef; # {{no}mirror} | ||
| 42 | field $direction :param :reader = undef; # {in |out} | ||
| 43 | field $scale :param :reader = undef; # {scale {default | <major> {,<minor>}}} | ||
| 44 | field $rotate :param :reader = undef; # {{no}rotate {by <ang>}} | ||
| 45 | field $offset :param :reader = undef; # {offset <offset> | nooffset} | ||
| 46 | field $justify :param :reader = undef; # {left | right | center | autojustify} | ||
| 47 | field $positions :param :reader = undef; # { autofreq | ||
| 48 | # | <incr> | ||
| 49 | # | <start>, <incr> {,<end>} | ||
| 50 | # | ({"<label>"} <pos> {<level>} {,{"<label>"}...) } | ||
| 51 | field $format :param :reader = undef; | ||
| 52 | field $font :param :reader = undef; # {"name{,<size>}"} | ||
| 53 | field $enhanced :param :reader = undef; # {{no}enhanced} | ||
| 54 | field $logscale :param :reader = undef; #{{no}logscale} | ||
| 55 | field $rangelimited :param :reader = undef; # {rangelimited} | ||
| 56 | field $textcolor :param :reader = undef; # {colorspec} | ||
| 57 | #>>> | ||
| 58 | |||
| 59 | |||
| 60 | |||
| 61 | |||
| 62 | |||
| 63 | |||
| 64 | |||
| 65 | |||
| 66 | |||
| 67 | |||
| 68 | |||
| 69 | |||
| 70 | |||
| 71 | |||
| 72 | |||
| 73 | |||
| 74 | |||
| 75 | |||
| 76 | |||
| 77 | |||
| 78 | |||
| 79 | |||
| 80 | |||
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | |||
| 85 | |||
| 86 | |||
| 87 | |||
| 88 | |||
| 89 | |||
| 90 | |||
| 91 | |||
| 92 | |||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | ADJUST { | ||
| 97 | |||
| 98 | pvalidate( where => Enum->of( 'axis', 'border' ), \$where ); | ||
| 99 | |||
| 100 | defined $mirror | ||
| 101 | and !is_bool( $mirror ) | ||
| 102 | and croak( q{invalid value for "mirror" parameter: must be bool} ); | ||
| 103 | |||
| 104 | pvalidate( direction => Enum->of( 'axis', 'border' ), \$direction ); | ||
| 105 | |||
| 106 | # for now, just store this as a string | ||
| 107 | defined $scale | ||
| 108 | and !is_NonEmptyStr( $scale ) | ||
| 109 | and croak( q{"scale" must be non-empty} ); | ||
| 110 | |||
| 111 | defined $rotate | ||
| 112 | and !is_bool( $rotate ) | ||
| 113 | and !is_Num( $rotate ) | ||
| 114 | and croak( '"rotate" must be a float or a boolean' ); | ||
| 115 | |||
| 116 | # offset is either a false boolean or an expression | ||
| 117 | pvalidate( offset => PerlBoolFalse | CoordOffset3D, \$offset ); | ||
| 118 | |||
| 119 | pvalidate( justify => Enum->of( 'left', 'right', 'center', 'autojustify' ), \$justify ); | ||
| 120 | |||
| 121 | pvalidate( positions => Enum->of( 'autofreq' ) | TicSeries | TicList, \$positions ); | ||
| 122 | |||
| 123 | pvalidate( format => AxisFormat => \$format ); | ||
| 124 | pvalidate( font => Font => \$font ); | ||
| 125 | |||
| 126 | defined $enhanced | ||
| 127 | and !is_bool( $enhanced ) | ||
| 128 | and croak( q{invalid value for "enhanced" parameter: must be bool} ); | ||
| 129 | |||
| 130 | defined $logscale | ||
| 131 | and !is_bool( $enhanced ) | ||
| 132 | and croak( q{invalid value for "logscale" parameter: must be bool} ); | ||
| 133 | |||
| 134 | defined $rangelimited | ||
| 135 | and !is_bool( $rangelimited ) | ||
| 136 | and croak( q{invalid value for "rangelimited" parameter: must be bool} ); | ||
| 137 | |||
| 138 | pvalidate( textcolor => ColorSpec => \$textcolor ); | ||
| 139 | } | ||
| 140 | |||
| 141 | |||
| 142 | |||
| 143 | |||
| 144 | |||
| 145 | |||
| 146 | |||
| 147 | |||
| 148 | |||
| 149 | |||
| 150 | |||
| 151 | |||
| 152 | |||
| 153 | |||
| 154 | |||
| 155 | |||
| 156 | |||
| 157 | |||
| 158 | |||
| 159 | |||
| 160 | method to_hash { | ||
| 161 | |||
| 162 | to_hash_r( { | ||
| 163 | ( defined $where ? ( where => $where ) : () ), | ||
| 164 | ( defined $mirror ? ( mirror => $mirror ) : () ), | ||
| 165 | ( defined $direction ? ( direction => $direction ) : () ), | ||
| 166 | ( defined $scale ? ( scale => $scale ) : () ), | ||
| 167 | ( defined $rotate ? ( rotate => $rotate ) : () ), | ||
| 168 | ( defined $offset ? ( offset => $offset ) : () ), | ||
| 169 | ( defined $justify ? ( justify => $justify ) : () ), | ||
| 170 | ( defined $positions ? ( positions => $positions ) : () ), | ||
| 171 | ( defined $enhanced ? ( enhanced => $enhanced ) : () ), | ||
| 172 | ( defined $logscale ? ( logscale => $logscale ) : () ), | ||
| 173 | ( defined $rangelimited ? ( rangelimited => $rangelimited ) : () ), | ||
| 174 | ( defined $textcolor ? ( textcolor => $textcolor ) : () ), | ||
| 175 | ( defined $format ? ( format => $format ) : () ), | ||
| 176 | ( defined $font ? ( font => $font ) : () ), | ||
| 177 | } ); | ||
| 178 | } | ||
| 179 | |||
| 180 | my sub opts_tic_series( $series ) { | ||
| 181 | |||
| 182 | my \%series = $series; | ||
| 183 | my @position; | ||
| 184 | |||
| 185 | push @position, $series{start} | ||
| 186 | if defined $series{start}; | ||
| 187 | |||
| 188 | if ( defined( my $incr = $series{incr} ) ) { | ||
| 189 | push @position, | ||
| 190 | is_plain_hashref( $incr ) | ||
| 191 | ? join( q{ }, grep defined, $incr->@{ 'multiple', 'unit' } ) | ||
| 192 | : $incr; | ||
| 193 | } | ||
| 194 | |||
| 195 | push @position, $series{end} | ||
| 196 | if defined $series{end}; | ||
| 197 | |||
| 198 | return join( ', ', @position ); | ||
| 199 | } | ||
| 200 | |||
| 201 | my sub opts_tic_entry ( $entry ) { | ||
| 202 | |||
| 203 | my \%entry = $entry; | ||
| 204 | |||
| 205 | my @pos; | ||
| 206 | |||
| 207 | defined $entry{label} | ||
| 208 | and push @pos, maybe_quote( $entry{label} ); | ||
| 209 | |||
| 210 | push @pos, $entry{pos}; | ||
| 211 | |||
| 212 | defined $entry{level} | ||
| 213 | and push @pos, $entry{level}; | ||
| 214 | |||
| 215 | return join q{ }, @pos; | ||
| 216 | } | ||
| 217 | |||
| 218 | my sub opts_positions ( $positions ) { | ||
| 219 | |||
| 220 | return () if !defined $positions; | ||
| 221 | |||
| 222 | # start, incr, end | ||
| 223 | return opts_tic_series( $positions ) | ||
| 224 | if is_plain_hashref( $positions ); | ||
| 225 | |||
| 226 | # autofreq | ||
| 227 | return $positions if !is_plain_arrayref( $positions ); | ||
| 228 | |||
| 229 | my \@positions = $positions; | ||
| 230 | |||
| 231 | # add | ||
| 232 | my @add = is_ref( $positions[0] ) ? () : shift @positions; | ||
| 233 | my $tics = join q{, }, map { opts_tic_entry( $_ ) } @positions; | ||
| 234 | return join q{ }, @add, "( $tics )"; | ||
| 235 | } | ||
| 236 | |||
| 237 | |||
| 238 | |||
| 239 | |||
| 240 | |||
| 241 | method opts { | ||
| 242 | my @opts; | ||
| 243 | |||
| 244 | defined $where | ||
| 245 | and push @opts, $where; | ||
| 246 | |||
| 247 | defined $mirror | ||
| 248 | and push @opts, $mirror ? 'mirror' : 'nomirror'; | ||
| 249 | |||
| 250 | defined $direction | ||
| 251 | and push @opts, $direction; | ||
| 252 | |||
| 253 | defined $scale | ||
| 254 | and push @opts, [ scale => $scale ]; | ||
| 255 | |||
| 256 | defined $rotate | ||
| 257 | and push @opts, is_bool( $rotate ) | ||
| 258 | ? ( $rotate ? 'rotate' : 'norotate' ) | ||
| 259 | : [ 'rotate by' => $rotate ]; | ||
| 260 | |||
| 261 | if ( defined $offset ) { | ||
| 262 | if ( is_bool( $offset ) ) { | ||
| 263 | push @opts, ( $offset ? 'offset' : 'nooffset' ); | ||
| 264 | } | ||
| 265 | else { | ||
| 266 | push @opts, render_opts( offset => $offset ); | ||
| 267 | } | ||
| 268 | |||
| 269 | } | ||
| 270 | |||
| 271 | defined $justify | ||
| 272 | and push @opts, $justify; | ||
| 273 | |||
| 274 | defined $positions | ||
| 275 | and push @opts, opts_positions( $positions ); | ||
| 276 | |||
| 277 | push @opts, render_opts( format => $format ); | ||
| 278 | |||
| 279 | push @opts, render_opts( font => $font ); | ||
| 280 | |||
| 281 | defined $enhanced | ||
| 282 | and push @opts, ( $enhanced ? 'enhanced' : 'noenhanced' ); | ||
| 283 | |||
| 284 | defined $logscale | ||
| 285 | and push @opts, ( $logscale ? 'logscale' : 'nologscale' ); | ||
| 286 | |||
| 287 | defined $rangelimited | ||
| 288 | and push @opts, ( $rangelimited ? 'rangelimited' : () ); | ||
| 289 | |||
| 290 | push @opts, render_opts( textcolor => $textcolor ); | ||
| 291 | |||
| 292 | return @opts; | ||
| 293 | } | ||
| 294 | |||
| 295 | # | ||
| 296 | # This file is part of CXC-Gnuplot | ||
| 297 | # | ||
| 298 | # This software is Copyright (c) 2024 by Smithsonian Astrophysical Observatory. | ||
| 299 | # | ||
| 300 | # This is free software, licensed under: | ||
| 301 | # | ||
| 302 | # The GNU General Public License, Version 3, June 2007 | ||
| 303 | # | ||
| 304 | |||
| 305 | 1; | ||
| 306 | |||
| 307 | __END__ | ||