Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Drawing A Dichotomous Key

by varanasi (Scribe)
on May 25, 2020 at 19:52 UTC ( [id://11117245]=perlquestion: print w/replies, xml ) Need Help??

varanasi has asked for the wisdom of the Perl Monks concerning the following question:

I would like to draw, and ultimately print, a dichotomous key. A dichotomous key works rather like a flowchart or decision tree with a yes/no choice at each node. There's an explanation with some nice examples of possible pictures here: https://creately.com/blog/diagrams/what-is-a-dichotomous-key/

I suspect that what I need is in cpan, but I've searched cpan without success.

Replies are listed 'Best First'.
Re: Drawing A Dichotomous Key
by tybalt89 (Monsignor) on May 25, 2020 at 21:49 UTC

    Here's something I did for https://www.rosettacode.org/wiki/Display_an_outline_as_a_nested_table#Perl It's not exactly what I think you want, but it may be close.

    #!/usr/bin/perl # http://www.rosettacode.org/wiki/Display_an_outline_as_a_nested_table use strict; use warnings; my @rows; my $row = -1; my $width = 0; my $color = 0; our $bg = 'e0ffe0'; parseoutline( do { local $/; <DATA> =~ s/\t/ /gr } ); print "<table border=1 cellspacing=0>\n"; for ( @rows ) { my $start = 0; print " <tr>\n"; for ( @$_ ) # columns { my ($data, $col, $span, $bg) = @$_; print " <td></td>\n" x ( $col - $start ), " <td colspan=$span align=center bgcolor=#$bg> $data </td>\n" +; $start = $col + $span; } print " <td></td>\n" x ( $width - $start ), " </tr>\n"; } print "</table>\n"; sub parseoutline { ++$row; while( $_[0] =~ /^( *)(.*)\n((?:\1 .*\n)*)/gm ) { my ($head, $body, $col) = ($2, $3, $width); $row == 1 and local $bg = qw( ffffe0 ffe0e0 )[ $color ^= 1]; if( length $body ) { parseoutline( $body ) } else { ++$width } push @{ $rows[$row] }, [ $head, $col, $width - $col, $bg ]; } --$row; } __DATA__ insects large wings butterfly small or no wings very long rear legs antenna front mosquito antenna rear grasshopper shorter rear legs horned head rhino beetle not horned head small eyes termite solder large eyes beetle

    I used the information from the "Insects" drawing.
    When the output is run through links -dump filename it outputs:

    +------------------------------------------------------------------ +------+ | insects + | |------------------------------------------------------------------ +------| | large wings | small or no wings + | |-------------+---------------------------------------------------- +------| | butterfly | very long rear legs | shorter rear legs + | |-------------+--------------------------+------------------------- +------| | | antenna | antenna rear | horned | not horned h +ead | | | front | | head | + | |-------------+-----------+--------------+---------+--------------- +------| | | mosquito | grasshopper | rhino | small | l +arge | | | | | beetle | eyes | e +yes | |-------------+-----------+--------------+---------+-----------+--- +------| | | | | | termite | be +etle | | | | | | solder | + | +------------------------------------------------------------------ +------+

    Of course, it can also be viewed in a browser.

    insects
    large wings small or no wings
    butterfly very long rear legs shorter rear legs
    antenna front antenna rear horned head not horned head
    mosquito grasshopper rhino beetle small eyes large eyes
    termite solder beetle


    Wow, that worked :)

    UPDATE: fixed typo in comment

      Wow! This is lovely. Thank you!

Re: Drawing A Dichotomous Key
by Fletch (Bishop) on May 25, 2020 at 20:11 UTC

    Perhaps GraphViz, and/or the underlying dot software directly?

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Drawing A Dichotomous Key
by perlfan (Vicar) on May 26, 2020 at 00:38 UTC
    Maybe UML is a keyword to use? I found UML::State, but GraphViz (mentioned below!) seems rather well supported and a good idea. You're not going to get something to create pretty pictures most likely. Another avenue might be via LaTeX. Ultimately what you're doing is rendering a graph, so you actually do have quite a few choices. But you are probably not going to find something that does exactly what you want without creating it yourself. Also not what you want, but may want to see what's underneath the hood if Bio::Graphics.
Re: Drawing A Dichotomous Key
by Anonymous Monk on May 28, 2020 at 02:27 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11117245]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-16 17:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found