| 1 | # ----------------------------------------------------------------------------- | ||||||||||
| 2 | |||||||||||
| 3 | =encoding utf8 | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Quiq::PlotlyJs::Reference - Erzeuge Plotly.js Reference Manual | ||||||||||
| 8 | |||||||||||
| 9 | =head1 BASE CLASS | ||||||||||
| 10 | |||||||||||
| 11 | L<Quiq::Hash> | ||||||||||
| 12 | |||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||
| 14 | |||||||||||
| 15 | use Quiq::PlotlyJs::Reference; | ||||||||||
| 16 | use Quiq::Html::Producer; | ||||||||||
| 17 | |||||||||||
| 18 | $root = Quiq::PlotlyJs::Reference->new; | ||||||||||
| 19 | $h = Quiq::Html::Producer->new; | ||||||||||
| 20 | $html = $root->asHtml($h); | ||||||||||
| 21 | |||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||
| 23 | |||||||||||
| 24 | Die L<Dokumentation zu Plotly.js|https://plot.ly/javascript/> ist | ||||||||||
| 25 | umfangreich. Ein wichtiger Teil davon, die | ||||||||||
| 26 | L<Full Reference|https://plot.ly/javascript/reference/> mit der Beschreibung aller | ||||||||||
| 27 | Attribute ist allerdings umständlich zu handhaben. Diese Klasse | ||||||||||
| 28 | erzeugt eine L<übersichtlichere Fassung der Full Reference|https://s31tz.github.io/plotlyjs-reference.html>. | ||||||||||
| 29 | |||||||||||
| 30 | =head1 EXAMPLE | ||||||||||
| 31 | |||||||||||
| 32 | =head2 Dokument an der Kommandozeile erzeugen | ||||||||||
| 33 | |||||||||||
| 34 | $ perl -MQuiq::Html::Producer -MQuiq::PlotlyJs::Reference -E '$h = Quiq::Html::Producer->new; print Quiq::PlotlyJs::Reference->new->asHtml($h)' | ||||||||||
| 35 | |||||||||||
| 36 | produziert auf stdout | ||||||||||
| 37 | |||||||||||
| 38 | <details> | ||||||||||
| 39 | <summary> | ||||||||||
| 40 | 0. Layout | ||||||||||
| 41 | </summary> | ||||||||||
| 42 | <div style="margin-left: 22px"> | ||||||||||
| 43 | <p> | ||||||||||
| 44 | <details> | ||||||||||
| 45 | <summary> | ||||||||||
| 46 | angularaxis | ||||||||||
| 47 | </summary> | ||||||||||
| 48 | <div style="margin-left: 22px"> | ||||||||||
| 49 | <dl> | ||||||||||
| 50 | <dt>Parent:</dt> | ||||||||||
| 51 | <dd>layout</dd> | ||||||||||
| 52 | ... und mehr als 11.000 weitere Zeilen ... | ||||||||||
| 53 | |||||||||||
| 54 | =cut | ||||||||||
| 55 | |||||||||||
| 56 | # ----------------------------------------------------------------------------- | ||||||||||
| 57 | |||||||||||
| 58 | package Quiq::PlotlyJs::Reference; | ||||||||||
| 59 | 1 | ▶ | use base qw/Quiq::Hash/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 60 | |||||||||||
| 61 | 1 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 62 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 63 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 64 | |||||||||||
| 65 | 1 | our $VERSION = '1.240'; | |||||||||
| 66 | |||||||||||
| 67 | 1 | ▶ | use Quiq::Hash; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 68 | 1 | ▶ | use HTML::TreeBuilder (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 69 | 1 | ▶ | use Quiq::Html::List; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 70 | 1 | ▶ | use Quiq::Html::Page; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 71 | |||||||||||
| 72 | # ----------------------------------------------------------------------------- | ||||||||||
| 73 | |||||||||||
| 74 | =head1 METHODS | ||||||||||
| 75 | |||||||||||
| 76 | =head2 Konstruktor | ||||||||||
| 77 | |||||||||||
| 78 | =head3 new() - Instantiiere Objekt | ||||||||||
| 79 | |||||||||||
| 80 | =head4 Synopsis | ||||||||||
| 81 | |||||||||||
| 82 | $root = $class->new; | ||||||||||
| 83 | |||||||||||
| 84 | =head4 Returns | ||||||||||
| 85 | |||||||||||
| 86 | Wurzelknoten des Dokument-Baums (Object) | ||||||||||
| 87 | |||||||||||
| 88 | =head4 Description | ||||||||||
| 89 | |||||||||||
| 90 | Parse das Originaldokument, überführe es in einen Dokumentbaum | ||||||||||
| 91 | und liefere eine Referenz auf den Wurzelknoten dieses Baums zurück. | ||||||||||
| 92 | |||||||||||
| 93 | =cut | ||||||||||
| 94 | |||||||||||
| 95 | # ----------------------------------------------------------------------------- | ||||||||||
| 96 | |||||||||||
| 97 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 98 | 0 | my $class = shift; | |||||||||
| 99 | |||||||||||
| 100 | # my $file = 'Blob/doc-content/plotlyjs-reference-orig.html'; | ||||||||||
| 101 | # my $hRoot = HTML::TreeBuilder->new_from_file($file)->elementify; | ||||||||||
| 102 | |||||||||||
| 103 | 0 | my $url = 'https://plot.ly/javascript/reference/'; | |||||||||
| 104 | 0 | my $hRoot = HTML::TreeBuilder->new_from_url($url)->elementify; | |||||||||
| 105 | |||||||||||
| 106 | # Parse die Attributliste eines Knotens | ||||||||||
| 107 | |||||||||||
| 108 | 0 | my $attributesSub; # muss wg. rekursivem Aufruf vorher deklariert werden | |||||||||
| 109 | 0 | ▶ | $attributesSub = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=9 SCAR=45.0
| |||||||||||
| 110 | 0 | my $h = shift; | |||||||||
| 111 | |||||||||||
| 112 | 0 | my @attributes; | |||||||||
| 113 | |||||||||||
| 114 | 0 | my $ul = $h->look_down(_tag=>'ul'); | |||||||||
| 115 | 0 | ▶ | if ($ul) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 116 | 0 | for my $li ($ul->content_list) { | |||||||||
| 117 | # Name | ||||||||||
| 118 | |||||||||||
| 119 | 0 | my $name = $li->look_down(class=>'attribute-name')->as_text; | |||||||||
| 120 | 0 | $name =~ s/^\s+//; | |||||||||
| 121 | 0 | $name =~ s/\s+$//; | |||||||||
| 122 | |||||||||||
| 123 | 0 | my $html = $li->as_HTML; | |||||||||
| 124 | |||||||||||
| 125 | # Parent | ||||||||||
| 126 | |||||||||||
| 127 | 0 | my ($parent) = $html =~ m|Parent:.*?<code>(.*?)</code>|; | |||||||||
| 128 | 0 | ▶ | if (!defined $parent) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 129 | # Angabe Parent: erwarten wir immer | ||||||||||
| 130 | 0 | $class->throw; | |||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | # Type | ||||||||||
| 134 | |||||||||||
| 135 | 0 | my $type; | |||||||||
| 136 | 0 | ▶ | if ($html =~ /Type:/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 137 | 0 | ($type) = $html =~ m{Type:</em>(.*?)(<br|<p>|<ul>|$)}s; | |||||||||
| 138 | 0 | ▶ | if (!defined $type) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 139 | # Wenn Angabe Type: vorkommt, müssen wir sie | ||||||||||
| 140 | # extrahieren können | ||||||||||
| 141 | 0 | $class->throw( | |||||||||
| 142 | 'PLOTYJS-00001: Can\'t extract Type:', | ||||||||||
| 143 | Html => $html, | ||||||||||
| 144 | ); | ||||||||||
| 145 | } | ||||||||||
| 146 | 0 | $type =~ s/^\s+//; | |||||||||
| 147 | 0 | $type =~ s/\s+$//; | |||||||||
| 148 | 0 | $type =~ s|</?code>||g; | |||||||||
| 149 | 0 | $type =~ s|"|"|g; | |||||||||
| 150 | } | ||||||||||
| 151 | |||||||||||
| 152 | # Default | ||||||||||
| 153 | |||||||||||
| 154 | 0 | my $default; | |||||||||
| 155 | 0 | ▶ | if ($html =~ /Default:/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 156 | 0 | ($default) = $html =~ m|Default:.*?<code>(.*?)</code>|; | |||||||||
| 157 | 0 | ▶ | if (!defined $default) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 158 | # Wenn Angabe Default: vorkommt, müssen wir sie | ||||||||||
| 159 | # extrahieren können | ||||||||||
| 160 | 0 | $class->throw( | |||||||||
| 161 | 'PLOTYJS-00001: Can\'t extract Default:', | ||||||||||
| 162 | Html => $html, | ||||||||||
| 163 | ); | ||||||||||
| 164 | } | ||||||||||
| 165 | 0 | $default =~ s|</?code>||g; | |||||||||
| 166 | 0 | $default =~ s|"|"|g; | |||||||||
| 167 | } | ||||||||||
| 168 | |||||||||||
| 169 | # Description | ||||||||||
| 170 | |||||||||||
| 171 | 0 | my $descr; | |||||||||
| 172 | 0 | my $p = $li->look_down(_tag=>'p'); | |||||||||
| 173 | 0 | ▶ | if ($p) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 174 | 0 | $descr = $p->as_text; | |||||||||
| 175 | 0 | $descr =~ s|M~|\\M~|g; | |||||||||
| 176 | } | ||||||||||
| 177 | |||||||||||
| 178 | 0 | push @attributes,Quiq::Hash->new( | |||||||||
| 179 | name => $name, | ||||||||||
| 180 | parent => $parent, | ||||||||||
| 181 | type => $type, | ||||||||||
| 182 | default => $default, | ||||||||||
| 183 | description => $descr, | ||||||||||
| 184 | attributeA => $attributesSub->($li), | ||||||||||
| 185 | ); | ||||||||||
| 186 | } | ||||||||||
| 187 | } | ||||||||||
| 188 | |||||||||||
| 189 | 0 | return \@attributes; | |||||||||
| 190 | 0 | }; | |||||||||
| 191 | |||||||||||
| 192 | # Parse Dokument | ||||||||||
| 193 | |||||||||||
| 194 | 0 | my $i = 0; | |||||||||
| 195 | 0 | my @sections; | |||||||||
| 196 | 0 | for my $hSec ($hRoot->look_down(_tag=>'div',class=>'row')) { | |||||||||
| 197 | 0 | ▶ | if (!$i++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 198 | # Die Einleitung des Reference-Dokuments übergehen wir | ||||||||||
| 199 | 0 | next; | |||||||||
| 200 | } | ||||||||||
| 201 | |||||||||||
| 202 | 0 | my $title = ucfirst $hSec->look_down(_tag=>'h4')->as_text; | |||||||||
| 203 | 0 | $title =~ s/^\s+//; | |||||||||
| 204 | 0 | $title =~ s/\s+$//; | |||||||||
| 205 | |||||||||||
| 206 | 0 | my $descr; | |||||||||
| 207 | 0 | my $e = $hSec->look_down(_tag=>'div',class=>'description'); | |||||||||
| 208 | 0 | ▶ | if ($e) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 209 | 0 | $descr = $e->as_text; | |||||||||
| 210 | } | ||||||||||
| 211 | |||||||||||
| 212 | 0 | push @sections,Quiq::Hash->new( | |||||||||
| 213 | title => $title, | ||||||||||
| 214 | description => $descr, | ||||||||||
| 215 | attributeA => $attributesSub->($hSec), | ||||||||||
| 216 | ); | ||||||||||
| 217 | } | ||||||||||
| 218 | |||||||||||
| 219 | # Abschnitt Layout an den Anfang | ||||||||||
| 220 | 0 | unshift @sections,pop @sections; | |||||||||
| 221 | |||||||||||
| 222 | 0 | return $class->SUPER::new( | |||||||||
| 223 | title => 'Plotly.js Reference', | ||||||||||
| 224 | sectionA => \@sections, | ||||||||||
| 225 | ); | ||||||||||
| 226 | } | ||||||||||
| 227 | |||||||||||
| 228 | # ----------------------------------------------------------------------------- | ||||||||||
| 229 | |||||||||||
| 230 | =head2 HTML-Repräsentation | ||||||||||
| 231 | |||||||||||
| 232 | =head3 asHtml() - Erzeuge HTML-Repräsentation | ||||||||||
| 233 | |||||||||||
| 234 | =head4 Synopsis | ||||||||||
| 235 | |||||||||||
| 236 | $html = $obj->asHtml($h); | ||||||||||
| 237 | |||||||||||
| 238 | =head4 Arguments | ||||||||||
| 239 | |||||||||||
| 240 | =over 4 | ||||||||||
| 241 | |||||||||||
| 242 | =item $h | ||||||||||
| 243 | |||||||||||
| 244 | Quiq::Html::Tag Objekt. | ||||||||||
| 245 | |||||||||||
| 246 | =back | ||||||||||
| 247 | |||||||||||
| 248 | =head4 Options | ||||||||||
| 249 | |||||||||||
| 250 | =over 4 | ||||||||||
| 251 | |||||||||||
| 252 | =item -document => $bool (Default: 0) | ||||||||||
| 253 | |||||||||||
| 254 | Erzeuge ein vollständiges HTML-Dokument. | ||||||||||
| 255 | |||||||||||
| 256 | =item -indent => $n (Default: 22) | ||||||||||
| 257 | |||||||||||
| 258 | Rücke die Ebenen um $n Pixel ein. | ||||||||||
| 259 | |||||||||||
| 260 | =back | ||||||||||
| 261 | |||||||||||
| 262 | =head4 Returns | ||||||||||
| 263 | |||||||||||
| 264 | HTML-Code (String) | ||||||||||
| 265 | |||||||||||
| 266 | =head4 Description | ||||||||||
| 267 | |||||||||||
| 268 | Liefere die plotly.js Dokumentation in HTML. | ||||||||||
| 269 | |||||||||||
| 270 | =cut | ||||||||||
| 271 | |||||||||||
| 272 | # ----------------------------------------------------------------------------- | ||||||||||
| 273 | |||||||||||
| 274 | 0 | ▶ | sub asHtml { | ||||||||
|
Subroutine
asHtml: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 275 | 0 | my ($self,$h) = splice @_,0,2; | |||||||||
| 276 | |||||||||||
| 277 | # Optionen | ||||||||||
| 278 | |||||||||||
| 279 | 0 | my $document = 0; | |||||||||
| 280 | 0 | my $indent = 22; | |||||||||
| 281 | |||||||||||
| 282 | 0 | $self->parameters(\@_, | |||||||||
| 283 | document => \$document, | ||||||||||
| 284 | indent => \$indent, | ||||||||||
| 285 | ); | ||||||||||
| 286 | |||||||||||
| 287 | # Generiere Attributliste | ||||||||||
| 288 | |||||||||||
| 289 | 0 | my $attributesAsHtmlSub; # muss wg. rekursivem Aufruf deklariert werden | |||||||||
| 290 | 0 | ▶ | $attributesAsHtmlSub = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 291 | 0 | my ($node,$h,$indent) = @_; | |||||||||
| 292 | |||||||||||
| 293 | 0 | my $html = ''; | |||||||||
| 294 | |||||||||||
| 295 | 0 | my @attributes = sort {$a->get('name') cmp $b->get('name')} | |||||||||
| 296 | 0 | @{$node->get('attributeA')}; | |||||||||
| 297 | |||||||||||
| 298 | 0 | for my $att (@attributes) { | |||||||||
| 299 | 0 | $html .= $h->tag('details', | |||||||||
| 300 | '-', | ||||||||||
| 301 | $h->tag('summary', | ||||||||||
| 302 | $att->get('name') | ||||||||||
| 303 | ), | ||||||||||
| 304 | $h->tag('div', | ||||||||||
| 305 | style => "margin-left: ${indent}px", | ||||||||||
| 306 | '-', | ||||||||||
| 307 | Quiq::Html::List->html($h, | ||||||||||
| 308 | type => 'description', | ||||||||||
| 309 | isText => 1, | ||||||||||
| 310 | items => [ | ||||||||||
| 311 | 'Parent:' => $att->get('parent'), | ||||||||||
| 312 | 'Type:' => $att->get('type'), | ||||||||||
| 313 | 'Default:' => $att->get('default'), | ||||||||||
| 314 | ], | ||||||||||
| 315 | ), | ||||||||||
| 316 | $h->tag('p', | ||||||||||
| 317 | -text => 1, | ||||||||||
| 318 | $att->get('description') | ||||||||||
| 319 | ), | ||||||||||
| 320 | ), | ||||||||||
| 321 | ); | ||||||||||
| 322 | 0 | $html .= $h->tag('div', | |||||||||
| 323 | -ignoreIfNull => 1, | ||||||||||
| 324 | style => "margin-left: ${indent}px", | ||||||||||
| 325 | $attributesAsHtmlSub->($att,$h,$indent) | ||||||||||
| 326 | ); | ||||||||||
| 327 | } | ||||||||||
| 328 | |||||||||||
| 329 | 0 | return $html; | |||||||||
| 330 | 0 | }; | |||||||||
| 331 | |||||||||||
| 332 | # Generiere Dokument | ||||||||||
| 333 | |||||||||||
| 334 | 0 | my $html = ''; | |||||||||
| 335 | 0 | my $i = 0; | |||||||||
| 336 | 0 | for my $sec (@{$self->get('sectionA')}) { | |||||||||
| 337 | 0 | $html .= $h->tag('details', | |||||||||
| 338 | '-', | ||||||||||
| 339 | $h->tag('summary', | ||||||||||
| 340 | "$i. ".$sec->get('title') | ||||||||||
| 341 | ), | ||||||||||
| 342 | $h->tag('div', | ||||||||||
| 343 | style => "margin-left: ${indent}px", | ||||||||||
| 344 | '-', | ||||||||||
| 345 | $h->tag('p', | ||||||||||
| 346 | -text => 1, | ||||||||||
| 347 | $sec->get('description') | ||||||||||
| 348 | ), | ||||||||||
| 349 | $h->tag('p', | ||||||||||
| 350 | $attributesAsHtmlSub->($sec,$h,$indent) | ||||||||||
| 351 | ), | ||||||||||
| 352 | ), | ||||||||||
| 353 | ); | ||||||||||
| 354 | 0 | $i++; | |||||||||
| 355 | } | ||||||||||
| 356 | |||||||||||
| 357 | 0 | ▶ | if ($document) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 358 | 0 | my $title = $self->get('title'); | |||||||||
| 359 | 0 | $html = Quiq::Html::Page->html($h, | |||||||||
| 360 | title => $title, | ||||||||||
| 361 | styleSheet => qq~ | ||||||||||
| 362 | body { | ||||||||||
| 363 | font-family: sans-serif; | ||||||||||
| 364 | font-size: 11pt; | ||||||||||
| 365 | } | ||||||||||
| 366 | ~, | ||||||||||
| 367 | body => $h->cat( | ||||||||||
| 368 | $h->tag('h1',$title), | ||||||||||
| 369 | $html, | ||||||||||
| 370 | ), | ||||||||||
| 371 | ); | ||||||||||
| 372 | } | ||||||||||
| 373 | |||||||||||
| 374 | 0 | return $html; | |||||||||
| 375 | } | ||||||||||
| 376 | |||||||||||
| 377 | # ----------------------------------------------------------------------------- | ||||||||||
| 378 | |||||||||||
| 379 | =head1 VERSION | ||||||||||
| 380 | |||||||||||
| 381 | 1.240 | ||||||||||
| 382 | |||||||||||
| 383 | =head1 AUTHOR | ||||||||||
| 384 | |||||||||||
| 385 | Frank Seitz, L<http://fseitz.de/> | ||||||||||
| 386 | |||||||||||
| 387 | =head1 COPYRIGHT | ||||||||||
| 388 | |||||||||||
| 389 | Copyright (C) 2026 Frank Seitz | ||||||||||
| 390 | |||||||||||
| 391 | =head1 LICENSE | ||||||||||
| 392 | |||||||||||
| 393 | This code is free software; you can redistribute it and/or modify | ||||||||||
| 394 | it under the same terms as Perl itself. | ||||||||||
| 395 | |||||||||||
| 396 | =cut | ||||||||||
| 397 | |||||||||||
| 398 | # ----------------------------------------------------------------------------- | ||||||||||
| 399 | |||||||||||
| 400 | 1 | 1; | |||||||||
| 401 | |||||||||||
| 402 | # eof | ||||||||||