| 1 | package CXC::Gnuplot::V1::Label; | ||
| 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::Label : isa(CXC::Gnuplot::V1::Base) does( CXC::Gnuplot::V1::Role::Clone ); | ||
| 10 | |||
| 11 | no namespace::clean; | ||
| 12 | |||
| 13 | use Ref::Util 'is_ref', 'is_plain_arrayref'; | ||
| 14 | use builtin 'is_bool', 'true'; | ||
| 15 | |||
| 16 | use namespace::clean; | ||
| 17 | |||
| 18 | use CXC::Gnuplot::V1::Types -lexical, qw( | ||
| 19 | is_NonEmptyStr | ||
| 20 | is_Num | ||
| 21 | |||
| 22 | ArrayRef | ||
| 23 | CoordPosition3D | ||
| 24 | Dict | ||
| 25 | Enum | ||
| 26 | NonEmptyStr | ||
| 27 | Num | ||
| 28 | Optional | ||
| 29 | PerlBool | ||
| 30 | PerlBoolFalse | ||
| 31 | PositiveInt | ||
| 32 | PositiveNum | ||
| 33 | SetFormats | ||
| 34 | |||
| 35 | signature_for | ||
| 36 | ); | ||
| 37 | |||
| 38 | use CXC::Gnuplot::V1::Util -lexical, 'maybe_quote', | ||
| 39 | |||
| 40 | 'pvalidate', 'to_hash_r', 'render_opts', 'render_set'; | ||
| 41 | |||
| 42 | my sub croak { | ||
| 43 | require Carp; | ||
| 44 | goto \&Carp::croak; | ||
| 45 | } | ||
| 46 | |||
| 47 | # set label {<tag>} {"<label text>"} {at <position>} | ||
| 48 | # {left | center | right} | ||
| 49 | # {norotate | rotate {by <degrees>}} | ||
| 50 | # {font "<name>{,<size>}"} | ||
| 51 | # {noenhanced} | ||
| 52 | # {front | back} | ||
| 53 | # {textcolor <colorspec>} | ||
| 54 | # {point <pointstyle> | nopoint} | ||
| 55 | # {offset <offset>} | ||
| 56 | # {nobox} {boxed {bs <boxstyle>}} | ||
| 57 | # {hypertext} | ||
| 58 | |||
| 59 | |||
| 60 | #<<< notidy | ||
| 61 | field $tag :param :reader = undef; | ||
| 62 | field $text :param :reader = undef; | ||
| 63 | field $at :param :reader = undef; | ||
| 64 | field $justify :param :reader = undef; | ||
| 65 | field $rotate :param :reader = undef; | ||
| 66 | field $font :param :reader = undef; | ||
| 67 | field $enhanced :param :reader = undef; | ||
| 68 | field $layer :param :reader = undef; | ||
| 69 | field $textcolor :param :reader = undef; | ||
| 70 | field $point :param :reader = undef; | ||
| 71 | field $offset :param :reader = undef; | ||
| 72 | field $boxed :param :reader = undef; | ||
| 73 | field $hypertext :param :reader = undef; | ||
| 74 | #>>> | ||
| 75 | |||
| 76 | |||
| 77 | |||
| 78 | |||
| 79 | |||
| 80 | |||
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | |||
| 85 | |||
| 86 | |||
| 87 | |||
| 88 | |||
| 89 | |||
| 90 | |||
| 91 | |||
| 92 | |||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | |||
| 97 | |||
| 98 | |||
| 99 | |||
| 100 | |||
| 101 | |||
| 102 | |||
| 103 | |||
| 104 | |||
| 105 | |||
| 106 | |||
| 107 | |||
| 108 | |||
| 109 | |||
| 110 | ADJUST { | ||
| 111 | |||
| 112 | pvalidate( tag => PositiveInt, \$tag ); | ||
| 113 | |||
| 114 | pvalidate( text => NonEmptyStr, \$text ); | ||
| 115 | |||
| 116 | pvalidate( at => CoordPosition3D, \$at ); | ||
| 117 | |||
| 118 | pvalidate( justify => Enum->of( 'left', 'right', 'center' ), \$justify ); | ||
| 119 | |||
| 120 | pvalidate( rotate => Num | PerlBool, \$rotate ); | ||
| 121 | |||
| 122 | pvalidate( font => Font => \$font ); | ||
| 123 | |||
| 124 | pvalidate( enhanced => PerlBool, \$enhanced ); | ||
| 125 | |||
| 126 | pvalidate( layer => Enum->of( 'front', 'back' ), \$layer ); | ||
| 127 | |||
| 128 | pvalidate( textcolor => ColorSpec => \$textcolor ); | ||
| 129 | |||
| 130 | pvalidate( | ||
| 131 | point => PerlBoolFalse | Dict [ | ||
| 132 | line => Optional [PositiveInt], | ||
| 133 | type => PositiveInt | NonEmptyStr, | ||
| 134 | size => Optional [PositiveNum], | ||
| 135 | color => Optional [NonEmptyStr], # TODO: convert this to a ColorSpec object | ||
| 136 | ], | ||
| 137 | \$point, | ||
| 138 | ); | ||
| 139 | |||
| 140 | pvalidate( offset => CoordOffset3D => \$offset ); | ||
| 141 | |||
| 142 | pvalidate( boxed => PerlBool | PositiveNum, \$boxed ); | ||
| 143 | |||
| 144 | pvalidate( hypertext => PerlBool, \$hypertext ); | ||
| 145 | } | ||
| 146 | |||
| 147 | |||
| 148 | |||
| 149 | |||
| 150 | |||
| 151 | |||
| 152 | |||
| 153 | |||
| 154 | |||
| 155 | |||
| 156 | |||
| 157 | |||
| 158 | |||
| 159 | |||
| 160 | |||
| 161 | method BUILDARGS : common ( @args ) { | ||
| 162 | return ( text => $args[0] ) if @args == 1 && !is_ref( $args[0] ); | ||
| 163 | return $class->SUPER::BUILDARGS( @args ); | ||
| 164 | } | ||
| 165 | |||
| 166 | |||
| 167 | |||
| 168 | |||
| 169 | |||
| 170 | |||
| 171 | |||
| 172 | |||
| 173 | method to_hash { | ||
| 174 | |||
| 175 | to_hash_r( { | ||
| 176 | ( defined $tag ? ( tag => $tag ) : () ), | ||
| 177 | ( defined $text ? ( text => $text ) : () ), | ||
| 178 | ( defined $at ? ( at => $at ) : () ), | ||
| 179 | ( defined $justify ? ( justify => $justify ) : () ), | ||
| 180 | ( defined $rotate ? ( rotate => $rotate ) : () ), | ||
| 181 | ( defined $font ? ( font => $font ) : () ), | ||
| 182 | ( defined $enhanced ? ( enhanced => $enhanced ) : () ), | ||
| 183 | ( defined $layer ? ( layer => $layer ) : () ), | ||
| 184 | ( defined $textcolor ? ( textcolor => $textcolor ) : () ), | ||
| 185 | ( defined $point ? ( point => $point ) : () ), | ||
| 186 | ( defined $offset ? ( offset => $offset ) : () ), | ||
| 187 | ( defined $boxed ? ( boxed => $boxed ) : () ), | ||
| 188 | ( defined $hypertext ? ( hypertext => $hypertext ) : () ), | ||
| 189 | } ); | ||
| 190 | |||
| 191 | } | ||
| 192 | |||
| 193 | |||
| 194 | |||
| 195 | |||
| 196 | |||
| 197 | my %PointMap = ( | ||
| 198 | line => 'lt', | ||
| 199 | type => 'pt', | ||
| 200 | size => 'ps', | ||
| 201 | color => 'lc', | ||
| 202 | ); | ||
| 203 | |||
| 204 | |||
| 205 | method opts { | ||
| 206 | my @opts; | ||
| 207 | |||
| 208 | defined $tag | ||
| 209 | and push @opts, $tag; | ||
| 210 | |||
| 211 | defined $text | ||
| 212 | and push @opts, maybe_quote( $text ); | ||
| 213 | |||
| 214 | push @opts, render_opts( at => $at ); | ||
| 215 | |||
| 216 | defined $justify | ||
| 217 | and push @opts, $justify; | ||
| 218 | |||
| 219 | # rotate is either a false boolean or a number | ||
| 220 | defined $rotate | ||
| 221 | and push @opts, is_bool( $rotate ) | ||
| 222 | ? ( $rotate ? 'rotate' : 'norotate' ) | ||
| 223 | : [ 'rotate by' => $rotate ]; | ||
| 224 | |||
| 225 | push @opts, render_opts( font => $font ); | ||
| 226 | |||
| 227 | defined $enhanced | ||
| 228 | and push @opts, ( $enhanced ? 'enhanced' : 'noenhanced' ); | ||
| 229 | |||
| 230 | defined $layer | ||
| 231 | and push @opts, $layer; | ||
| 232 | |||
| 233 | push @opts, render_opts( textcolor => $textcolor ); | ||
| 234 | |||
| 235 | defined $hypertext && $hypertext | ||
| 236 | and push @opts, 'hypertext'; | ||
| 237 | |||
| 238 | defined $point | ||
| 239 | and push @opts, [ point => map { $PointMap{$_} => $point->{$_} } sort keys $point->%* ]; | ||
| 240 | |||
| 241 | push @opts, render_opts( offset => $offset ); | ||
| 242 | |||
| 243 | defined $boxed | ||
| 244 | and push @opts, is_bool( $boxed ) | ||
| 245 | ? ( $boxed ? 'boxed' : 'noboxed' ) | ||
| 246 | : ( boxed => boxstyle => $boxed ); | ||
| 247 | |||
| 248 | return @opts; | ||
| 249 | } | ||
| 250 | |||
| 251 | |||
| 252 | |||
| 253 | |||
| 254 | |||
| 255 | |||
| 256 | signature_for set => ( | ||
| 257 | method => 1, | ||
| 258 | named => [ | ||
| 259 | as => SetFormats, | ||
| 260 | { default => 'string' }, | ||
| 261 | ], | ||
| 262 | ); | ||
| 263 | |||
| 264 | method set ( $opt ) { | ||
| 265 | return render_set( [ render_opts( [ set => 'label' ], $self ) ], $opt->as ); | ||
| 266 | } | ||
| 267 | |||
| 268 | 1; | ||
| 269 | |||
| 270 | # | ||
| 271 | # This file is part of CXC-Gnuplot | ||
| 272 | # | ||
| 273 | # This software is Copyright (c) 2024 by Smithsonian Astrophysical Observatory. | ||
| 274 | # | ||
| 275 | # This is free software, licensed under: | ||
| 276 | # | ||
| 277 | # The GNU General Public License, Version 3, June 2007 | ||
| 278 | # | ||
| 279 | |||
| 280 | __END__ | ||